H2Oパッケージを触っていてエラーが出たのでメモ
環境
- ubuntu14.04
- R-3.3.1
- h2o-2.0.1
インストール
まずここを参考にインストールします
cmake
1 2 3 4 5 6 | wget https://cmake.org/files/v3.6/cmake-3.6.1.tar.gz tar zxvfp cmake-3.6.1.tar.gz cd cmake-3.6.1 ./configure make make install |
h2o
1 2 3 4 5 6 | wget https://github.com/h2o/h2o/archive/v2.0.1.tar.gz tar zxvfp v2.0.1.tar.gz cd h2o-2.0.1/ cmake . make make install |
設定
1 2 3 4 5 6 | mkdir /usr/local/etc/h2o/ cd /usr/local/etc/h2o/ openssl genrsa 2048 > cert.key openssl req -new -key cert.key > cert.csr openssl x509 -days 3650 -req -signkey cert.key < cert.csr > cert.pem touch /usr/local/etc/h2o/error-log |
起動
1 | sudo /usr/local/bin/h2o -m daemon -c /usr/local/etc/h2o/h2o.conf |
サンプル
ここのサンプルを実行してみます
1 2 3 | library("h2o") localH2O <- h2o.init(ip = "localhost", port = 54321, startH2O = TRUE, nthreads=-1) cfData<-h2o.importFile(localH2O,path="https://raw.githubusercontent.com/ozt-ca/tjo.hatenablog.samples/master/r_samples/public_lib/jp/conflict_sample.txt") |
ここでエラー発生
1 | Error: is.character(key) && length(key) == 1L && !is.na(key) is not TRUE |
どうやら、h2oの仕様が変わったようです。こちらを参考に修正します
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | cfData<-h2o.importFile(path="https://raw.githubusercontent.com/ozt-ca/tjo.hatenablog.samples/master/r_samples/public_lib/jp/conflict_sample.txt") res.err.dl<-rep(0,100) numlist<-sample(3000,100,replace=F) for(i in 1:100){ cf.train <- cfData[-numlist[i],] cf.test <- cfData[numlist[i],] res.dl <- h2o.deeplearning(x = 1:7, y = 8, data = cf.train, activation = "Tanh",hidden=rep(20,2)) pred.dl <- h2o.predict(object=res.dl,newdata=cf.test[,-8]) pred.dl.df <- as.data.frame(pred.dl) test.dl.df <- as.data.frame(cf.test) res.err.dl[i] <- ifelse(as.character(pred.dl.df[1,1])==as.character(test.dl.df[1,8]),0,1) } |
またまたエラー
1 2 | Error in h2o.deeplearning(x = 1:7, y = 8, data = cf.train, activation = "Tanh", : unused argument (data = cf.train) |
仕様をみると、また変わっていました。以下のように修正します
1 | res.dl <- h2o.deeplearning(x = 1:7, y = 8, training_frame = cf.train, activation = "Tanh",hidden=rep(20,2)) |
続けます
1 | sum(res.err.dl) |
これでうまく実行できました
終了
1 | sudo kill -TERM `cat /usr/local/etc/h2o/pid-file` |
仕様がよく変わるので、メジャーバージョンアップ時は要注意です