当预测值为分类变量时无法工作

问题:当预测值为分类变量时无法工作
CatBoost版本:0.8
操作系统:Windows
CPU:Intel

当我的预测值(Y)为分类变量时,出现了“无法转换为浮点数”的错误。我是否需要对Y值进行独热编码?

感谢帮助。

Python代码:

from sklearn.model_selection import train_test_splittrain_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 CatBoostClassifiermodel=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: 无法将字符串转换为浮点数:’some defect’


回答:

CatBoost尝试将其转换为浮点数,因为它需要它是一个数字。使用LabelEncoder来处理它,效果很好,我在多类问题中使用它没有遇到任何问题。

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注