2017-06-29 68 views
0

请在建立模型和检查准确性时查找附加的错误。我正在使用H2o软件包。 我已经创建模型为h2o模型。我想在测试和验证数据中应用模型。我在使用h中的h2o.confusionMatrix函数时出现“下标越界”错误

我的R代码里面是: -

library(mlbench) 
library(h2o) 
h2o.init(nthreads = -1) 
data("BreastCancer") 

#Adjusting data types 
data<-BreastCancer[,-1] #remove the ID column 
#converting all columns to numeric type 
data[,c(1:ncol(data))]<-sapply(data[,c(1:ncol(data))],as.numeric) 
#convert class column to factor type 
data[,'Class']<-as.factor(data[,'Class']) 

#converting in the h2o format 
splitsample<-sample(1:3,size=nrow(data),prob=c(0.6,0.2,0.2),replace=TRUE) 
train_h2o<-as.h2o(data[splitsample==1,]) 
val_h2o<- as.h2o(data[splitsample==2,]) 
test_h2o<-as.h2o(data[splitsample==3,]) 
model<- h2o.deeplearning(x=1:9,# column number for predictors 
         y=10, #column number for label 
         #data in H2o format 
         training_frame = train_h2o, 
         #or 'Tanh' 
         # TanhWithDropout means Tanh function with regularization 
         activation = "TanhWithDropout", 
         #% of inputs dropout 
         # It is used to drop bad or curropted or noise data 
         input_dropout_ratio = 0.2, 
         #balanced the two class 
         balance_classes = TRUE, 
         #two hidden layers of 10 units 
         hidden = c(10,10), 
         #% for nodes dropout 
         # dropout probability for hidden layers 
         hidden_dropout_ratios = c(0.3,0.3), 
         #max no. of epochs 
         # Times of iterate data 
         epochs = 10, 
         seed=0) 
h2o.confusionMatrix(model) 


#validation confusion matrix 

h2o.confusionMatrix(model,newdata=val_h2o) 

我的错误是:

错误在res $ model_metrics [1L]:下标越界

的请人帮助我深入学习。我非常感谢你。

我有错误的代码: -

h2o.confusionMatrix(模型,newdata = val_h2o)

Error in res$model_metrics[[1L]] : subscript out of bounds

+1

请发布一个完全可重现的例子(包括数据,或使用像虹膜这样的内置数据集,以及所有的代码)。 –

+0

@ErinLeDell我更新了我的文章,请帮助我。谢谢。 –

回答

0

我无法重现的错误,所以我假设你使用的是一些旧版本的水。在稳定释放H2O(今天是3.10.5.2)时,我可以毫无错误地执行你的代码。

> h2o.confusionMatrix(model,newdata=val_h2o) 
Confusion Matrix (vertical: actual; across: predicted) for max f1 @ threshold = 0.228804884732884: 
     1 2 Error Rate 
1  89 2 0.021978 =2/91 
2  0 46 0.000000 =0/46 
Totals 89 48 0.014599 =2/137 

如果遇到在未来的错误,请务必尝试升级到H2O的最新的稳定版本,然后再试一次,看看是否报告错误之前修复了这个bug。稳定版本的链接始终位于此page以及CRAN上。我们经常发布,所以最好确保您始终运行最新版本。

+1

谢谢。我更新了软件包。现在,它运行良好。 –