在进行预测时,使用代码如下:
model_AdaBoostRegressor.fit(df_train_X, df_train_y)
actual_lst = df_test_y.values.tolist()
pred_lst = model_AdaBoostRegressor.predict(df_test_X)
score = rmse(actual_lst, pred_lst)
print( "\n model_AdaBoostRegressor Score:",score,"\n")
出现如下警告
/home/anaconda3/envs/tensorflow/lib/python3.7/site-packages/sklearn/ensemble/bagging.py:398: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().
return column_or_1d(y, warn=True)
经查询后,添加.values.ravel() 换成如下代码。即可解决问题.
model_AdaBoostRegressor.fit(df_train_X, df_train_y.values.ravel())
actual_lst = df_test_y.values.tolist()
pred_lst = model_AdaBoostRegressor.predict(df_test_X)
score = rmse(actual_lst, pred_lst)
print( "\n model_AdaBoostRegressor Score:",score,"\n")