Particionamiento con LeaveOneOut#
Ultima modificación: 2023-02-27 | `YouTube <>`__
[1]:
#
# Equivale a KFold(n_splits=total_de_datos)
#
from sklearn.model_selection import LeaveOneOut
# No tiene parámetros
leaveOneOut = LeaveOneOut()
leaveOneOut
[1]:
LeaveOneOut()
[2]:
from mymodule import plot_schema
y_classes = [0] * 10 + [1] * 10
plot_schema(leaveOneOut, 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])
leaveOneOut = LeaveOneOut()
for i, (train_index, test_index) in enumerate(leaveOneOut.split(X)):
print(f"Fold {i}:")
print(f" Train: index={train_index}")
print(f" Test: index={test_index}")
print()
Fold 0:
Train: index=[1 2 3 4 5]
Test: index=[0]
Fold 1:
Train: index=[0 2 3 4 5]
Test: index=[1]
Fold 2:
Train: index=[0 1 3 4 5]
Test: index=[2]
Fold 3:
Train: index=[0 1 2 4 5]
Test: index=[3]
Fold 4:
Train: index=[0 1 2 3 5]
Test: index=[4]
Fold 5:
Train: index=[0 1 2 3 4]
Test: index=[5]