Mục tiêu
- Cài môi trường Python 3.10+ với venv và Jupyter.
- Cài NumPy, pandas, matplotlib, scikit-learn.
- Nắm roadmap
Lý thuyết
Stack khuyến nghị
| Thư viện | Vai trò |
|---|---|
| NumPy | Mảng, linear algebra |
| pandas | Bảng, CSV, EDA |
| matplotlib | Biểu đồ |
| scikit-learn | Preprocessing + models + metrics |
| Jupyter | Notebook thử nghiệm |
Deep learning (TensorFlow/PyTorch) ở Ch.12+ — không bắt buộc batch 1.
Thói quen học
- Chạy mọi snippet — không chỉ đọc.
- Ghi lại metric và seed
random_state. - So sánh với baseline trước khi tune phức tạp.
Code Python
Cài đặt
python3 -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install --upgrade pip
pip install numpy pandas matplotlib scikit-learn jupyter
jupyter lab
Smoke test stack
import numpy as np
import pandas as pd
import sklearn
import matplotlib
print("numpy", np.__version__)
print("pandas", pd.__version__)
print("sklearn", sklearn.__version__)
from sklearn.datasets import load_iris
from sklearn.model_selection import cross_val_score
from sklearn.linear_model import LogisticRegression
X, y = load_iris(return_X_y=True)
scores = cross_val_score(
LogisticRegression(max_iter=1000),
X, y, cv=5,
)
print("5-fold CV accuracy:", scores.mean().round(3), "+/-", scores.std().round(3))
Tài liệu: Installing scikit-learn.
Lỗi thường gặp
- Cài package vào Python system thay vì venv → xung đột version.
- Thiếu
max_itertrên logistic →ConvergenceWarning. - Jupyter kernel trỏ sai interpreter (không thấy package vừa pip).
Bài tập
- Tạo venv, chạy smoke test, chụp/ghi version 4 thư viện.
- Mở notebook, load Iris, vẽ scatter 2 feature đầu tô màu theo species.
- Lập kế hoạch 2 tuần: đọc xong Ch.2 (10 bài) — 5 bài/tuần.
Tóm tắt
Học machine learning với Python cần stack ổn định và roadmap rõ. Chương 2 bắt đầu Perceptron và Adaline — code từ đầu trước khi phụ thuộc hoàn toàn vào sklearn.