通过 scikit-learn 进行回归的半监督学习

Semi-supervised learning for regression by scikit-learn

Label Propagation 可以用于 scikit-learn 中的半监督回归任务吗? 根据其API,答案是YES。 http://scikit-learn.org/stable/modules/label_propagation.html

但是,当我尝试 运行 以下代码时收到错误消息。

from sklearn import datasets
from sklearn.semi_supervised import label_propagation
import numpy as np
rng=np.random.RandomState(0)
boston = datasets.load_boston()
X=boston.data
y=boston.target
y_30=np.copy(y)
y_30[rng.rand(len(y))<0.3]=-999
label_propagation.LabelSpreading().fit(X,y_30)

在label_propagation.LabelSpreading().fit(X,y_30)行显示"ValueError: Unknown label type: 'continuous'"

我该如何解决这个问题?非常感谢。

看起来像是文档中的错误,代码本身显然只是 class化(BasePropagation class.fit 调用的开始):

    check_classification_targets(y)

    # actual graph construction (implementations should override this)
    graph_matrix = self._build_graph()

    # label construction
    # construct a categorical distribution for classification only
    classes = np.unique(y)
    classes = (classes[classes != -1])

理论上你可以删除 "check_classification_targets" 调用并使用 "regression like method",但这不是真正的回归,因为你永远不会 "propagate" 任何在训练集,您只需将回归值视为 class 标识符。您将无法使用值“-1”,因为它是 "unlabeled"...

的代号