Tập huấn luyện và tập kiểm tra

Tiền xử lý cho Machine Learning bằng Python

James Chapman

Curriculum Manager, DataCamp

Vì sao phải tách?

 

  1. Giảm overfitting
  2. Đánh giá hiệu năng trên tập giữ lại
Tiền xử lý cho Machine Learning bằng Python

Chia tách dữ liệu của bạn

from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
   X_train y_train            
0      1.0       n
1      4.0       n
       ...
5      5.0       n
6      6.0       n

   X_test y_test
0     9.0      y
1     1.0      n
2     4.0      n
Tiền xử lý cho Machine Learning bằng Python

Lấy mẫu phân tầng

 

  • Dataset $100$ mẫu: $80$ class 1 và $20$ class 2
  • Tập huấn luyện $75$ mẫu: $60$ class 1 và $15$ class 2
  • Tập kiểm tra $25$ mẫu: $20$ class 1 và $5$ class 2
Tiền xử lý cho Machine Learning bằng Python

Lấy mẫu phân tầng

X_train,X_test,y_train,y_test = train_test_split(X, y, stratify=y, random_state=42)
y["labels"].value_counts()
class1    80
class2    20
Name: labels, dtype: int64
Tiền xử lý cho Machine Learning bằng Python

Lấy mẫu phân tầng

y_train["labels"].value_counts()
class1    60
class2    15
Name: labels, dtype: int64
y_test["labels"].value_counts()
class1    20
class2    5
Name: labels, dtype: int64
Tiền xử lý cho Machine Learning bằng Python

Cùng luyện tập nào!

Tiền xử lý cho Machine Learning bằng Python

Preparing Video For Download...