poiuytrez
poiuytrez

Reputation: 22518

ValueError: need more than 1 value to unpack with classifier in scikit-learn

I have the following code to learn from my dataset:

>>> train_features[:5]
array([[2.0, 9.0, 37.0, 0.0, 28.71, 0.0, 243.63, False],
       [2.0, 0.0, 4.0, 0.0, 0.0, 0.0, 6.3100000000000005, False],
       [2.0, 3.0, 3.0, 0.0, 28.07, 0.0, 28.07, False],
       [2.0, 1.0, 2.0, 0.0, 5.49, 0.0, 14.48, False],
       [2.0, 3.0, 3.0, 0.0, 7.4700000000000015, 0.0, 7.4700000000000015,
        False]], dtype=object)

>>> train_labels[:5]
array([ True, False,  True, False,  True], dtype=bool)

>>> rf = RandomForestClassifier(n_estimators=10) 
>>> rf.fit(train_labels, train_features)

I am getting this error on the fit function:

ValueError: need more than 1 value to unpack

I believe this is a formatting error. What value does scikit-learn expect? I have not found the input reference in the scikit-learn manual.

Upvotes: 0

Views: 1410

Answers (1)

Irshad Bhat
Irshad Bhat

Reputation: 8709

The only error is that you have passed the arguments in reverse order. Replace:

rf.fit(train_labels, train_features)

by:

rf.fit(train_features,train_labels)

Hope it fixes the issue.

Upvotes: 3

Related Questions