Scikit-learn cross val score: too many indices for array

前端 未结 5 1860
再見小時候
再見小時候 2020-12-15 05:15

I have the following code

 from sklearn.ensemble import ExtraTreesClassifier
 from sklearn.cross_validation import cross_val_score
 #split the dataset for tr         


        
5条回答
  •  不思量自难忘°
    2020-12-15 05:49

    When we do cross validation in scikit-learn, the process requires an (R,) shape label instead of (R,1). Although they are the same thing to some extend, their indexing mechanisms are different. So in your case, just add:

    c, r = labels.shape
    labels = labels.reshape(c,)
    

    before passing it to the cross-validation function.

提交回复
热议问题