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
Answer from Djib2011 on Stack Exchange
Discussions

'numpy.ndarray' object has no attribute 'numpy'.
I tried to submit this to the repository linked in your publication, but, apparently, I can't! I received this error while running predictions: Traceback (most recent call last): File "/Us... More on github.com
🌐 github.com
1
November 16, 2023
AttributeError: 'numpy.ndarray' object has no attribute 'values'
Traceback (most recent call last): ... X_unlabeled_sample, T=T) File "UST/ust.py", line 62, in mc_dropout_evaluate y_pred.extend(pred.values[gpu]) AttributeError: 'numpy.ndarray' object has no attribute 'values'... More on github.com
🌐 github.com
1
April 9, 2021
python - AttributeError: 'numpy.ndarray' object has no attribute 'values' - Stack Overflow
I am trying to buid a simple Neural Network and you can find my code below. When I run it I get an error message saying: Traceback (most recent call last): File "algosofleetNNkuantic2.py", line ... More on stackoverflow.com
🌐 stackoverflow.com
Error creating numpy v-stack, 'AttributeError: 'numpy.ndarray' object has no attribute 'np'
I think I'm using the wrong notation to append to the empty arrays: The best way to find out is to read the documentation https://numpy.org/doc/stable/reference/generated/numpy.append.html And yes you are. Numpy arrays don't have an append method, it's a function from the library. And there is no such thing as object.library.function(...) which is what you are doing here similarity.np.append(...) num_interactions.np.append(...) It should be similarity = np.append(similarity, values_to_append) num_interactions = np.append(num_interactions, values_to_append) And should avoid appending data to a numpy array. I'm almost sure there is much better alternative. But since you didn't explain what you are trying to do, I can't help you with that. More on reddit.com
🌐 r/learnpython
5
2
May 4, 2021
🌐
GitHub
github.com › waylandy › phosformer › issues › 1
'numpy.ndarray' object has no attribute 'numpy'. · Issue #1 · waylandy/phosformer
November 16, 2023 - Traceback (most recent call last): File "/Users/joshuasacher/phosformer/wip1_S234.py", line 17, in <module> predictions = Phosformer.predict_many( ^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/joshuasacher/phosformer/Phosformer/modules.py", line 204, in predict_many return np.array([i['pred'] for i in batch_job(kinases, peptides, **kwargs)]) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/joshuasacher/phosformer/Phosformer/modules.py", line 204, in <listcomp> return np.array([i['pred'] for i in batch_job(kinases, peptides, **kwargs)]) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/joshuasacher/phosformer/Phosformer/modules.py", line 96, in batch_job pred = softmax(result['logits'].cpu(), axis=1)[:,1].numpy() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'numpy.ndarray' object has no attribute 'numpy'.
Author   jrsacher
🌐
GitHub
github.com › microsoft › UST › issues › 4
AttributeError: 'numpy.ndarray' object has no attribute 'values' · Issue #4 · microsoft/UST
April 9, 2021 - AttributeError: 'numpy.ndarray' object has no attribute 'values'#4 · Copy link · airlsyn · opened · on Apr 9, 2021 · Issue body actions · training with 1 GPU, tensorflow_gpu-2.3.1, transformers-3.3.1 , an error occurred: y_pred.extend(pred.values[gpu]) in ust.py ·
Author   airlsyn
🌐
Quora
quora.com › Why-do-I-get-numpy-ndarray-object-has-no-attribute-append-error
Why do I get “numpy.ndarray object has no attribute append error”? - Quora
Summary The AttributeError is simply because ndarray has no append method. Choose the appropriate container or numpy function for your use case: list for frequent appends, preallocation for efficiency, or np.append/np.concatenate when copying ...
Find elsewhere
🌐
Reddit
reddit.com › r/learnpython › error creating numpy v-stack, 'attributeerror: 'numpy.ndarray' object has no attribute 'np'
r/learnpython on Reddit: Error creating numpy v-stack, 'AttributeError: 'numpy.ndarray' object has no attribute 'np'
May 4, 2021 -

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

🌐
Researchdatapod
researchdatapod.com › home › how to solve python attributeerror: ‘numpy.ndarray’ has no attribute ‘values’
How to Solve Python AttributeError: 'numpy.ndarray' has no attribute 'values' - The Research Scientist Pod
May 15, 2022 - If you attempt to call the values() ... belongs to the DataFrame object. This error typically occurs when trying to call values after already converting a Series or DataFrame to NumPy array....
🌐
Itsourcecode
itsourcecode.com › home › attributeerror: numpy.ndarray object has no attribute values
Attributeerror: numpy.ndarray object has no attribute values
April 4, 2023 - This attributeerror: numpy.ndarray object has no attribute values error occurs when you try to access the “values” attribute of a NumPy ndarray object, but it does not exist.
🌐
GeeksforGeeks
geeksforgeeks.org › how-to-fix-numpy-ndarray-object-has-no-attribute-index
How to Fix: ‘numpy.ndarray’ object has no attribute ‘index’ - GeeksforGeeks
November 28, 2021 - As Indexes in array starts from 0, Here in the numbers array 0th index consists of value 0, 1st index has value 1, 2nd index has value 2 and 3rd index has value 9 which is specified so it returned an array which contains a value 3. ... Specify an element in where method such that the element we specified is occurred more than once in an array. ... # import necessary packages import numpy as np # Create a Numpy array numbers = np.array([0, 1, 2, 9, 8, 0]) # finding the index values of 0 in # numbers array np.where(numbers == 0)
🌐
GitHub
github.com › lmcinnes › umap › issues › 894
AttributeError: 'numpy.ndarray' object has no attribute 'transform' · Issue #894 · lmcinnes/umap
July 27, 2022 - Hello, When trying to do a .fit_transform on the "Train" data and then a .transform on the "Test" data, I get the error: AttributeError: 'numpy.ndarray' object has no attribute 'transform' This is my use case: reducer = umap.UMAP( n_comp...
Author   rbsingh13
🌐
Career Karma
careerkarma.com › blog › python › python attributeerror: ‘numpy.ndarray’ object has no attribute ‘append’ solution
Python AttributeError: 'numpy.ndarray' object has no attribute 'append' Solution
December 1, 2023 - The AttributeError: ‘numpy.ndarray’ object has no attribute ‘append’ error is caused by using the append() method to add an item to a NumPy array.
🌐
freeCodeCamp
forum.freecodecamp.org › python
Attribute error during testing - Python - The freeCodeCamp Forum
October 5, 2021 - Tell us what’s happening: The test module fails giving the error 'numpy.ndarray' object has no attribute 'get_xlabel'. A very similar error comes up in the second test. Additionally for some reasons the values in my correlation matrix are wrong. This is the console output: python main.py ...
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-fix-numpy-ndarray-object-has-no-attribute-append
How to Fix: ‘numpy.ndarray’ object has no attribute ‘append’ - GeeksforGeeks
November 28, 2021 - The output is pretty explanatory, the NumPy array has a type of numpy.ndarray which does not have any append() method. Now, we know that the append is not supported by NumPy arrays then how do we use it? It is actually a method of NumPy and not its array, let us understand it through the example given below, where we actually perform the append operation on a numpy list. ... values: numpy array or value: These values are appended to a copy of arr.
🌐
Python Forum
python-forum.io › thread-37639.html
AttributeError: 'numpy.ndarray' object has no attribute 'load'
I have the following error: Error: currrent_pixel = my_image.load() AttributeError: 'numpy.ndarray' object has no attribute 'load'in the following code: import cv2 import numpy as np my_image = cv2.imread...
🌐
Neurostars
neurostars.org › community chat
AttributeError: 'numpy.ndarray' object has no attribute 'func' - Community Chat - Neurostars
September 1, 2022 - Hello, I am working on a subject on my local pc I did preprocessing through fmriprep on docker. I used the when I wanted to run import nibabel as nib from nibabel.testing import data_path import numpy as np from nilearn import datasets atlas = datasets.fetch_atlas_msdl() Loading atlas image stored in ‘maps’ atlas_filename = atlas[‘maps’] Loading atlas data stored in ‘labels’ labels = atlas[‘labels’] Load the functional datasets a = nib.load(’/home/roya/outputneww2/sub-1001/ses-01/...