การ Generalize ของโมเดล: Bootstrapping และ Cross-Validation

ฝึกตอบคำถามสัมภาษณ์ Machine Learning ด้วย Python

Lisa Stuart

Data Scientist

ภาพรวมบทที่ 4

  • Bootstrapping/Cross-Validation --> การ Generalize ของโมเดล
  • คลาสที่ไม่สมดุล
  • Feature ที่มีความสัมพันธ์กัน
  • การเลือกโมเดลแบบ Ensemble
ฝึกตอบคำถามสัมภาษณ์ Machine Learning ด้วย Python

การ Generalize ของโมเดล

  • ความสามารถของโมเดล ML ในการทำงานได้ดีกับข้อมูลที่ยังไม่เคยเห็น
    • ชุดข้อมูลทดสอบ
    • ข้อมูลในอนาคต
  • Train metrics $\approx$ test metrics
  • โมเดลที่ Overfit จะ Generalize ไม่ได้
ฝึกตอบคำถามสัมภาษณ์ Machine Learning ด้วย Python

Decision Tree

กราฟ Decision Tree

1 https://medium.com/@rnbrown/creating-and-visualizing-decision-trees-with-python-f8e8fa394176
ฝึกตอบคำถามสัมภาษณ์ Machine Learning ด้วย Python

โหนดของ Decision Tree

โหนดรากของ Decision Tree

ฝึกตอบคำถามสัมภาษณ์ Machine Learning ด้วย Python

ข้อดีและข้อเสีย

กราฟ Decision Tree

  • ข้อดี:
    • เข้าใจง่าย
    • แสดงภาพได้ง่าย
  • ข้อเสีย:
    • Overfit ได้ง่าย
    • ถือว่าเป็น Greedy
    • มี Bias เมื่อคลาสไม่สมดุล
ฝึกตอบคำถามสัมภาษณ์ Machine Learning ด้วย Python

Random Forest

Random Forest

1 https://www.researchgate.net/figure/Random-Forest-visualization_fig11_326560291
ฝึกตอบคำถามสัมภาษณ์ Machine Learning ด้วย Python

K-Fold Cross-Validation

K-Fold Cross-Validation

1 https://scikit-learn.org/stable/modules/cross_validation.html
ฝึกตอบคำถามสัมภาษณ์ Machine Learning ด้วย Python

ฟังก์ชัน

# decision tree
`sklearn.tree.DecisionTreeClassifier` 

# random forest 
`sklearn.ensemble.RandomForestClassifier`

# cross-validated grid search
`sklearn.model_selection.GridSearchCV` 

# model accuracy
`sklearn.metrics.accuracy_score` 

# train/test split function
`sklearn.model_selection.train_test_split`

# Parameters that gave best results
`cross-val_model.best_params_`

# Mean cross-validated score of 
# estimator with best params 
`cross-val_model.best_score_`
ฝึกตอบคำถามสัมภาษณ์ Machine Learning ด้วย Python

GridSearchCV และ RandomSearchCV

Grid Search

ฝึกตอบคำถามสัมภาษณ์ Machine Learning ด้วย Python

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

ฝึกตอบคำถามสัมภาษณ์ Machine Learning ด้วย Python

Preparing Video For Download...