X_train=train.loc[:,'X1':'X29']
y_train=train.loc[:,'Y']
X_test=test.loc[:,'X1':'X29']
y_test=test.loc[:,'Y']
cat_features=["X1","X2","X3","X4","X5","X6","X7","X8","X9","X10","X11","X12","X13","X14","X15","X16","X17","X18","X19","X20","X21","X22","X23","X24","X25","X26","X27","X28","X29"]
from catboost import Pool, CatBoostClassifier, cv
from sklearn.model_selection import GridSearchCV
# 加载数据
train_data = Pool(data=X_train,
label=y_train,
cat_features=cat_features)
test_data = Pool(data=X_test,
label=y_test,
cat_features=cat_features)
# 定义参数空间
param_grid1 = {'learning_rate': [0.01, 0.05, 0.1],
'depth': [4, 6, 8],
'iterations': [300, 500]}
# 定义CatBoost分类器
cat = CatBoostClassifier()
# 使用GridSearch搜索最佳参数
CATgrid_search = GridSearchCV(estimator=cat,
param_grid=param_grid1,
scoring='accuracy',
cv=5)
CATgrid_search.fit(train_data)
# 输出最佳模型参数
print(CATgrid_search.best_params_)
以上是我的代码,但是报错Singleton array array(<catboost.core.Pool object at 0x00000243E3252AC0>, dtype=object) cannot be considered a valid collection.我不理解为什么,哪里出问题了?
字面意思这不是一个有效的连接