【发布时间】:2021-02-08 09:11:42
【问题描述】:
我在尝试将 CatBoostClassifier 拟合到训练数据时收到一个模糊的错误。我在下面创建了一个简单的数据集来帮助说明问题:
from sklearn.model_selection import train_test_split
# Initialize a dataframe
d = {'response': [1,0,1,0,1,0,0,0,0,1],
'color': ['red','blue','yellow','blue','red','blue','blue','yellow','red','red'],
'status': ['open','pending','open','open','closed','pending','closed','open','closed','open'],
'age': [45,10,58,22,42,35,55,26,32,59],
'income': [95000,40000,100000,55000,70000,60000,45000,75000,65000,90000]}
df = pd.DataFrame(data=d)
# Create X and y matrices
X = df.drop(['response'], axis=1)
y = df.response
# Split into train and test data
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=.2, random_state=42)
现在我将尝试在下面拟合 CatBoostClassifier:
from catboost import CatBoostClassifier
cat_features = ['color', 'status']
cb = CatBoostClassifier(iterations=100, random_state=42, eval_metric='F1')
cb.fit(X_train, y_train, cat_features=cat_features, plot=True, eval_set=(X_test, y_test))
我在尝试拟合声明 AttributeError: module 'pandas' has no attribute 'SparseDtype' 的模型时收到以下错误。我不确定我是否理解这是指什么或如何更正该问题。任何有关如何解决此错误的反馈将不胜感激!
我正在运行 python 3.6.8,目前安装了 pandas==0.23.4 和 catboost==0.24.2。
【问题讨论】:
标签: python pandas classification catboost