【问题标题】:Obscure Error when Fitting CatBoostClassifier in Python在 Python 中拟合 CatBoostClassifier 时出现模糊错误
【发布时间】: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


    【解决方案1】:

    SparseDtype 是 pandas 0.24.0 版中的新内容。安装了最新版本的熊猫。 https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.SparseDtype.html

    【讨论】:

      猜你喜欢
      • 2018-08-30
      • 2019-12-05
      • 2018-02-18
      • 2018-04-26
      • 2020-09-15
      • 1970-01-01
      • 1970-01-01
      • 2022-11-05
      • 1970-01-01
      相关资源
      最近更新 更多