Created
June 2, 2022 07:01
-
-
Save Abhayparashar31/f80a7376b60d754f01d0146faf20d6bf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############## LEAVE ONE OUT CROSS VALIDATION ########### | |
import numpy as np | |
""" Creating Sample X and y """ | |
X = np.array([[1,2,3], | |
[4,5,6], | |
[7,8,9], | |
[10,11,12], | |
[13,14,15], | |
[16,17,18]]) | |
y = np.array([0,1,1,1,0,1]) | |
""" Importing LeaveOneOut Cross Validation Inside The Script """ | |
from sklearn.model_selection import LeaveOneOut | |
""" Creating Object """ | |
loo = LeaveOneOut() | |
""" Generating Indexes For Train and Test Data """ | |
for train_index, test_index in loo.split(X): | |
X_train, X_test = X[train_index], X[test_index] | |
y_train, y_test = y[train_index], y[test_index] | |
print("Train Index:", train_index, "|", "Test Index:", test_index) | |
--------------------------------------------------------------------------------------- | |
Train Index: [1 2 3 4 5] | Test Index: [0] | |
Train Index: [0 2 3 4 5] | Test Index: [1] | |
Train Index: [0 1 3 4 5] | Test Index: [2] | |
Train Index: [0 1 2 4 5] | Test Index: [3] | |
Train Index: [0 1 2 3 5] | Test Index: [4] | |
Train Index: [0 1 2 3 4] | Test Index: [5] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment