Way*_*yne 3 python regression machine-learning scikit-learn
标签传播可以用于 scikit-learn 中的半监督回归任务吗?根据其 API,答案是肯定的。 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)
Run Code Online (Sandbox Code Playgroud)
它在 label_propagation.LabelSpreading().fit(X,y_30) 行中显示“ValueError: Unknown label type: 'continuous'”。
我应该如何解决问题?非常感谢。
看起来文档中的错误,代码本身显然只是分类(开始.fit调用BasePropagation 类):
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])
Run Code Online (Sandbox Code Playgroud)
理论上你可以删除“check_classification_targets”调用并使用“regression like method”,但它不会是真正的回归,因为你永远不会“传播”训练集中没有遇到的任何值,你只会处理回归值作为类标识符。而且您将无法使用值“-1”,因为它是“未标记”的代号...
| 归档时间: |
|
| 查看次数: |
1693 次 |
| 最近记录: |