2017-11-12 8 views
0

私は、誤った分類であるmisrate.testの値を出力しようとしているループ内の各反復の後に、10の異なるシードを使用して自分のニューラルネットワークの誤分類を出力しようとしています。ここでは、データ+コードスニペットのプレビューですが、私は私が(new.testを持っていない)、正確にあなたの質問を再現することはできません各反復後に値を出力するR

V1 V70 V30 V86 V22 V107 V46 V78 V94 V62 V91  
    V76 
    4 7 1.000 -0.421 0.931 -0.114 -0.186 1.000 0.695 -0.363 1.000 
    -0.949 -0.606 
    11 7 1.000 1.000 1.000 -0.973 -1.000 0.167 -0.121 0.265 -0.415 
    -1.000 -1.000 
    15 7 -0.870 -1.000 -0.289 -1.000 -0.279 -1.000 -1.000 -1.000 -1.000 
    -0.715 0.918 
    16 7 0.758 -1.000 -0.535 0.901 0.508 -0.786 -0.913 -1.000 -0.796 
    -0.293 0.913 
    23 7 0.047 0.531 -0.983 0.212 -0.965 1.000 0.343 -0.427 0.993 
    -1.000 -0.857 
    26 7 -0.158 0.912 -1.000 -0.173 0.469 -0.117 -1.000 -1.000 -0.977 
    -0.020 0.974 


library(nnet) 
diff.seed <- c(1,66,70,222,1345,766,453,2999,7654,10000) 
for(i in diff.seed){ 
set.seed(i) #Set different seed 
digit.nnet <- nnet(V1~., data=new.train, size = 5, rang=0.1, decay=5e-4, 
maxit=1000) #Train the network on new.train 

y.hat <- as.numeric(predict(digit.nnet,new.test, type = "class")) #Apply on 
new.test which is same as new.train 

misrate.test <- sum(y.hat != 
new.test[,1])/length(new.test[,1])#Misclassification rate 
misrate.test #Attempt to output it 
} 
+2

あなたは[ 'cat'](https://stat.ethz.ch/R-manual/R-devel/library/base/を使用することができます。これらの動作するはずのhtml/cat.html)、['print'](https://stat.ethz.ch/R-manual/R-devel/library/base/) html/print.html)、['message'](https://stat.ethz.ch/R-manual/R-devel/library/base/html/message.html)、['警告 '](https ://stat.ethz.ch/R-manual/R-devel/library/base/html/warning.html)?あるいは、おそらく['lapply'や' sapply'を使って 'misrate.test'をベクターに取り込むことを考えています(https://stat.ethz.ch/R-manual/R-devel/library/base/html)。 /lapply.html)? – r2evans

+0

あなたの 'for'ループの中で' print(misrate.test) 'を試してください –

+0

私はちょうどベクトルにそれらを入れて各反復後に' misrate.test'の異なる値を取得しようとしています –

答えて

0

私のプログラム実行した後、その値のデータnew.trainをすることはできませんと呼ばれる、しかし、1つ

library(nnet) 
diff.seed <- c(1,66,70,222,1345,766,453,2999,7654,10000) 
for(i in diff.seed) { 
    set.seed(i) #Set different seed 
    digit.nnet <- nnet(V1~., data=new.train, size = 5, rang=0.1, decay=5e-4, maxit=1000) #Train the network on new.train 
    y.hat <- as.numeric(predict(digit.nnet,new.test, type = "class")) #Apply on new.test which is same as new.train 

    misrate.test <- sum(y.hat != new.test[,1])/length(new.test[,1])#Misclassification rate 
    print(misrate.test) #Attempt to output it 
} 

または

misrates <- sapply(diff.seed, function(i) { 
    set.seed(i) #Set different seed 
    digit.nnet <- nnet(V1~., data=new.train, size = 5, rang=0.1, decay=5e-4, maxit=1000) #Train the network on new.train 
    y.hat <- as.numeric(predict(digit.nnet,new.test, type = "class")) #Apply on new.test which is same as new.train 

    misrate.test <- sum(y.hat != new.test[,1])/length(new.test[,1])#Misclassification rate 
    misrate.test 
}) 
+0

new.testはnew.trainと同じデータです –

+0

*効果*については、おそらくテストデータが何であるかは関係ありません。これらの方法のいずれかを試しましたか?あなたの意図する結果に近いものはどれですか? – r2evans

+0

狂気のように狂ったように見えますが、それはうまくいきません。 –