dask_xgboost.predict 有效但无法显示 - 数据必须是一维的

dask_xgboost.predict works but cannot be shown -Data must be 1-dimensional

我正在尝试使用 XGBoost 创建模型。
似乎我设法训练了模型,但是,当我尝试预测我的测试数据并查看实际预测时,我收到以下错误:

ValueError: Data must be 1-dimensional

这就是我尝试预测数据的方式:

from dask_ml.model_selection import train_test_split
import dask
import xgboost
import dask_xgboost
from dask.distributed import Client
import dask_ml.model_selection as dcv

#split the data
x_train,x_test,y_train,y_test=train_test_split(x,y,test_size=0.33,random_state=42)

client = Client(n_workers=10, threads_per_worker=1)

#Trying to do hyperparamter running
model_xgb = xgb.XGBRegressor(seed=42,verbose=True)


params={
    'learning_rate':[0.1,0.01,0.05],
    'max_depth':[1,5,8],
    'gamma':[0,0.5,1],
    'scale_pos_weight':[1,3,5]
}

grid_search = GridSearchCV(model_xgb, params, cv=3, scoring='neg_mean_squared_error')

grid_search.fit(x_train, y_train)

#train data with best paraeters
bst = dask_xgboost.train(client, grid_search.best_params_, x_train, y_train, num_boost_round=10)

#predict data
dask_xgboost.predict(client, bst, x_test).persist()

预测的最后一行有效,但是当我将计算添加到末尾以查看实际数组时,我得到了维度错误:

dask_xgboost.predict(client, bst, x_test).persist().compute()
>>>ValueError: Data must be 1-dimensional

如何使用 .predict 获得预测?

dask-xgboostpip 页面所述:

Dask-XGBoost has been deprecated and is no longer maintained.
The functionality of this project has been included directly
in XGBoost. To use Dask and XGBoost together, please use
xgboost.dask instead
https://xgboost.readthedocs.io/en/latest/tutorials/dask.html.

您提供的代码缺少一些赋值和表达式(例如 x 是如何定义的,GridSearchCV 是从哪里导入的)。一些可能应该更改的内容:

# note the .dask
model_xgb = xgb.dask.DaskXGBRegressor(seed=42, verbose=True)

grid_search = GridSearchCV(model_xgb, params, cv=3, scoring='neg_mean_squared_error')

grid_search.fit(x_train, y_train)

#train data with best params
model_xgb.client = client
model_xgb.set_params(grid_search.best_params_)
model_xgb.fit(X_train, y_train, eval_set=[(X_test, y_test)])