Cross validation in CATBOOST Regressor: ValueError: Classification metrics can't handle a mix of binary and continuous targets
Cross validation in CATBOOST Regressor: ValueError: Classification metrics can't handle a mix of binary and continuous targets
我有一个数据框没有空值,只有数字值(我做了必要的转换)
CATBOOST 实施
from catboost import CatBoostRegressor
from sklearn.model_selection import cross_val_score
CatBoost_clf=CatBoostRegressor()
CatBoost_clf.fit(X, y)
print('Train Accuracy',cross_val_score(CatBoost_clf, X_train, y_train,
cv=3, scoring='accuracy'))
print('Test Accuracy',cross_val_score(CatBoost_clf, X_test, y_test, cv=3,
scoring='accuracy'))
错误
> ----> 5 print('Accuracy:',cross_val_score(CatBoost_clf, X, y, cv=3, scoring='accuracy'))
> ValueError: Classification metrics can't handle a mix of binary and continuous targets
如何在 CATBOOST 上计算交叉验证精度(cv=3 或验证集的 3 次迭代)?(输出 y 的值为 0 和 1)
你应该使用的是CatBoostClassifier
。
您正在使用 CatBoostRegressor
,它旨在根据连续值(例如 0.43823)最大限度地减少误差。分类器,例如 CatBoostClassifier
,采用分类输入值(例如 0 或 1),这就是您所拥有的。在您的示例中,y
是:
0 1
1 0
2 0
3 0
4 0
5 0
6 1
这绝对是绝对的,而不是连续的。
我有一个数据框没有空值,只有数字值(我做了必要的转换)
CATBOOST 实施
from catboost import CatBoostRegressor
from sklearn.model_selection import cross_val_score
CatBoost_clf=CatBoostRegressor()
CatBoost_clf.fit(X, y)
print('Train Accuracy',cross_val_score(CatBoost_clf, X_train, y_train,
cv=3, scoring='accuracy'))
print('Test Accuracy',cross_val_score(CatBoost_clf, X_test, y_test, cv=3,
scoring='accuracy'))
错误
> ----> 5 print('Accuracy:',cross_val_score(CatBoost_clf, X, y, cv=3, scoring='accuracy'))
> ValueError: Classification metrics can't handle a mix of binary and continuous targets
如何在 CATBOOST 上计算交叉验证精度(cv=3 或验证集的 3 次迭代)?(输出 y 的值为 0 和 1)
你应该使用的是CatBoostClassifier
。
您正在使用 CatBoostRegressor
,它旨在根据连续值(例如 0.43823)最大限度地减少误差。分类器,例如 CatBoostClassifier
,采用分类输入值(例如 0 或 1),这就是您所拥有的。在您的示例中,y
是:
0 1
1 0
2 0
3 0
4 0
5 0
6 1
这绝对是绝对的,而不是连续的。