> For the complete documentation index, see [llms.txt](https://www.nhasachso.io.vn/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.nhasachso.io.vn/truc-tuyen/interactive-blocks-1/tac-gia/nguyen-hong-phuong/sach-cong-cu-ai-python/phan-2-hoc-may-machine-learning/scikit-learn-mot-thu-vien-toan-dien-cho-cac-thuat-toan-hoc-may-co-ban-phan-loai-hoi-quy-cum.md).

# Scikit-learn: Một thư viện toàn diện cho các thuật toán học máy cơ bản (phân loại, hồi quy, cụm)

#### **Scikit-learn**

**Mục tiêu:** Cung cấp một thư viện toàn diện cho học máy cơ bản và tiền xử lý dữ liệu.

**🔧 Tiền xử lý dữ liệu (Preprocessing)**

* **Chuẩn hóa (Standardization):** giúp các đặc trưng có cùng thang đo, cải thiện hiệu suất mô hình.
* **Mã hóa (Encoding):** chuyển đổi dữ liệu phân loại thành số (LabelEncoder, OneHotEncoder).
* **Chia tập dữ liệu:** tách dữ liệu thành tập huấn luyện (train) và kiểm tra (test) nhanh chóng.

**🤖 Thuật toán học máy cơ bản**

* **Phân loại (Classification):** `Logistic Regression`, `KNN`, `Random Forest`, `SVM`,...
* **Hồi quy (Regression):** `Linear Regression`, `Ridge`, `Lasso`,...
* **Phân cụm (Clustering):** `KMeans`, `DBSCAN`, `Agglomerative Clustering`,...

**💡 Đặc điểm nổi bật:**

* Giao diện đơn giản, dễ tích hợp vào quy trình học máy.
* Là lựa chọn hàng đầu cho người mới bắt đầu với AI/ML.
* Tích hợp tốt với NumPy, Pandas và Matplotlib.

**Ví dụ tổng quát:**

```python
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.datasets import load_iris

# Tải bộ dữ liệu mẫu
data = load_iris()
X, y = data.data, data.target

# Chuẩn hóa dữ liệu
scaler = StandardScaler()
X_scaled = scaler.fit_transform(X)

# Chia dữ liệu
X_train, X_test, y_train, y_test = train_test_split(X_scaled, y, test_size=0.2)

# Huấn luyện mô hình phân loại
model = LogisticRegression()
model.fit(X_train, y_train)

# Dự đoán
predictions = model.predict(X_test)
```

***
