【问题标题】:How to fix error of type "object of type 'CategoricalDtype' has no len()"?如何修复“'CategoricalDtype'类型的对象没有len()”类型的错误?
【发布时间】:2019-02-07 16:02:04
【问题描述】:

在训练数据中:x 的数据类型是“int64”,y 是“分类” 我无法在这个算法中拟合训练数据集..

我在“model.fit(x_train,y_train)”行中遇到错误

错误是“'CategoricalDtype' 类型的对象没有 len()”

    x=df.drop("income",axis=1)
    y=df["income"]
    from sklearn.model_selection import train_test_split         
    x_train,x_test,y_train,y_test=train_test_split(x,y,train_size=0.3,random_state=100)
    from sklearn.tree import DecisionTreeClassifier
    model=DecisionTreeClassifier(max_depth=4)
    model.fit(x_train,y_train)

【问题讨论】:

  • 请发布完整的错误跟踪以及您的数据样本

标签: python machine-learning


【解决方案1】:

尝试在y_train and y_test之后添加.tolist()

【讨论】:

    猜你喜欢
    • 2019-08-28
    • 2021-08-03
    • 2012-08-02
    • 2015-10-08
    • 1970-01-01
    • 2016-02-15
    • 2019-11-16
    • 2018-10-01
    相关资源
    最近更新 更多