Particionamiento con LeaveOneOut#

[1]:
#
# Equivale a KFold(n_splits=total_de_datos)
#
from sklearn.model_selection import LeaveOneOut

# No tiene parámetros
leaveOneOut = LeaveOneOut()

leaveOneOut
[1]:
LeaveOneOut()

assets/leave-one-out.jpg

[2]:
from mymodule import plot_schema

y_classes = [0] * 10 + [1] * 10

plot_schema(leaveOneOut, y_classes)
../_images/05_iteradores_03_LeaveOneOut_3_0.png
[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]