Conjuntos de entrenamiento y prueba

Preprocesamiento para machine learning en Python

James Chapman

Curriculum Manager, DataCamp

¿Por qué dividir?

 

  1. Reduce el overfitting
  2. Evalúa el rendimiento con un conjunto de validación
Preprocesamiento para machine learning en Python

Dividir tu conjunto de datos

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
Preprocesamiento para machine learning en Python

Muestreo estratificado

 

  • Conjunto de $100$ muestras: $80$ clase 1 y $20$ clase 2
  • Entrenamiento de $75$ muestras: $60$ clase 1 y $15$ clase 2
  • Prueba de $25$ muestras: $20$ clase 1 y $5$ clase 2
Preprocesamiento para machine learning en Python

Muestreo estratificado

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
Preprocesamiento para machine learning en Python

Muestreo estratificado

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
Preprocesamiento para machine learning en Python

¡Vamos a practicar!

Preprocesamiento para machine learning en Python

Preparing Video For Download...