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

前端 未结 8 655
慢半拍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 10:51

    With neuraxle, you can easily solve this :

    p = Pipeline([
       # expected outputs shape: (n, 1)
       OutputTransformerWrapper(NumpyRavel()), 
       # expected outputs shape: (n, )
       RandomForestRegressor(**RF_tuned_parameters)
    ])
    
    p, outputs = p.fit_transform(data_inputs, expected_outputs)
    

    Neuraxle is a sklearn-like framework for hyperparameter tuning and AutoML in deep learning projects !

    0 讨论(0)
  • 2020-12-12 10:53
    format_train_y=[]
    for n in train_y:
        format_train_y.append(n[0])
    
    0 讨论(0)
  • 2020-12-12 10:55

    Y = y.values[:,0]

    Y - formated_train_y

    y - train_y

    0 讨论(0)
  • 2020-12-12 10:56

    I also encountered this situation when I was trying to train a KNN classifier. but it seems that the warning was gone after I changed:
    knn.fit(X_train,y_train)
    to
    knn.fit(X_train, np.ravel(y_train,order='C'))

    Ahead of this line I used import numpy as np.

    0 讨论(0)
  • 2020-12-12 10:56

    Another way of doing this is to use ravel

    model = forest.fit(train_fold, train_y.values.reshape(-1,))
    
    0 讨论(0)
  • 2020-12-12 11:04

    use below code:

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

    if you are still getting slap by error as identical as below ?

    Unknown label type: %r" % y
    

    use this code:

    y = train_y.ravel()
    train_y = np.array(y).astype(int)
    model = forest.fit(train_fold, train_y)
    
    0 讨论(0)
提交回复
热议问题