【问题标题】:ValueError: Unknown label type: 'unknown'-Labels are numericValueError:未知标签类型:“未知”-标签是数字
【发布时间】:2018-03-16 14:26:12
【问题描述】:

我正在为二进制分类问题构建一个随机森林分类器。我的标签都是数字的。

print labels.unique()
[1 0]

print type(labels)
    <class 'pandas.core.series.Series'>
print labels.shape
(3000,)

但是当我用 Gridsearchcv 拟合模型时

pipeline = Pipeline(steps=[('scaler', scaler), ('algorithm', algo)])
cv = StratifiedShuffleSplit(labels, 5, test_size=0.25, random_state=42)
gs = GridSearchCV(pipeline, param_grid, cv=cv, scoring='f1')
gs.fit(features, labels)

我收到了这个错误

ValueError: Unknown label type: 'unknown'

但是当我使用

gs.fit(features, labels.astype(int))

一切正常。谁能告诉我标签的问题出在哪里?

【问题讨论】:

    标签: python scikit-learn random-forest grid-search


    【解决方案1】:

    您只需使用tolist() 方法更改要列出的标签类型。使用

    labels_lst = labels.tolist()
    

    Scikit-learn 无法自动将系列转换为标签列表。

    【讨论】:

      猜你喜欢
      • 2018-01-02
      • 2021-05-11
      • 2021-08-17
      • 2018-12-16
      • 2020-05-14
      • 2019-07-03
      • 2018-01-01
      • 2017-08-29
      • 2018-12-10
      相关资源
      最近更新 更多