我试图重现的例子在这里,但使用RandomForestClassifer
。
我看不到如何转换这部分代码
# Learn to predict each class against the other
classifier = OneVsRestClassifier(svm.SVC(kernel='linear', probability=True,
random_state=random_state))
y_score = classifier.fit(X_train, y_train).decision_function(X_test)
我试过了
# Learn to predict each class against the other
classifier = OneVsRestClassifier(RandomForestClassifier())
y_score = classifier.fit(X_train, y_train).decision_function(X_test)
但我明白了
AttributeError:基本估算器没有Decision_function属性。
有解决方法吗?
好吧,您应该知道它的decision_function
用途。它仅与SVM分类器一起使用,原因是它给出了数据点与分隔数据的超平面之间的距离,而当您使用时RandomForestClassifier
,则没有意义。您可以使用RFC支持的其他方法。predict_proba
如果要获取分类数据点的概率,则可以使用。
这是支持功能的参考
仅提及RFC do support oob_decision_function
,这是您的训练集的实际费用估计。
因此,只需将您的行替换为-
y_score = classifier.fit(X_train, y_train).predict_proba(X_test)
或者
y_score = classifier.fit(X_train, y_train).predict(X_test)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句