【问题标题】:ValueError: pos_label=1 is not a valid label: array(['COLLECTION', 'PAIDOFF'], dtype='<U10')ValueError: pos_label=1 不是有效标签:array(['COLLECTION', 'PAIDOFF'], dtype='<U10')
【发布时间】:2021-04-16 08:01:50
【问题描述】:

我首先遇到了pos_label这个错误,我首先导入了这个库

from sklearn.metrics import jaccard_similarity_score

因为版本错误我再次导入这个库

from sklearn.metrics import jaccard_score

这是我的运行代码:

depth_range = range(1, 10)
jaccard_similarity_score_ = []
f1_score_ = []

for d in depth_range:
    dt = DecisionTreeClassifier(criterion = 'gini', max_depth = d)
    dt.fit(X_train, y_train)
    dt_yhat = dt.predict(X_test)
    ja = jaccard_score(y_test, dt_yhat, "yes")
    jaccard_similarity_score_.append(ja)
    f1_score_.append(f1_score(y_test, dt_yhat, average = 'weighted'))

我收到此错误:

ValueError: pos_label=1 is not a valid label: array(['COLLECTION', 'PAIDOFF'], dtype='

【问题讨论】:

  • 嗨,你能给我们展示一下数据集吗?可能像前 5 行和列的名称?否则我认为没有足够的信息来找出问题所在。

标签: python machine-learning decision-tree


【解决方案1】:

您需要在要预测为 1 的类别中提及 pos_label 值。因此,对于您的情况,PAIDOFF 将是一个正标签,因此请包括 pos_label='PAIDOFF'

【讨论】:

    猜你喜欢
    • 2018-10-16
    • 2020-05-22
    • 2021-02-20
    • 2013-08-26
    • 2018-12-25
    • 2016-06-27
    • 2015-04-29
    • 2019-09-21
    相关资源
    最近更新 更多