การนำ trainControl กลับมาใช้ซ้ำ

Machine Learning ด้วย caret ใน R

Max Kuhn

Software Engineer at RStudio and creator of caret

ตัวอย่างจากสถานการณ์จริง

  • ข้อมูล: การเลิกใช้บริการของลูกค้าบริษัทโทรคมนาคม
  • ฝึกโมเดลหลายแบบและเลือกโมเดลที่ดีที่สุด
  • โมเดลทุกแบบต้องใช้ชุดข้อมูล train/test เดียวกัน
  • สร้าง object trainControl ร่วมกัน
Machine Learning ด้วย caret ใน R

ตัวอย่าง: ข้อมูลการเลิกใช้บริการของลูกค้า

# Summarize the target variables
library(caret)
library(C50)
data(churn)
table(churnTrain$churn) / nrow(churnTrain)
      yes        no 
0.1449145 0.8550855 
Machine Learning ด้วย caret ใน R

ตัวอย่าง: ข้อมูลการเลิกใช้บริการของลูกค้า

# Create train/test indexes
set.seed(42)
myFolds <- createFolds(churnTrain$churn, k = 5)
# Compare class distribution
i <- myFolds$Fold1
table(churnTrain$churn[i]) / length(i)
      yes        no 
0.1441441 0.8558559
Machine Learning ด้วย caret ใน R

ตัวอย่าง: ข้อมูลการเลิกใช้บริการของลูกค้า

myControl <- trainControl(
  summaryFunction = twoClassSummary,
  classProbs = TRUE,
  verboseIter = TRUE,
  savePredictions = TRUE,
  index = myFolds
)
  • ใช้ folds เพื่อสร้าง object trainControl
  • ใช้ cross-validation folds ชุดเดียวกันทุกโมเดล
Machine Learning ด้วย caret ใน R

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

Machine Learning ด้วย caret ใน R

Preparing Video For Download...