バイアス-バリアンスのトレードオフ

Rで学ぶTree-Based ModelsによるMachine Learning

Sandro Raabe

Data Scientist

ハイパーパラメータ

  • モデラーが設定
  • 例: tree_depth
  • ドキュメントを確認
?decision_tree

複数のハイパーパラメータ

Rで学ぶTree-Based ModelsによるMachine Learning

【単純モデル】

simple_spec <- decision_tree(tree_depth = 2) %>% 
    set_mode("regression")

simple_spec %>% fit(final_grade ~ .,
                    data = training_data)

【複雑モデル】

complex_spec <- decision_tree(tree_depth = 15) %>% 
    set_mode("regression")

complex_spec %>% fit(final_grade ~ .,
                     data = training_data)

深さ2の木

深さ30の木

Rで学ぶTree-Based ModelsによるMachine Learning

複雑モデル ― 過学習 ― 高バリアンス

学習データでの予測: 良好

学習データの誤差は小さい

mae(train_results, 
    estimate = .pred,
    truth = final_grade)
# A tibble: 1 x 3
  .metric  .estimate
1 mae          0.204

テストデータでの予測: かけ離れている

テストデータの誤差は大きい

mae(test_results, 
    estimate = .pred,
    truth = final_grade)
# A tibble: 1 x 3
  .metric  .estimate
1 mae          0.947
Rで学ぶTree-Based ModelsによるMachine Learning

単純モデル ― アンダーフィット ― 高バイアス

学習・テストともに誤差が大きい:

bind_rows(training = mae(train_results, estimate = .pred, truth = final_grade),
          test     = mae(test_results,  estimate = .pred, truth = final_grade),
          .id = "dataset")
# A tibble: 2 x 4
  dataset    .metric  .estimate
  <chr>      <chr>        <dbl>
1 training   mae          0.754
2 test       mae          0.844
Rで学ぶTree-Based ModelsによるMachine Learning

バイアス-バリアンスのトレードオフ

バイアス-バリアンスのトレードオフ

 

  • 単純なモデル -> 高バイアス
  • 複雑なモデル -> 高バリアンス
  • バイアスとバリアンスのトレードオフ
  • 最適点(sweet spot)を狙う
Rで学ぶTree-Based ModelsによるMachine Learning

過学習の検出

アウトオブサンプル/CV:

collect_metrics(cv_fits)


# A tibble: 1 x 3
  .metric    mean     n 
1 mae       2.432     5
  • CV誤差が大きい
  • 過学習/高バリアンス
  • 複雑さを下げる!

インサンプル:

mae(training_pred, 
    estimate = .pred, 
    truth = final_grade)
# A tibble: 1 x 2
  .metric  .estimate
1 mae          0.228
  • 学習誤差が小さい
Rで学ぶTree-Based ModelsによるMachine Learning

アンダーフィットの検出

インサンプル:

mae(training_pred, estimate = .pred, truth = final_grade)
# A tibble: 1 x 2
  .metric .estimate
  <chr>       <dbl>
1 mae         2.432
  • インサンプル/学習誤差が大きい
  • アンダーフィット/高バイアス
  • 複雑さを上げる!
Rで学ぶTree-Based ModelsによるMachine Learning

トレードオフしよう!

Rで学ぶTree-Based ModelsによるMachine Learning

Preparing Video For Download...