การเทรนโมเดล

Machine Learning แบบ End-to-End

Joshua Stapleton

Machine Learning Engineer

มีดโกนของออคแคม

  • คำอธิบายที่ง่ายที่สุดที่เพียงพอคือดีที่สุด
  • เลือกโมเดลที่เรียบง่ายเมื่อมีตัวเลือก

ตัวอย่างภาพแสดงหลักการของมีดโกนของออคแคม

Machine Learning แบบ End-to-End

ตัวเลือกโมเดล

Logistic Regression

  • หา decision boundary ระหว่างคลาส
  • sklearn.linear_model.LogisticRegression

Support Vector Classifier

  • หาระนาบเพื่อแยกคลาส
  • sklearn.svm.SVC

Decision Tree

  • หา "กฎ" ง่ายๆ เพื่อจำแนกข้อมูล
  • sklearn.tree.DecisionTreeClassifier

Random Forest

  • รวม decision tree หลายต้นเข้าด้วยกัน
  • sklearn.ensemble.RandomForestClassifier
Machine Learning แบบ End-to-End

โมเดลอื่นๆ

โมเดล Deep Learning

  • Neural Networks
  • Convolutional Neural Networks
  • Generative Pretrained Transformer (GPT)

K-Nearest Neighbors (KNN)

  • อัลกอริทึม supervised learning

XGBoost

Machine Learning แบบ End-to-End

หลักการเทรนโมเดล

โมเดล:

  • ใช้ชุดข้อมูลที่ทำความสะอาดและจัดการฟีเจอร์แล้ว
  • เรียนรู้รูปแบบจากข้อมูล training
  • มุ่งทำนายการวินิจฉัยโรคหัวใจ

หลักการ:

  • โมเดลต้องสามารถ generalize กับข้อมูลใหม่ที่ไม่เคยเห็น
  • "สำรอง" ข้อมูลบางส่วนไว้ทดสอบหลังเทรนเสร็จ
  • สัดส่วน training/testing มักอยู่ที่ 70/30 หรือ 80/20
  • ใช้ sklearn.model_selection.train_test_split ได้
Machine Learning แบบ End-to-End

การเทรนโมเดล

# Importing necessary libraries
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression

# Split the data into training and testing sets (80:20) X_train, X_test, y_train, y_test = train_test_split(features, heart_disease_y, test_size=0.2, random_state=42)
# Define the models logistic_model = LogisticRegression(max_iter=200)
# Train the model logistic_model.fit(X_train, y_train)
Machine Learning แบบ End-to-End

การดึงผลการทำนายจากโมเดล

# Jane Doe's health data, for example: [age, cholesterol level, blood pressure, etc.]
jane_doe_data = [45, 230, 120, ...]

# Reshape the data to 2D, because scikit-learn expects a 2D array-like input jane_doe_data = jane_doe_data.reshape(1, -1)
# Use the model to predict Jane's heart disease diagnosis probabilities jane_doe_probabilities = logistic_model.predict_proba(jane_doe_data) jane_doe_prediction = logistic_model.predict(jane_doe_data)
Machine Learning แบบ End-to-End

การดึงผลการทำนายจากโมเดล (ต่อ)

# Print the probabilities
print(f"Jane Doe's predicted probabilities: {jane_doe_probabilities[0]}")
print(f"Jane Doe's predicted health condition: {jane_doe_prediction[0]}")
Jane Doe's predicted health condition probabilities: [0.2 0.8]

Jane Doe's predicted health condition: 1
Machine Learning แบบ End-to-End

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

Machine Learning แบบ End-to-End

Preparing Video For Download...