I am applying selectKbest feature selection technique but it is giving me the following error:
AttributeError: 'numpy.ndarray' object has no attribute 'columns'
here is the portion of my code:
bestfeatures = SelectKBest(score_func=chi2, k=10)
fit = bestfeatures.fit(X,y)
dfscores = pd.DataFrame(fit.scores_)
dfcolumns = pd.DataFrame(X.columns)
(Note: the original data is in CSV format)
CodePudding user response:
X is a numpy array, and you can only call the .columns method on a dataframe. You need to convert to a dataframe first, then call the method.
dfcolumns = pd.DataFrame(X).columns