Reputation: 51
i'm a beginner with scikit-learn and python, i tried this code that looks very simple using SelectKBest from feature_selection package.
train = pd.read_csv("train.csv")
test = pd.read_csv('test.csv')
train = SelectKBest(chi2, k=120).fit_transform(train)
print train.shape
but i got this error and i really don't know how to fix it !!
TypeError: fit() takes exactly 3 arguments (2 given)
Can u guys please help me fixing that :( ?
Upvotes: 2
Views: 758
Reputation: 447
The issue is that it expect 3 arguments.
fit(X, y) X : array-like, shape = [n_samples, n_features] which is the training input samples. y : array-like, shape = [n_samples] is the target values (class labels in classification, real numbers in regression).
fit_transform(X,y=None, **fit_params)[source]
Therefore, to fix your problem, if the labels are stored in the last column of the training/test data i.e. train.ix[:,-1], you could do this:
train = pd.read_csv("train.csv")
test = pd.read_csv('test.csv')
model = SelectKBest(chi2, k=120).fit_transform(train.ix[:,:-1],train.ix[:,-1])
print train.shape
This code worked for me.
Upvotes: 1