Training और test सेट

Python में Machine Learning के लिए Preprocessing

James Chapman

Curriculum Manager, DataCamp

Split क्यों?

 

  1. Overfitting घटता है
  2. Holdout सेट पर performance जाँचें
Python में Machine Learning के लिए Preprocessing

अपने डेटासेट को विभाजित करना

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
Python में Machine Learning के लिए Preprocessing

Stratified sampling

 

  • $100$ सैंपल का डेटासेट: $80$ class 1 और $20$ class 2
  • $75$ सैंपल का training सेट: $60$ class 1 और $15$ class 2
  • $25$ सैंपल का test सेट: $20$ class 1 और $5$ class 2
Python में Machine Learning के लिए Preprocessing

Stratified sampling

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
Python में Machine Learning के लिए Preprocessing

Stratified sampling

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
Python में Machine Learning के लिए Preprocessing

अभ्यास करते हैं!

Python में Machine Learning के लिए Preprocessing

Preparing Video For Download...