Scikit-learn: Dùng để tiền xử lý dữ liệu (chuẩn hóa, mã hóa, chia tách dữ liệu
Scikit-learn
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler, LabelEncoder
import pandas as pd
# Tạo dữ liệu mẫu
df = pd.DataFrame({
'age': [25, 30, 35, 40],
'income': [3000, 4000, 5000, 6000],
'label': ['yes', 'no', 'yes', 'no']
})
# Mã hóa nhãn
le = LabelEncoder()
df['label_encoded'] = le.fit_transform(df['label'])
# Chuẩn hóa dữ liệu
scaler = StandardScaler()
df[['age', 'income']] = scaler.fit_transform(df[['age', 'income']])
# Chia tập train/test
X = df[['age', 'income']]
y = df['label_encoded']
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25)PreviousMatplotlib & Seaborn: Vẽ biểu đồ, trực quan hóa dữ liệuNextPhần 2: Học Máy (Machine Learning)
Last updated
