複数の前処理手法

Rで学ぶ caret を使った Machine Learning

Zach Mayer

Data Scientist at DataRobot and co-author of caret

preProcess の世界

  • 中央値やKNN補完以外にも多くの手法があります
  • 複数の前処理を連結できます
  • 線形モデルの一般的な「レシピ」(順序が重要)
    • 中央値補完 ⇒ 中心化 ⇒ 標準化 ⇒ glm を学習
  • 詳細は ?preProcess を参照
Rで学ぶ caret を使った Machine Learning

例: mtcars の前処理

# 欠損を含むデータを作成
data(mtcars)
set.seed(42)
mtcars[sample(1:nrow(mtcars), 10), "hp"] <- NA
Y <- mtcars$mpg
X <- mtcars[,2:4] # <- Missing at random
# 線形モデルの「レシピ」を使用
set.seed(42)
model <- train(
  X, Y, method = "glm",
  preProcess = c("center", "scale", "medianImpute")
)
print(min(model$results$RMSE))
3.612713
Rで学ぶ caret を使った Machine Learning

例: mtcars の前処理

# 学習前にPCA
set.seed(42)
model <- train(
  X, Y, method = "glm",
  preProcess = c("center", "scale", "medianImpute", "pca")
)
min(model$results$RMSE)
3.402557
Rで学ぶ caret を使った Machine Learning

例: mtcars の前処理

# Spatial sign 変換
set.seed(42)
model <- train(
  X, Y, method = "glm",
  preProcess = c("center", "scale", "medianImpute", "spatialSign")
)
min(model$results$RMSE)
4.284904
Rで学ぶ caret を使った Machine Learning

前処理チートシート

  • まずは中央値補完
  • 欠損が無作為でない場合はKNN補完を検討
  • 線形モデルでは…
    • 中心化と標準化
    • PCA と spatial sign を試す
  • 木ベースモデルは前処理がほぼ不要
Rで学ぶ caret を使った Machine Learning

Passons à la pratique !

Rで学ぶ caret を使った Machine Learning

Preparing Video For Download...