Particionamiento con ShuffleSplit#
Ultima modificación: 2023-02-27 | `YouTube <>`__
[1]:
#
# Parte aleatoriamente la muestra, sin garantizar que los grupos
# sean diferentes
#
from sklearn.model_selection import ShuffleSplit
shuffleSplit = ShuffleSplit(
# --------------------------------------------------------------------------
# Número de grupos
n_splits=10,
# --------------------------------------------------------------------------
# Tamaño del conjunto de prueba
# int: número de ejemplos
# float: porcentaje de la muestra
test_size=0.25,
# --------------------------------------------------------------------------
# Tamaño del conjunto de entrenamiento
# int: número de ejemplos
# float: porcentaje de la muestra
train_size=None,
# --------------------------------------------------------------------------
# Semilla del generador de aleatorios
random_state=0,
)
shuffleSplit
[1]:
ShuffleSplit(n_splits=10, random_state=0, test_size=0.25, train_size=None)
[2]:
from mymodule import plot_schema
y_classes = [0] * 10 + [1] * 10
plot_schema(shuffleSplit, y_classes)
[3]:
import numpy as np
X = np.array([[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11, 12]])
y = np.array([1, 2, 3, 4, 5, 6])
shuffleSplit = ShuffleSplit(
n_splits=10,
test_size=2,
random_state=12345,
)
for i, (train_index, test_index) in enumerate(shuffleSplit.split(X)):
print(f"Fold {i}:")
print(f" Train: index={train_index}")
print(f" Test: index={test_index}")
print()
Fold 0:
Train: index=[4 0 1 2]
Test: index=[5 3]
Fold 1:
Train: index=[3 1 2 5]
Test: index=[4 0]
Fold 2:
Train: index=[5 2 3 1]
Test: index=[0 4]
Fold 3:
Train: index=[3 1 2 0]
Test: index=[4 5]
Fold 4:
Train: index=[5 4 2 1]
Test: index=[3 0]
Fold 5:
Train: index=[0 3 1 5]
Test: index=[4 2]
Fold 6:
Train: index=[1 0 4 3]
Test: index=[5 2]
Fold 7:
Train: index=[4 1 5 3]
Test: index=[2 0]
Fold 8:
Train: index=[1 0 3 5]
Test: index=[2 4]
Fold 9:
Train: index=[0 5 3 4]
Test: index=[1 2]