Skip to content

Bridge to Classical ML — Từ nền tảng đến Machine Learning

Bạn vừa hoàn thành 6 bài học — từ vector thô đến feature matrix sạch sẽ. Bây giờ câu hỏi quan trọng nhất: "Làm sao máy học được từ dữ liệu đó?" Bài này nối liền mọi thứ bạn đã biết vào quy trình ML thực tế, và chuẩn bị bạn cho ML Blueprint — hành trình xây dựng model thật sự.

🎯 Mục tiêu

Sau bài này, bạn sẽ:

  • Hiểu ML paradigm cốt lõi: X (features), y (target), fit, predict, evaluate
  • Biết cách và tại sao cần train/test split — mô phỏng "dữ liệu chưa thấy"
  • Nắm cross-validation (K-Fold, Stratified, Time Series) để đánh giá model đáng tin cậy
  • Phân biệt overfitting vs underfitting — trade-off nền tảng nhất của ML
  • Sẵn sàng bước vào ML Blueprint với tư duy đúng đắn

1. Phase 1 Recap — Bạn đã biết gì?

Trước khi tiến lên, hãy kiểm kê lại hành trang. Mỗi bài học là một viên gạch xây nên pipeline ML hoàn chỉnh:

BàiChủ đềBạn học được gì
01Vectors, Matrices, TensorsDữ liệu thực tế → cấu trúc toán học mà máy hiểu được
02Vectorization & BroadcastingTính toán nhanh trên toàn bộ array, không cần vòng lặp
03Matrix OperationsPhép nhân ma trận — ngôn ngữ chung của mọi mô hình ML
04EDA — Exploratory Data AnalysisHiểu dữ liệu trước khi train, phát hiện vấn đề sớm
05Feature EngineeringTạo tín hiệu (feature) từ dữ liệu thô, tăng sức mạnh cho model
06Imbalanced Data & StreamsXử lý dữ liệu lệch, dữ liệu liên tục — thực tế production

Bức tranh toàn cảnh

Raw Data  ──→  EDA  ──→  Feature Engineering  ──→  Feature Matrix (X, y)
 (messy)    (lesson 04)     (lesson 05)              (clean, ready)

                    Handle imbalance (lesson 06)

Kết quả: Bạn có thể nhận dữ liệu thô → làm sạch → tạo feature → xây dựng ma trận có cấu trúc, sẵn sàng cho training. Đó chính là 80% công việc thực tế của một ML Engineer.

💡 Quy tắc 80/20 trong ML

Trong production, 80% thời gian dành cho data preparation (những gì Phase 1 dạy bạn), chỉ 20% cho việc chọn và huấn luyện model. Nền tảng bạn vừa xây là phần khó nhất.


2. The ML Paradigm: X, y, predict

Mọi bài toán supervised learning đều tuân theo cùng một khuôn mẫu:

2.1. Các thành phần cốt lõi

  • X — Feature matrix: ma trận (n_samples × n_features), mỗi hàng là 1 mẫu dữ liệu
  • y — Target vector: vector (n_samples,), kết quả cần dự đoán
  • model.fit(X_train, y_train) — Học pattern từ dữ liệu
  • model.predict(X_test) — Dự đoán trên dữ liệu mới
  • evaluate(y_pred, y_test) — So sánh dự đoán với thực tế

2.2. Pipeline tổng thể

Raw Data → EDA → Features → X, y → Split → Train → Evaluate

                                 X_train, y_train
                                 X_test,  y_test

2.3. Code minh họa: sklearn interface

python
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score

# X: feature matrix (100 mẫu, 5 features)
# y: target vector (100 nhãn: 0 hoặc 1)
X = np.random.randn(100, 5)
y = (X[:, 0] + X[:, 1] > 0).astype(int)

# Split: 80% train, 20% test
X_train, X_test, y_train, y_test = train_test_split(
    X, y, test_size=0.2, random_state=42
)

# Train
model = LogisticRegression()
model.fit(X_train, y_train)

# Predict & Evaluate
y_pred = model.predict(X_test)
print(f"Accuracy: {accuracy_score(y_test, y_pred):.2%}")

📌 Tại sao sklearn?

Scikit-learn là thư viện ML phổ biến nhất cho classical ML. Mọi model đều dùng chung interface: .fit(), .predict(), .score(). Học một lần, dùng cho tất cả model.


3. Train/Test Split — Tại sao và Cách thực hiện

3.1. Mục đích: mô phỏng "dữ liệu chưa thấy"

Model ML cần được đánh giá trên dữ liệu mà nó chưa bao giờ thấy trong quá trình training. Nếu bạn đánh giá trên chính dữ liệu training → kết quả quá lạc quan, model có thể chỉ đang ghi nhớ chứ không học.

Toàn bộ dữ liệu (1000 mẫu)
├── Train set (800 mẫu) ← model học từ đây
└── Test set  (200 mẫu) ← đánh giá ở đây (KHÔNG ĐƯỢC chạm vào khi train!)

3.2. Tỷ lệ phổ biến

Tỷ lệKhi nào dùng
80/20Mặc định, phù hợp đa số trường hợp
70/30Khi dataset nhỏ, cần nhiều dữ liệu test hơn
90/10Khi dataset rất lớn (>100K mẫu)

3.3. Code thực hành

python
from sklearn.model_selection import train_test_split

# Split cơ bản
X_train, X_test, y_train, y_test = train_test_split(
    X, y,
    test_size=0.2,        # 20% cho test
    random_state=42,      # tái lập kết quả
    stratify=y            # giữ tỷ lệ class giống nhau
)

print(f"Train: {X_train.shape[0]} mẫu")
print(f"Test:  {X_test.shape[0]} mẫu")
print(f"Tỷ lệ class trong train: {np.bincount(y_train) / len(y_train)}")
print(f"Tỷ lệ class trong test:  {np.bincount(y_test) / len(y_test)}")

3.4. Stratified Split — Giữ tỷ lệ class

Với bài toán classification, stratify=y đảm bảo tỷ lệ class trong train và test giống với dữ liệu gốc. Đặc biệt quan trọng khi dữ liệu imbalanced (bài 06).

Dữ liệu gốc: 90% class 0, 10% class 1
├── Train (stratified): 90% class 0, 10% class 1  ✅
└── Test  (stratified): 90% class 0, 10% class 1  ✅

Không stratify → có thể:
├── Train: 95% class 0, 5% class 1   ❌ lệch
└── Test:  70% class 0, 30% class 1  ❌ lệch

⚠️ Time Series: KHÔNG shuffle!

Với dữ liệu chuỗi thời gian, tuyệt đối không xáo trộn trước khi split. Dùng time-based split: train trên quá khứ, test trên tương lai.

python
# ❌ SAI: shuffle time series
train_test_split(X, y, shuffle=True)

# ✅ ĐÚNG: split theo thời gian
split_idx = int(len(X) * 0.8)
X_train, X_test = X[:split_idx], X[split_idx:]
y_train, y_test = y[:split_idx], y[split_idx:]

Lý do: trong thực tế, bạn không thể dùng dữ liệu tương lai để dự đoán quá khứ. Shuffle = data leakage.


4. Cross-Validation — Đánh giá đáng tin cậy hơn

Train/test split có nhược điểm: kết quả phụ thuộc vào cách chia dữ liệu. Cross-validation giải quyết điều này.

4.1. K-Fold Cross-Validation

Chia dữ liệu thành K phần bằng nhau. Lần lượt dùng 1 phần làm test, K-1 phần còn lại làm train. Lặp K lần:

Fold 1: [TEST ] [train] [train] [train] [train]
Fold 2: [train] [TEST ] [train] [train] [train]
Fold 3: [train] [train] [TEST ] [train] [train]
Fold 4: [train] [train] [train] [TEST ] [train]
Fold 5: [train] [train] [train] [train] [TEST ]

→ Kết quả: trung bình score của 5 lần = ước lượng chính xác hơn

4.2. Các biến thể quan trọng

Phương phápĐặc điểmKhi nào dùng
K-FoldChia đều, xáo trộnMặc định, dữ liệu đủ lớn
Stratified K-FoldGiữ tỷ lệ class mỗi foldClassification, đặc biệt imbalanced
Time Series SplitExpanding window, không shuffleDữ liệu có yếu tố thời gian
Leave-One-OutK = n (mỗi lần bỏ 1 mẫu)Dataset rất nhỏ (<50 mẫu)

4.3. Time Series Split

Split 1: [train     ] [TEST]
Split 2: [train          ] [TEST]
Split 3: [train               ] [TEST]
Split 4: [train                    ] [TEST]

→ Window mở rộng dần, luôn train trên quá khứ, test trên tương lai

4.4. Code Cross-Validation

python
from sklearn.model_selection import cross_val_score, StratifiedKFold
from sklearn.ensemble import RandomForestClassifier

model = RandomForestClassifier(n_estimators=100, random_state=42)

# K-Fold cơ bản
scores = cross_val_score(model, X, y, cv=5, scoring='accuracy')
print(f"Accuracy: {scores.mean():.3f} ± {scores.std():.3f}")

# Stratified K-Fold (cho classification)
cv = StratifiedKFold(n_splits=5, shuffle=True, random_state=42)
scores = cross_val_score(model, X, y, cv=cv, scoring='f1')
print(f"F1 Score: {scores.mean():.3f} ± {scores.std():.3f}")

# Time Series Split
from sklearn.model_selection import TimeSeriesSplit
ts_cv = TimeSeriesSplit(n_splits=5)
scores = cross_val_score(model, X, y, cv=ts_cv, scoring='accuracy')
print(f"Time Series CV Accuracy: {scores.mean():.3f} ± {scores.std():.3f}")

💡 Cross-validation vs Train/Test Split

  • Train/Test Split: nhanh, dùng cho đánh giá cuối cùng
  • Cross-Validation: chậm hơn, nhưng ước lượng đáng tin cậy hơn, dùng cho model selection

Trong thực tế: dùng CV để chọn model và hyperparameters, sau đó dùng test set để đánh giá lần cuối.


5. Overfitting vs Underfitting — Trade-off nền tảng

Đây là khái niệm quan trọng nhất bạn cần nắm trước khi bước vào ML Blueprint.

5.1. Định nghĩa

  • Overfitting (quá khớp): Model ghi nhớ training data, hoạt động tốt trên train nhưng kém trên dữ liệu mới. Giống như học thuộc đáp án mà không hiểu bài.
  • Underfitting (chưa khớp): Model quá đơn giản, không nắm bắt được pattern. Giống như trả lời bài kiểm tra mà không học gì cả.

5.2. Learning Curve — Nhận biết qua biểu đồ

Error
│  ╲       ╱
│   ╲     ╱   ← test error tăng = OVERFITTING
│    ╲   ╱
│     ╲ ╱
│      ╳      ← điểm "vừa phải" = sweet spot
│     ╱ ╲
│    ╱   ╲    ← training error giảm
│   ╱     ╲
│  ╱
└──────────────── Model Complexity →
   Underfitting    OK     Overfitting

5.3. Dấu hiệu nhận biết

Train scoreTest scoreChẩn đoán
✅ Tốt92%90%Model học tốt, generalize tốt
❌ Overfit99%65%Model ghi nhớ, không generalize
❌ Underfit55%52%Model quá đơn giản

5.4. Regularization — Giải pháp chống overfitting (preview)

Regularization "phạt" model khi nó trở nên quá phức tạp:

  • L1 (Lasso): Đẩy một số trọng số về 0 → tự động chọn feature
  • L2 (Ridge): Thu nhỏ tất cả trọng số → model mượt hơn
  • Elastic Net: Kết hợp L1 + L2

📌 Preview — không cần hiểu sâu ngay

Regularization sẽ được giải thích chi tiết trong ML Blueprint. Ở đây bạn chỉ cần biết: nó tồn tại và nó giải quyết overfitting.


6. The Complete ML Pipeline

Ghép tất cả lại — đây là quy trình end-to-end từ dữ liệu thô đến đánh giá model:

6.1. Sáu bước

Step 1: EDA                 (bài 04) → Hiểu dữ liệu
Step 2: Feature Engineering (bài 05) → Tạo features
Step 3: Handle Imbalance    (bài 06) → Cân bằng dữ liệu
Step 4: Train/Test Split             → Tách train và test
Step 5: Cross-Validation             → Chọn model tốt nhất
Step 6: Final Evaluation             → Đánh giá trên test set

6.2. Code: Pipeline hoàn chỉnh

python
import numpy as np
import pandas as pd
from sklearn.model_selection import (
    train_test_split, cross_val_score, StratifiedKFold
)
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LogisticRegression
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import classification_report

# ── Step 1-3: Giả sử bạn đã có X, y sạch từ Phase 1 ──
# (EDA → Feature Engineering → Handle Imbalance)

# ── Step 4: Train/Test Split ──
X_train, X_test, y_train, y_test = train_test_split(
    X, y, test_size=0.2, random_state=42, stratify=y
)

# Scale features (fit trên train, transform cả train và test)
scaler = StandardScaler()
X_train_scaled = scaler.fit_transform(X_train)
X_test_scaled = scaler.transform(X_test)  # CHỈ transform, không fit!

# ── Step 5: Cross-Validation để chọn model ──
models = {
    "Logistic Regression": LogisticRegression(max_iter=1000),
    "Random Forest": RandomForestClassifier(n_estimators=100, random_state=42),
}

cv = StratifiedKFold(n_splits=5, shuffle=True, random_state=42)

for name, model in models.items():
    scores = cross_val_score(model, X_train_scaled, y_train, cv=cv, scoring='f1')
    print(f"{name}: F1 = {scores.mean():.3f} ± {scores.std():.3f}")

# ── Step 6: Chọn model tốt nhất → Đánh giá trên test set ──
best_model = RandomForestClassifier(n_estimators=100, random_state=42)
best_model.fit(X_train_scaled, y_train)

y_pred = best_model.predict(X_test_scaled)
print("\n--- Final Evaluation on Test Set ---")
print(classification_report(y_test, y_pred))

⚠️ Data Leakage khi scaling

Luôn fit scaler trên training set, rồi transform cả train lẫn test. Nếu bạn fit trên toàn bộ data trước khi split → thông tin từ test set "rò rỉ" vào training.

python
# ❌ SAI: fit trên toàn bộ data
scaler.fit(X)  # X bao gồm cả test → data leakage!
X_scaled = scaler.transform(X)
X_train, X_test = train_test_split(X_scaled, ...)

# ✅ ĐÚNG: fit trên train set
X_train, X_test = train_test_split(X, ...)
scaler.fit(X_train)
X_train_scaled = scaler.transform(X_train)
X_test_scaled = scaler.transform(X_test)

7. Supervised vs Unsupervised vs Reinforcement — Bản đồ nhanh

Trước khi đi sâu vào ML Blueprint, hãy biết vị trí của bạn trên bản đồ:

LoạiInputOutputVí dụ
SupervisedX + yDự đoán y mớiPhân loại email spam, dự đoán giá nhà
UnsupervisedChỉ XTìm patternsPhân cụm khách hàng, giảm chiều dữ liệu
ReinforcementAgent + EnvironmentTối đa rewardGame AI, robot điều hướng

📌 90% ML trong production là Supervised Learning

ML Blueprint sẽ tập trung vào supervised learning — nơi bạn có cả input (X) và đáp án (y) để model học. Đây là nền tảng trước khi khám phá unsupervised và reinforcement.


8. What's Next: The ML Blueprint

Phase 1 hoàn thành. Đây là lộ trình tiếp theo:

Thứ tựBài họcĐường dẫnBạn sẽ học
1Problem Framing/machine-learning/foundation/framingĐặt đúng câu hỏi cho ML
2Evaluation Metrics/machine-learning/foundation/evaluationAccuracy, Precision, Recall, F1, AUC-ROC
3Advanced Features/machine-learning/core/featuresFeature engineering nâng cao
4Model Selection/machine-learning/core/selectionChọn model phù hợp từng bài toán

Lesson Dependency Map

Phase 1 (hoàn thành)

  ├── 01 Vectors ──→ 02 Vectorization ──→ 03 Matrix Ops
  │                                            │
  ├── 04 EDA ──→ 05 Feature Eng ──→ 06 Imbalanced
  │                                       │
  └── 07 Bridge to ML (bài này) ◄─────────┘


  ML Blueprint
  ├── Foundation: Framing → Evaluation
  └── Core: Features → Selection → Tuning

🔥 GPU Paragraph — Tại sao Phase 1 quan trọng cho GPU Training

Với Phase 1 hoàn thành, bạn hiểu data structures (tensors), operations (matmul), và data preparation — những thứ xảy ra TRƯỚC khi GPU chạy training. ML Blueprint sẽ giới thiệu các model tận dụng sức mạnh GPU.

Hiểu nền tảng nghĩa là bạn sẽ biết TẠI SAO model train chậm: bad features? sai batch size? data bottleneck? — thay vì chỉ ném thêm GPU hours vào và hy vọng kết quả tốt hơn. Người hiểu data sẽ luôn thắng người chỉ biết tăng compute.


🧠 Common Beginner Misconception

"Tôi cần học hết mọi thuật toán trước khi bắt tay làm gì đó"

Sai. Hãy bắt đầu với Logistic RegressionRandom Forest — hai model này giải quyết 80% bài toán thực tế trong doanh nghiệp. ML Blueprint sẽ dạy bạn khi nào cần dùng model phức tạp hơn.

Quy tắc vàng: Model tốt nhất là model đơn giản nhất mà vẫn đáp ứng yêu cầu business. Không ai thưởng bạn vì dùng deep learning cho bài toán mà logistic regression đã giải được.


Fast Exercise — Pipeline hoàn chỉnh

Yêu cầu: Cho feature matrix X và target vector y đã chuẩn bị sẵn. Implement pipeline đầy đủ.

python
"""
BÀI TẬP: Hoàn thành pipeline ML từ đầu đến cuối.
Thay thế các dòng ... bằng code đúng.
"""
from sklearn.model_selection import train_test_split, cross_val_score
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score, f1_score
import numpy as np

# Dữ liệu giả lập (trong thực tế: từ Phase 1 pipeline)
np.random.seed(42)
X = np.random.randn(500, 10)
y = (X[:, 0] * 2 + X[:, 1] - X[:, 2] > 0).astype(int)

# Step 1: Train/Test Split (stratified, 80/20)
X_train, X_test, y_train, y_test = ...  # TODO

# Step 2: Scale features (fit trên train, transform cả hai)
scaler = StandardScaler()
X_train_scaled = ...  # TODO
X_test_scaled = ...   # TODO

# Step 3: Cross-validation trên train set
model = LogisticRegression(max_iter=1000)
cv_scores = ...  # TODO: 5-fold CV, scoring='f1'
print(f"CV F1: {cv_scores.mean():.3f} ± {cv_scores.std():.3f}")

# Step 4: Train final model và evaluate trên test set
model.fit(...)  # TODO
y_pred = model.predict(...)  # TODO

print(f"Test Accuracy: {accuracy_score(y_test, y_pred):.3f}")
print(f"Test F1:       {f1_score(y_test, y_pred):.3f}")
💡 Lời giải
python
# Step 1
X_train, X_test, y_train, y_test = train_test_split(
    X, y, test_size=0.2, random_state=42, stratify=y
)

# Step 2
scaler = StandardScaler()
X_train_scaled = scaler.fit_transform(X_train)
X_test_scaled = scaler.transform(X_test)

# Step 3
model = LogisticRegression(max_iter=1000)
cv_scores = cross_val_score(model, X_train_scaled, y_train, cv=5, scoring='f1')
print(f"CV F1: {cv_scores.mean():.3f} ± {cv_scores.std():.3f}")

# Step 4
model.fit(X_train_scaled, y_train)
y_pred = model.predict(X_test_scaled)
print(f"Test Accuracy: {accuracy_score(y_test, y_pred):.3f}")
print(f"Test F1:       {f1_score(y_test, y_pred):.3f}")

🪤 Gotcha — Test Set Contamination

⚠️ Dùng test data để tune hyperparameters = metrics lạc quan giả

Nếu bạn dùng test set để chọn hyperparameters (ví dụ: thử nhiều giá trị C cho Logistic Regression, chọn giá trị cho accuracy cao nhất trên test set) → bạn đã gián tiếp "nhìn thấy" test set.

Hậu quả: Metrics báo cáo cao hơn thực tế. Deploy lên production → hiệu suất tệ hơn mong đợi.

Giải pháp: Dùng 3-way split hoặc nested cross-validation:

Toàn bộ dữ liệu
├── Train set (60%)      ← train model
├── Validation set (20%) ← tune hyperparameters
└── Test set (20%)       ← đánh giá cuối cùng (KHÔNG CHẠM cho đến khi xong)
python
# 3-way split
X_temp, X_test, y_temp, y_test = train_test_split(
    X, y, test_size=0.2, random_state=42, stratify=y
)
X_train, X_val, y_train, y_val = train_test_split(
    X_temp, y_temp, test_size=0.25, random_state=42, stratify=y_temp
)
# 0.25 × 0.8 = 0.2 → kết quả: 60/20/20

📊 Performance Note — Tối ưu Cross-Validation

python
# Song song hóa CV trên nhiều CPU cores
scores = cross_val_score(
    model, X, y,
    cv=5,
    scoring='accuracy',
    n_jobs=-1  # sử dụng TẤT CẢ CPU cores
)

# Out-of-fold predictions (hữu ích cho stacking)
from sklearn.model_selection import cross_val_predict
y_oof = cross_val_predict(model, X, y, cv=5, n_jobs=-1)
# y_oof[i] = prediction khi mẫu i nằm trong fold test

💡 Khi nào cần cross_val_predict?

  • Khi bạn muốn out-of-fold predictions cho toàn bộ dataset (dùng trong ensemble/stacking)
  • Khi dataset lớn, dùng n_jobs=-1 để tận dụng đa nhân CPU
  • Khi cần phân tích chi tiết prediction error trên từng mẫu

🚫 Production Anti-pattern — Lãng phí dữ liệu khi deploy

⚠️ Đừng deploy model chỉ train trên train set

Sau khi validation xong, bạn đã chọn được model tốt nhất và hyperparameters phù hợp. Bước cuối: retrain trên train + validation trước khi deploy.

python
# ❌ SAI: deploy model chỉ train trên train set
final_model = best_model
final_model.fit(X_train, y_train)  # bỏ phí validation data
# deploy final_model...

# ✅ ĐÚNG: retrain trên toàn bộ non-test data
X_full_train = np.vstack([X_train, X_val])
y_full_train = np.concatenate([y_train, y_val])
final_model = best_model
final_model.fit(X_full_train, y_full_train)
# deploy final_model → model có nhiều data hơn → tốt hơn

Nguyên tắc: Model deployed nên được train trên TẤT CẢ dữ liệu có sẵn ngoại trừ test set. Nhiều data hơn = model tốt hơn.


Phase 1 → Practice Sequence

Đây là thứ tự thực hành khuyến nghị cho /practice/ai/:

Thứ tựBài tậpBài học liên quanKỹ năng kiểm tra
1Vector & Matrix basicsBài 01, 02Tạo và thao tác arrays, broadcasting
2Matrix multiplicationBài 03Matmul, dot product, transpose
3EDA pipelineBài 04Thống kê mô tả, phát hiện outlier
4Feature engineeringBài 05Encoding, scaling, tạo feature mới
5Imbalanced data handlingBài 06SMOTE, class weights, evaluation metrics
6Complete ML pipelineBài 07 (bài này)Split, CV, train, evaluate

💡 Chiến lược thực hành

Làm tuần tự từ bài 1 → 6. Mỗi bài xây trên kiến thức bài trước. Bài 6 (pipeline) là bài tổng hợp — nếu bạn hoàn thành được, bạn đã sẵn sàng cho ML Blueprint.


🧪 Quiz — Kiểm tra kiến thức

🧠 Quiz

Câu 1: Tại sao cần train/test split?

  • [ ] A) Để model train nhanh hơn
  • [x] B) Để đánh giá model trên dữ liệu chưa thấy, mô phỏng production
  • [ ] C) Để tiết kiệm bộ nhớ
  • [ ] D) Vì sklearn bắt buộc

💡 Giải thích: Model cần được đánh giá trên dữ liệu nó chưa bao giờ thấy trong training. Đó là cách duy nhất biết model có generalize được hay không.

🧠 Quiz

Câu 2: Khi nào KHÔNG nên shuffle dữ liệu trước khi split?

  • [ ] A) Khi dataset nhỏ
  • [ ] B) Khi có nhiều features
  • [x] C) Khi dữ liệu là time series
  • [ ] D) Khi dùng Random Forest

💡 Giải thích: Time series có thứ tự thời gian. Shuffle = dùng tương lai dự đoán quá khứ = data leakage. Luôn dùng time-based split.

🧠 Quiz

Câu 3: Train accuracy = 99%, Test accuracy = 55%. Đây là dấu hiệu gì?

  • [ ] A) Underfitting
  • [x] B) Overfitting
  • [ ] C) Model hoạt động tốt
  • [ ] D) Cần thêm features

💡 Giải thích: Khoảng cách lớn giữa train và test accuracy = model ghi nhớ training data nhưng không generalize. Đây là overfitting điển hình. Giải pháp: regularization, giảm complexity, thêm data.


Tổng kết

Phase 1 đã trang bị cho bạn toàn bộ nền tảng cần thiết:

Bạn cầnPhase 1 đã dạy
Hiểu cấu trúc dữ liệuVectors, matrices, tensors (bài 01)
Tính toán nhanhVectorization, broadcasting (bài 02)
Ngôn ngữ chung của MLMatrix operations (bài 03)
Hiểu dữ liệuEDA pipeline (bài 04)
Tạo tín hiệuFeature engineering (bài 05)
Xử lý thực tếImbalanced data, streams (bài 06)
Quy trình MLTrain/test, CV, pipeline (bài 07)

Bạn đã sẵn sàng. ML Blueprint đang chờ.