回帰木の評価指標

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

Sandro Raabe

Data Scientist

性能をどう測るか

  • 分類: 正解率(混同行列)
  • 回帰: 「正解」は相対的で、二値の正誤はない

⇒ 予測が真値からどれだけ離れているかを測る

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

回帰の代表的な指標

  • 平均絶対誤差(MAE)
  • 二乗平均平方根誤差(RMSE)

 

MAE の直感:

平均差のプロット

 

 

 

 

 

MAE = 赤い棒の平均の長さ

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

数式と直感

 

$$MAE = \frac{1}{n} \sum_{i=1}^n\left| actual_i - predicted_i \right|$$

 

  • 絶対偏差の合計を予測数で割ったもの

$$\quad MSE = \quad \frac{1}{n} \sum_{i=1}^n\left( actual_i - predicted_i \right)^2$$

  • 平均二乗誤差
Rで学ぶTree-Based ModelsによるMachine Learning

数式と直感

 

$$MAE = \frac{1}{n} \sum_{i=1}^n\left| actual_i - predicted_i \right|$$

 

  • 絶対偏差の合計を予測数で割ったもの

$$RMSE = \sqrt{\frac{1}{n} \sum_{i=1}^n\left( actual - predicted \right)^2}$$

  • 二乗平均平方根誤差
  • 大きな誤差に高い重み
Rで学ぶTree-Based ModelsによるMachine Learning

コード: 予測

# parsnip と yardstick は tidymodels に含まれる
library(tidymodels)
# 予測してテストデータに追加
predictions <- predict(model, new_data = chocolate_test) %>%

bind_cols(chocolate_test)
# A tibble: 358 x 7
   .pred final_grade review_date cocoa_percent company_location
   <dbl>       <dbl>       <int>         <dbl> <fct>           
 1  2.5         2.75        2013          0.7  France          
 2  3.64        3.25        2014          0.8  France          
 3  3.3         3.5         2012          0.7  France          
 4  3.25        3.5         2011          0.72 Fiji            
# ... with 354 more rows, and 2 more variables: bean_type <fct>, broad_bean_origin <fct>
Rで学ぶTree-Based ModelsによるMachine Learning

コード: mae() と rmse()

# mae() で評価
mae(predictions,

estimate = .pred,
truth = final_grade)
# A tibble: 1 x 2
  .metric   .estimate
  <chr>         <dbl>
1 mae           0.363
# rmse() で評価
rmse(predictions,
     estimate = .pred,
     truth = final_grade)
# A tibble: 1 x 2
  .metric   .estimate
  <chr>         <dbl>
1 rmse          0.457
Rで学ぶTree-Based ModelsによるMachine Learning

評価してみましょう!

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

Preparing Video For Download...