-1

Following is my code:-

from sklearn.feature_selection import SelectKBest, chi2, f_regression

X_train_new = SelectKBest(score_func=chi2,k=2000).fit_transform(X_train_2,y_train)

X_cv_new = SelectKBest(score_func=chi2,k=2000).transform(X_cv_2,y_cv)

X_test_new = SelectKBest(score_func=chi2,k=2000).transform(X_test_2,y_test)

X_train_new.shape, X_cv_new.shape, X_test_new.shape

I am trying to select top 2000 features and then apply it for a tfidf featurized train, cv and test data.

While doing the aforementioned I get the "TypeError: transform() takes 2 positional arguments but 3 were given"

Devesh Kumar Singh
  • 20,259
  • 5
  • 21
  • 40
  • Did you check the [docs](https://scikit-learn.org/stable/modules/generated/sklearn.feature_selection.SelectKBest.html#sklearn.feature_selection.SelectKBest.transform) ? – Devesh Kumar Singh Jul 07 '19 at 16:14

1 Answers1

0

From what the documentation provides, self is taken to be an argument, so when you provide y_train, y_cv, and y_test into the method, these are being taken as a third argument. The method takes (self, X) where X is an array of shape [n_samples, n_features].

Zander0416
  • 21
  • 5