การจัดการกับตัวทำนายที่มีข้อมูลน้อย

Machine Learning ด้วย caret ใน R

Zach Mayer

Data Scientist at DataRobot and co-author of caret

ตัวแปรที่ไม่มี (หรือมีน้อย) variance

  • บางตัวแปรมีข้อมูลน้อยมาก
    • ค่าคงที่ (ไม่มี variance เลย)
    • เกือบคงที่ (variance ต่ำมาก)
  • แต่ละ fold ของ CV อาจมีคอลัมน์ค่าคงที่ได้ง่าย
    • ซึ่งอาจทำให้โมเดลเกิดปัญหาได้
  • โดยทั่วไปควรตัดตัวแปรที่มี variance ต่ำมากออก
Machine Learning ด้วย caret ใน R

ตัวอย่าง: คอลัมน์ค่าคงที่ใน mtcars

# Reproduce dataset from last video
data(mtcars)
set.seed(42)
mtcars[sample(1:nrow(mtcars), 10), "hp"] <- NA
Y <- mtcars$mpg
X <- mtcars[, 2:4]
# Add constant-valued column to mtcars
X$bad <- 1
Machine Learning ด้วย caret ใน R

ตัวอย่าง: คอลัมน์ค่าคงที่ใน mtcars

# Try to fit a model with PCA + glm
model <- train(
  X, Y, method = "glm", 
  preProcess = c("center", "scale", "medianImpute", "pca"))
Warning in preProcess.default(thresh = 0.95, k = 5, method = c("medianImpute",  :
  These variables have zero variances: bad
Something is wrong; all the RMSE metric values are missing:
      RMSE        Rsquared  
 Min.   : NA   Min.   : NA  
 1st Qu.: NA   1st Qu.: NA  
 Median : NA   Median : NA  
 Mean   :NaN   Mean   :NaN  
 3rd Qu.: NA   3rd Qu.: NA  
 Max.   : NA   Max.   : NA  
 NA's   :1     NA's   :1   
Machine Learning ด้วย caret ใน R

caret ช่วยได้อีกครั้ง

  • "zv" ลบคอลัมน์ค่าคงที่ออก
  • "nzv" ลบคอลัมน์ที่เกือบคงที่ออก
# Have caret remove those columns during modeling
set.seed(42)
model <- train(
  X, Y, method = "glm", 
  preProcess = c("zv", "center", "scale", "medianImpute", "pca")
)
min(model$results$RMSE)
3.402557
Machine Learning ด้วย caret ใน R

มาฝึกกันเถอะ!

Machine Learning ด้วย caret ใน R

Preparing Video For Download...