我正在尝试通过R包H2O
使用h2o
进行深度学习,
并想询问H2O
是否可以保存和重新加载培训数据以供将来的额外培训使用?
我的代码:
iris.train <- irisdata[-1,]
iris.test <- irisdata[1,]
res.dl <- h2o.deeplearning(x = 1:4, y = 5_offset, data = iris.train, activation = "Rectifier")
pred.dl <- h2o.predict(object=res.dl, newdata=iris.test)
res.err.dl[i] <- ifelse(as.character(as.matrix(pred.dl)[1,1]) == as.character(as.matrix(iris.test)[1,5]),0,1)
答案 0 :(得分:0)
h2o.saveModel(object, dir = "", name = "", filename = "", force = FALSE)
和
h2o.loadModel(path, conn = h2o.getConnection())
答案 1 :(得分:0)
我最近在h2o版本2.8.6中构建深度学习模型时使用的一个工作示例。该模型保存在hdf中。对于最新版本,您可能必须删除classification = T开关并且必须更换数据与training_frame
library(h2o)
h = h2o.init(ip="xx.xxx.xxx.xxx", port=54321, startH2O = F)
cTrain.h2o <- as.h2o(h,cTrain,key="c1")
cTest.h2o <- as.h2o(h,cTest,key="c2")
nh2oD<-h2o.deeplearning(x =c(1:12),y="tgt",data=cTrain.h2o,classification=F,activation="Tanh",
rate=0.001,rho=0.99,momentum_start=0.5,momentum_stable=0.99,input_dropout_ratio=0.2,
hidden=c(12,25,11,11),hidden_dropout_ratios=c(0.4,0.4,0.4,0.4),
epochs=150,variable_importances=T,seed=1234,reproducible = T,l1=1e-5,
key="dn")
hdfsdir<-"hdfs://xxxxxxxxxx/user/xxxxxx/xxxxx/models"
h2o.saveModel(nh2oD,hdfsdir,name="DLModel1",save_cv=T,force=T)
test=h2o.loadModel(h,path=paste0(hdfsdir,"/","DLModel1"))