Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

leave one out in Sklearn

I am very new in this field. I am using spyder to run my code: I am trying to run simple leave one out cross validation code from sklearn:

from sklearn.cross_validation import train_test_split
from sklearn.cross_validation import LeaveOneOut

X = [1, 2 ,3, 4]
loo = LeaveOneOut()
for train, test in loo.split(X):
     print ("%s %s" %(train, test))

I am getting following error:

TypeError: __init__() takes exactly 2 arguments (1 given)

I understand the reason, but do not know what to pass here.

like image 519
hemanta Avatar asked Mar 10 '23 14:03

hemanta


1 Answers

You should pass total number of elements in dataset. The following code for your reference

import numpy as np
from sklearn.cross_validation import LeaveOneOut

X = np.array([1, 2 ,3, 4])
loo = LeaveOneOut(4)
for train_idx, test_idx in loo:
    print X[train_idx], X[test_idx]
like image 109
Shane Kao Avatar answered Mar 21 '23 02:03

Shane Kao