Trénovací a testovací sady

Preprocessing pro Machine Learning v Pythonu

James Chapman

Curriculum Manager, DataCamp

Proč dělit?

 

  1. Snižuje přetrénování
  2. Hodnocení výkonu na holdout sadě
Preprocessing pro Machine Learning v Pythonu

Rozdělení datové sady

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
Preprocessing pro Machine Learning v Pythonu

Stratifikované vzorkování

 

  • Datová sada $100$ vzorků: $80$ třída 1 a $20$ třída 2
  • Trénovací sada $75$ vzorků: $60$ třída 1 a $15$ třída 2
  • Testovací sada $25$ vzorků: $20$ třída 1 a $5$ třída 2
Preprocessing pro Machine Learning v Pythonu

Stratifikované vzorkování

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
Preprocessing pro Machine Learning v Pythonu

Stratifikované vzorkování

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
Preprocessing pro Machine Learning v Pythonu

Pojďme si procvičit!

Preprocessing pro Machine Learning v Pythonu

Preparing Video For Download...