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.
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]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With