Lzz0
Lzz0

Reputation: 493

Leave one out Cross validation using sklearn (Multiple CSV)

I have 52 CSV files in a folder. I want to build a model based on this data. That's why I want to do Leave one out cross-validation on these data. How can I do this using sci-kit learn in python?

I tried from sci kit document and also search many resources.But I didn't found the solution. I have tried this code.

import glob
import numpy as np
import pandas as pd
from sklearn.cross_validation import LeaveOneOut
path=r'...................\Data\New design process data'
filelist=glob.glob(path + "/*.csv")
loo=LeaveOneOut()
for train,test in loo.split(filelist):
   print("%s %s" % (train, test))

But it showed errors.

init() missing 1 required positional argument: 'n'

I am new in python as well as sci-kit learn. If anyone can help me, It would be a great convenience.

Upvotes: 0

Views: 1130

Answers (1)

elz
elz

Reputation: 5718

You should use the newer version of the module, which is located in sklearn.model_selection instead of sklearn.cross_validation. (The cross_validation module was depricated in 0.18.) Using this version, you can instantiate the class without the positional argument, and it also does not fail when you try to call split.

from sklearn.model_selection import LeaveOneOut

X = np.array([[1, 2], [3, 4]])
y = np.array([1, 2])
loo = LeaveOneOut()  # works without passing an argument
loo.get_n_splits(X)  # returns 2

Upvotes: -1

Related Questions