问题:当要预测的值是绝对值时不起作用 catboost版本:0.8 作业系统:Windows CPU:英特尔
当我也可以预测的值(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:无法将字符串转换为float:“某些缺陷”
答案 0 :(得分:0)
Catboost尝试将其转换为浮点数,因为它需要为数字。使用LabelEncoder可以做到,效果很好,我已经在MultiClass问题中顺利使用了它。