为什么分类器链要求至少 2 个类,当我有它时

数据挖掘 Python scikit-学习 线性回归 多标签分类
2022-02-15 23:25:23

我正在使用带有逻辑回归的分类器链,当我尝试使用 fit 时,我得到

这个求解器需要数据中至少 2 个类的样本,但数据只包含一个类:1

但我很确定我的数据中有两个类,这是我的X_test

<5825x2000 sparse matrix of type '<class 'numpy.float64'>'
    with 219990 stored elements in Compressed Sparse Row format>

我有这个作为我的y_train

array([[1, 0, 0, ..., 0, 1, 0],
       [1, 0, 0, ..., 1, 1, 0],
       [1, 0, 0, ..., 0, 1, 0],
       ...,
       [1, 0, 0, ..., 1, 1, 0],
       [1, 0, 0, ..., 0, 1, 0],
       [1, 0, 0, ..., 0, 1, 0]])

这是我要运行的部分

cc_clf = ClassifierChain(LogisticRegression(penalty='l1', C=1, dual=False, solver='liblinear'))
cc_clf.fit(X_train, y_train)
cc_y_pred = cc_clf.predict(X_test)

我是否错误地使用了分类器链?当我将相同的数据传递给一个 vs 休息时,它可以工作。

clf = OneVsRestClassifier(classifier1)
clf.fit(X_train, y_train)
0个回答
没有发现任何回复~