3
votes

Can Label Propagation be used for semi-supervised regression tasks in scikit-learn? According to its API, the answer is YES. http://scikit-learn.org/stable/modules/label_propagation.html

However, I got the error message when I tried to run the following code.

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)

It shows that "ValueError: Unknown label type: 'continuous'" in the label_propagation.LabelSpreading().fit(X,y_30) line.

How should I solve the problem? Thanks a lot.

1

1 Answers

6
votes

It looks like the error in the documentation, code itself clearly is classification only (beggining of the .fit call of the BasePropagation class):

    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])

In theory you could remove the "check_classification_targets" call and use "regression like method", but it will not be the true regression since you will never "propagate" any value which is not encountered in the training set, you will simply treat the regression value as the class identifier. And you will be unable to use value "-1" since it is a codename for "unlabeled"...