问题:当要预测的值是分类 catboost 版本时不起作用:0.8 操作系统:Windows CPU:intel
当我的值( Y )也被预测为分类时,出现“不能转换为浮动”的错误。我必须对 Y 值进行一次热编码吗?
感谢帮助。
Python代码:
from sklearn.model_selection import train_test_split
train_set , test_set = train_test_split(trainPLData, test_size=0.2, random_state=42)
for col in ['product_line','a_plant', 'a_pa', 'b_plant','b_pa',
'c_plant', 'c_pa', 'D_plant', 'D_pa', 'fam', 'pkg','defect']:
train_set[col] = train_set[col].astype('category')
test_set[col] = test_set[col].astype('category')
x_train = train_set[['product_line','a_plant', 'a_pa', 'b_plant','b_pa',
'c_plant', 'c_pa', 'D_plant', 'D_pa', 'fam', 'pkg']]
y_train = train_set[['defect']]
x_test = test_set[['product','a_plant', 'a_pa', 'b_plant','b_pa',
'c_plant', 'c_pa', 'D_plant', 'D_pa', 'fam', 'pkg']]
y_test = test_set[['defect']]
from catboost import CatBoostClassifier
model=CatBoostClassifier(iterations=50, depth=3, learning_rate=0.1,one_hot_max_size=10)
categorical_features_indices = np.where(x_train.dtypes != np.float)[0]
print(categorical_features_indices)
model.fit(x_train, y_train,cat_features=categorical_features_indices,
eval_set=(x_test, y_test))
那么错误是:
ValueError:无法将字符串转换为浮点数:“一些缺陷”