From the docs of numpy.where - the function returns the indexes where the condition within the function is True.
Example:
>>> np.where(outlier_preds == -1)
(array([ 35, 59, 117, 118, 119, 126, 128, 141, 143, 144, 145, 146, 149,
150, 151, 152, 153, 155, 156, 162, 175, 176, 184, 192, 201, 202,
203, 204, 205, 214, 217, 218], dtype=int64),)
>>> np.where(outlier_preds == -1)[0][0] #First element only
35
Answer from CDJB on Stack Overflowscikit learn - AttributeError: 'numpy.ndarray' object has no attribute 'columns' - Data Science Stack Exchange
'numpy.ndarray' object has no attribute 'numpy'.
Python Coding help- keep recieving error message"AttributeError: 'numpy.ndarray' object has no attribute 'MESSAGE_A'"
AttributeError: 'numpy.ndarray' object has no attribute 'func'
Hi,
I'm trying to create a numpy v-stack and creating 3 np.array's for it, by filling them with a loop:
I get the error: 'AttributeError: 'numpy.ndarray' object has no attribute 'np' . I think I'm using the wrong notation to append to the empty arrays:
neighbor_id = [id_ for id_ in range(1, n_obs) if id_ != user_id]
neighbor_id_arr = np.array(neighbor_id)
similarity = np.array([])
num_interactions = np.array([])
# get similarity and num_interactions
for id_ in neighbor_id:
similarity.np.append(np.dot(user_item.loc[user_id],user_item.loc[id_])) #The issue is here, I think
num_interactions.np.append(user_interactions.loc[id_])
c = numpy.vstack((neighbor_id_arr, similarity,num_interactions))
Thanks!
James
The problem is that train_test_split(X, y, ...) returns numpy arrays and not pandas dataframes. Numpy arrays have no attribute named columns
If you want to see what features SelectFromModel kept, you need to substitute X_train (which is a numpy.array) with X which is a pandas.DataFrame.
selected_feat= X.columns[(sel.get_support())]
This will return a list of the columns kept by the feature selector.
If you wanted to see how many features were kept you can just run this:
sel.get_support().sum() # by default this will count 'True' as 1 and 'False' as 0
because this :
X = df.iloc[:,:24481].values
y = df.iloc[:, -1].values
you should remove .values or make extra X_col, y_col like that
X_col = df.iloc[:,:24481]
y_col = df.iloc[:, -1]
https://imgur.com/gallery/yAdAjdx
Hello,
Linked is the screenshot of the two error messages I keep recieving as well as the code leading up to it. I'm trying to run an uplift on a classification tree. Any help is appreciated, I am still fairly new to python. Thank you!!
Recoding Variables
"
#I need to recode variables given there are "5" responses present on a 4-point scale
scldict = {1:1,2:2,3:3,4:4,5:'NaN'}
w1array = np.array(week1)
w1vec = w1array.vectorize(scldict)
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-92-e3f6056d2727> in <module>()
2 scaldict = {1:1,2:2,3:3,4:4,5:'NaN'}
3 w1array = np.array(week1)
----> 4 w1vec = w1array.vectorize(scaldict)
AttributeError: 'numpy.ndarray' object has no attribute 'vectorize'Hello world, I am trying to recode variables given there are invalid responses in my survey data. I am using a dictionary and the vectorize function (seen on StackOverflow) to do this. Why is the vectorize function not available? I am lost.
Any help or suggestions for recoding variables in an efficient manner would be appreciated.
I need help. This is the code which gives error:
import numpy as np
num = 3
X_new = np.array([])
for i in range(1, num+1):
print('Enter the', i, '. data:')
n = float(input())
X_new.append(n)
print('\n', X_new)
And this is the error:
AttributeError: 'numpy.ndarray' object has no attribute 'append'