2016-07-18 4 views
0

例をhttp://scikit-learn.org/stable/auto_examples/model_selection/plot_roc.htmlに再現しようとしていますが、RandomForestClassiferを使用しています。私は、コードOnevsrestClassifierとランダムフォレスト

# 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: Base estimator doesn't have a decision_function attribute. 

を取得し、回避策はありますか?

+0

なぜdownvote -

だからあなたのような行を置き換えますか? – eleanora

答えて

3

あなたはdecision_functionが何のために使われているかを知っておくべきです。 SVM分類器で使用されるのは、データを分離する超平面からのデータ点の距離を与えるのに対し、RandomForestClassifierを使用する場合は意味がありません。 RFCでサポートされている他のメソッドを使用できます。機密データポイントの確率を取得したい場合は、predict_probaを使用できます。ここで

はちょうどあなたのトレーニングセットの袋推定値のうちである、 oob_decision_functionをサポートしていませんRFCに言及するためにサポート functions

のリファレンスです。

y_score = classifier.fit(X_train, y_train).predict_proba(X_test) 

または

y_score = classifier.fit(X_train, y_train).predict(X_test) 
+0

ありがとうございました。 – eleanora

関連する問題