A column-vector y was passed when a 1d array was expected

前端 未结 8 656
慢半拍i
慢半拍i 2020-12-12 10:40

I need to fit RandomForestRegressor from sklearn.ensemble.

forest = ensemble.RandomForestRegressor(**RF_tuned_parameters)
model = fo         


        
相关标签:
8条回答
  • 2020-12-12 11:05

    I had the same problem. The problem was that the labels were in a column format while it expected it in a row. use np.ravel()

    knn.score(training_set, np.ravel(training_labels))
    

    Hope this solves it.

    0 讨论(0)
  • 2020-12-12 11:06

    Change this line:

    model = forest.fit(train_fold, train_y)
    

    to:

    model = forest.fit(train_fold, train_y.values.ravel())
    

    Edit:

    .values will give the values in an array. (shape: (n,1)

    .ravel will convert that array shape to (n, )

    0 讨论(0)
提交回复
热议问题