2016-08-19 14 views
3

h2oパッケージを使用してバイナリクラシファイアのデフェーブルを試しています。モデルを作成した後、新しい(保留された)データセットにh2o.predictを使用すると、一部の行でPredictの出力が最も高い確率の値と一致しないことがわかりました。h2o.deeplearningでの予期しない予測

ここh2o's deeplearning tutorialから適応、再現性の例です:

library(h2o) 

h2o.init(nthreads=-1, max_mem_size="2G") 
h2o.removeAll() 


df <- h2o.importFile(path = "https://raw.githubusercontent.com/h2oai/h2o-tutorials/master/tutorials/data/covtype.full.csv") 

splits <- h2o.splitFrame(df, c(0.6,0.2), seed=1234) 
train <- h2o.assign(splits[[1]], "train.hex") # 60% 
valid <- h2o.assign(splits[[2]], "valid.hex") # 20% 
test <- h2o.assign(splits[[3]], "test.hex") # 20% 

response <- "Cover_Type" 
predictors <- setdiff(names(df), response) 

train$bin_response <- ifelse(train[,response]=="class_1", 0, 1) 
train$bin_response <- as.factor(train$bin_response) ##make categorical 

# apply same transforms to test 
test$bin_response <- ifelse(test[,response]=="class_1", 0, 1) 
test$bin_response <- as.factor(test$bin_response) 

dlmodel <- h2o.deeplearning(
    x=predictors, 
    y="bin_response", 
    training_frame=train, 
    hidden=c(10,10), 
    epochs=0.1 
    #balance_classes=T ## enable this for high class imbalance 
) 

pred <- h2o.predict(dlmodel, test) 

のは、簡単にするためにdplyrを使用して、Rにそれを持参し、いくつかの新しい列を追加することを操作してみましょう:今すぐ

pred_df <- bind_cols(
    select(as.data.frame(test), actual = bin_response), 
    as.data.frame(pred) 
) %>% 
    tbl_df %>% 
    mutate(
    derived_predict = factor(as.integer(p1 > p0)), 
    match = predict == derived_predict 
) 

私は考え予測は常に最も高い確率で列に一致する必要があると考えていますが、それは必ずしもそうではありません:

> pred_df %>% summarize(sum(match)/n()) 
# A tibble: 1 x 1 
    sum(match)/n() 
      <dbl> 
1  0.9691755 

なぜその値は正確に1ではありませんか?上記のコードの私の最新の実行では、p0p1値は

> pred_df %>% filter(!match) 
# A tibble: 3,575 x 6 
    actual predict  p0  p1 derived_predict match 
    <fctr> <fctr>  <dbl>  <dbl>   <fctr> <lgl> 
1  1  1 0.5226679 0.4773321    0 FALSE 
2  0  1 0.5165302 0.4834698    0 FALSE 
3  0  1 0.5225683 0.4774317    0 FALSE 
4  0  1 0.5120126 0.4879874    0 FALSE 
5  1  1 0.5342851 0.4657149    0 FALSE 
6  0  1 0.5335089 0.4664911    0 FALSE 
7  0  1 0.5182881 0.4817119    0 FALSE 
8  0  1 0.5094492 0.4905508    0 FALSE 
9  0  1 0.5309947 0.4690053    0 FALSE 
10  0  1 0.5234880 0.4765120    0 FALSE 
# ... with 3,565 more rows 

しかしh2o.predictが劣勢値を選択する理由はまだ説明していないことにかなり接近しています。

ここで何か問題がありますか?これはh2oのバグですか? h2oはここで私に提示するよりも予測を選ぶのに、意図的に多くの情報を使用しますか?

興味深いことに、私のderived_predictを使用すると髪で、わずかに高い精度が得られます。

> pred_df %>% 
+ summarize(
+  original = sum(actual == predict)  /n(), 
+  derived = sum(actual == derived_predict)/n() 
+ ) 
# A tibble: 1 x 2 
    original derived 
     <dbl>  <dbl> 
1 0.7794946 0.7827452 

答えて

2

私は同じ問題に遭遇しました。予測値とp1値を説明しようとしています。

H2Oは、分類のためにデフォルトで最大F1スコアを使用します。 p1列では、独自のしきい値を指定できます。

ドキュメントを読むことはあまり明白ではありません。しかし、あなたはR小冊子でそれを見つけることができます。 DRF、GBM、ディープラーニングの小冊子には不思議ではありません。

+2

恐ろしい!他の人がhttps://groups.google.com/forum/#!topic/h2ostream/TkNkMFprzf0に私に指摘しましたが、少し古くなっていましたが、私は 'h2o.find_threshold_by_max_metric(h2o.performance(dlmodel) f1 ")'は実際に使用されているような閾値でした – ClaytonJY

関連する問題