2017-10-23 3 views
1

少しの背景のために、私はnnetパッケージを使って簡単なニューラルネットワークを構築しています。nnetモデルからのAUCの計算

私のデータセットには、多くの因子と連続可変機能があります。連続変数を扱うために、私はscalecenterを適用し、それぞれを平均で除算し、そのSDで除算します。

私はニューラルネットワークモデルの結果からROC & AUCプロットを生成しようとしています。

model1 <- nnet(Cohort ~ .-Cohort, 
      data = train.sample, 
      size = 1) 

は、私は次の関数を呼び出し、いくつかの予測を取得するには:

以下の私の基本的なニューラルネットワークモデルの構築に使用するコードです今

train.predictions <- predict(model1, train.sample) 

を、これはtrain.predictionsオブジェクトを割り当て0 & 1値からなる大きな行列に変換する。私がしたいことは、各予測のクラス確率を得ているので、pROCパッケージを使用してROC曲線をプロットすることができます。

train.predictions <- predict(model1, train.sample, type="prob") 

しかし、私はエラーを取得する:

だから、私は私の予測関数に次のパラメータを追加してみました

Error in match.arg(type) : 'arg' should be one of “raw”, “class”

にはどうすれば出力からクラス確率を得ることについて行くことができますか?

答えて

0

テスト/検証用データセットを仮定するとtrain.testであり、そしてtrain.labelsは真のクラスラベルが含まれています。あなたの助けのための

train.predictions <- predict(model1, train.test, type="raw") 

## This might not be necessary: 
detach(package:nnet,unload = T) 

library(ROCR) 

## train.labels:= A vector, matrix, list, or data frame containing the true 
## class labels. Must have the same dimensions as 'predictions'. 

## computing a simple ROC curve (x-axis: fpr, y-axis: tpr) 
pred = prediction(train.predictions, train.labels) 
perf = performance(pred, "tpr", "fpr") 
plot(perf, lwd=2, col="blue", main="ROC - Title") 
abline(a=0, b=1) 
+0

感謝。少しの研究をした後、列車関数の 'classProbs'パラメータもクラス確率と実際の予測 – Sam

+0

を返すと思いますが、コメントを残してください。 –

関連する問題