2017-04-04 6 views
0

これは恐らく疑問な質問ですが、RでH2O Predict関数を使用すると、スコアリングデータから列を保持するように指定できる方法があるかどうか疑問に思っています。具体的には、私の一意のIDキーを保持したい。新しいデータセットの採点時にIDキー(または他の列)を保持していますか?

今のところ、元のデータセットにインデックスキーを割り当て、スコアに1つのインデックスキーを割り当ててスコアリングデータセットにスコアをマージするという、非常に効率の悪いアプローチを行ってしまいます。むしろ「このデータセットをスコアリングしてx、y、z ....列を維持する」と言っています。何かアドバイス?

非効率なコード:予測フレームの行が同じ順序になっているので、

#Use H2O predict function to score new data 
NL2L_SCore_SetScored.hex = h2o.predict(object = best_gbm, newdata = 
NL2L_SCore_Set.hex) 

#Convert scores hex to data frame from H2O 
NL2L_SCore_SetScored.df<-as.data.frame(NL2L_SCore_SetScored.hex) 
#add index to the scores so we can merge the two datasets 
NL2L_SCore_SetScored.df$ID <- seq.int(nrow(NL2L_SCore_SetScored.df)) 



#Convert orignal scoring set to data frame from H2O 
NL2L_SCore_Set.df<-as.data.frame(NL2L_SCore_Set.hex) 
#add index to original scoring data so we can merge the two datasets 
NL2L_SCore_Set.df$ID <- seq.int(nrow(NL2L_SCore_Set.df)) 


#Then merge by newly created ID Key so I have the scores on my scoring data 
#set. Ideally I wouldn't have to even create this key and could keep 
#original Columns from the data set, which include the customer id key 

Full_Scored_Set=inner_join(NL2L_SCore_Set.df,NL2L_SCore_Set.df, by="ID") 

答えて

1

よりもむしろ参加をして、あなたは単に、予測フレームへのID列をカラムに結合することができます。

Rの例(これはデモンストレーションのみを目的としている私は、元の訓練セットに予測していたという事実を無視する):

predict setosa versicolor virginica id 
1 setosa 0.9989301 0.0005656447 0.0005042210 1 
2 setosa 0.9985183 0.0006462680 0.0008354416 2 
3 setosa 0.9989298 0.0005663071 0.0005038929 3 
4 setosa 0.9989310 0.0005660443 0.0005029535 4 
5 setosa 0.9989315 0.0005649384 0.0005035886 5 
6 setosa 0.9983457 0.0011517334 0.0005025218 6 
:今

library(h2o) 
h2o.init() 

data(iris) 
iris$id <- 1:nrow(iris) #add ID column 
iris_hf <- as.h2o(iris) #convert iris to an H2OFrame 

fit <- h2o.gbm(x = 1:4, y = 5, training_frame = iris_hf) 
pred <- h2o.predict(fit, newdata = iris_hf) 
pred$id <- iris_hf$id 
head(pred) 

あなたはID列と予測フレームを持っています

関連する問題