Machine Learning คือ สาขาหนึ่งของ AI ที่ทำให้คอมพิวเตอร์สามารถเรียนรู้จากข้อมูลและประสบการณ์ โดยไม่ต้องเขียนโปรแกรมกำหนดพฤติกรรมไว้ตายตัว
เหมือนการเรียนที่มีครูคอยบอกคำตอบ
เหมือนให้เด็กจัดกลุ่มของเล่นเอง โดยไม่บอกว่าจัดยังไง
เหมือนการฝึกสุนัขด้วยการให้รางวัลและลงโทษ
ทำไมต้องแบ่ง? เหมือนให้นักเรียนทำข้อสอบชุดเดิมที่เคยทำ - อาจได้คะแนนเต็มแต่ไม่ได้เข้าใจจริง!
ข้อมูลทั้งหมด (100%) ├── Training Set (60-70%) - ใช้สอนโมเดล ├── Validation Set (15-20%) - ใช้ปรับ hyperparameters └── Test Set (15-20%) - ใช้ประเมินผลสุดท้าย
หลักการ: "บอกฉันว่าคุณคบใครเป็นเพื่อน แล้วฉันจะบอกว่าคุณเป็นคนแบบไหน"
d = √[(x₁-x₂)² + (y₁-y₂)²]
d = |x₁-x₂| + |y₁-y₂|
หลักการ: ทำงานเหมือนเกม 20 คำถาม - ถามทีละข้อจนได้คำตอบ
สีเหลือง? / \ ใช่ ไม่ / \ ขนาดใหญ่? สีแดง? / \ / \ ใช่ ไม่ ใช่ ไม่ | | | | แตงโม กล้วย แอปเปิล ส้ม
เลือก feature ที่ดีที่สุด
แบ่งข้อมูลตาม feature
Entropy = -Σ(p_i × log₂(p_i)) IG = Entropy(parent) - Σ(weighted Entropy)
Gini = 1 - Σ(p_i²)
Bayes' Theorem
P(class|features) = P(features|class) × P(class) / P(features)
ความน่าจะเป็นที่เป็น class นั้น เมื่อเห็น features เหล่านี้ = ความน่าจะเป็นที่เจอ features ใน class นั้น × ความน่าจะเป็นของ class โดยทั่วไป ÷ ความน่าจะเป็นที่เจอ features
สมมติว่าทุก feature เป็นอิสระต่อกัน
Predicted Positive Negative Actual Positive TP FN Negative FP TN
F1 = 2 × (Precision × Recall) / (Precision + Recall)
รอบ 1: [Valid] [Train] [Train] [Train] [Train] รอบ 2: [Train] [Valid] [Train] [Train] [Train] รอบ 3: [Train] [Train] [Valid] [Train] [Train] รอบ 4: [Train] [Train] [Train] [Valid] [Train] รอบ 5: [Train] [Train] [Train] [Train] [Valid]
Use Case วินิจฉัยโรคหายาก (Rare Disease Diagnosis)
# Train: 500 patients, 30 symptoms # Predict: new patient symptoms → disease yes/no Model: Simple Decision Tree Accuracy: 92% with only 500 samples
Use Case E-commerce Product Recommendation
# Train: 10M transactions, 500K users, 100K products # Predict: user profile → top 10 products Model: Deep Neural Network (can learn complex patterns) Performance: 35% click-through rate improvement
Use Case House Price Prediction
# Train: area, bedrooms, location, age (4 features) # Predict: house features → price in THB Model: Random Forest (handles non-linear well) Data: 5,000 houses → RMSE: ±200,000 THB
Use Case Bank Loan Approval
# Train: income, debt, credit_score, employment # Predict: applicant → approve/reject + reason Model: Logistic Regression Output: "Rejected: debt_ratio (0.8) > threshold (0.6)" Requirement: ธปท. ต้องอธิบายเหตุผลการปฏิเสธได้
Use Case Netflix Movie Recommendation
# Train: 100M ratings, viewing history, time patterns # Predict: user → next movie to watch Model: Deep Neural Network (Matrix Factorization + DNN) Focus: Accuracy > Explainability (users don't care why)
Use Case Credit Card Fraud Detection
# Train: 1M transactions, 50 features # Predict: new transaction → fraud/normal in <100ms Model: Logistic Regression Speed: 0.1ms per transaction (can handle 10,000 TPS) Alternative: Deep model → distilled to simple model
Use Case Medical Image Diagnosis (X-Ray)
# Train: 100,000 X-ray images # Predict: X-ray image → disease detection Model: Ensemble of 5 CNNs (ResNet, EfficientNet, etc.) Speed: 5 seconds per image (acceptable for radiology) Accuracy: 98.5% (worth the wait)
Challenge Predict 30-day readmission risk
Data Size: 8,000 patients (ข้อมูลน้อย) Features: 45 (lab results, medications, diagnosis) Requirement: ต้องอธิบายได้ (medical decision) Speed: Not critical (batch processing) Selected: Logistic Regression with L2 Avoided: Deep Learning (data too small) Result: AUC 0.78, can explain risk factors to doctors
Challenge Recommend Thai content to global users
Data Size: Small for Thai content (cold start problem) Features: Viewing history, content metadata, subtitles Requirement: Handle sparse data + new content Selected: Transfer Learning - Pre-trained embeddings from global data, Fine-tune on Thai viewing patterns - Fallback to content-based for new shows Result: 40% increase in Thai content viewership
เข้าใจข้อมูลก่อน
Preprocessing ให้ดี
ป้องกัน data leakage
Document ทุกอย่าง
อย่าเชื่อ accuracy อย่างเดียว
อย่า overfit validation set
อย่าใช้ default เสมอ
Machine Learning ไม่ใช่เวทมนตร์
แต่เป็นเครื่องมือที่ทรงพลัง
เมื่อใช้อย่างเข้าใจและเหมาะสม!