【发布时间】:2021-07-08 06:33:54
【问题描述】:
我正在尝试将 CatBoost 应用于我的分类特征列之一,但出现以下错误:
CatBoostError: Invalid type for cat_feature[non-default value idx=0,feature_idx=2]=68892500.0 : cat_features must be integer or string, real number values and NaN values should be converted to string.
我可以使用 one-hot 编码,但这里的许多人说 CatBoost 似乎更擅长处理这个问题并且不太容易过度拟合模型。
我的数据由三列组成,“国家”、“年份”、“电话用户”。 Target 是“Country”,“year”和“phone users”是 Feature。
数据:
Country year phone users
Ireland 1989 978
France 1990 854
Spain 1991 882
Turkey 1992 457
... ... ...
到目前为止我的代码:
X = df.loc[115:305]
y = df.loc[80:, 0]
cat_features = list(range(0, X_pool.shape[1]))
Output: [0, 1, 2]
X_train, X_val, y_train, y_val = train_test_split(X_pool, y_pool,
test_size=0.2, random_state=0)
cbc = CatBoostClassifier(iterations=5, learning_rate=0.1)
cbc.fit(X_train, y_train, eval_set=(X_val, y_val),
cat_features=cat_features, verbose=False)
print("Model Evaluation Stage")
在适应 catboost 模型之前,我需要运行 LabelEncoder 吗?我在这里错过了什么?
【问题讨论】:
标签: python machine-learning train-test-split catboost