__init__() got multiple values for argument 'n_splits'

Hi ,

I am getting error while using nfolds as : init() got an unexpected keyword argument ‘n_folds’ for the below code.
#Perform k-fold cross-validation with 5 folds
kf = KFold(data.shape[0], n_folds=5)
error =

so i replaced with n_folds with n_splits after replacing tha i am getting init() got multiple values for argument 'n_splits’ this error . can anyone guide me on this .

Hey @SBK,

The definition of KFold is a bit different in the new version of sklearn (you can refer here for the current version)

Basically, what you have to do is

  1. Define the cross validation object and initialize the parameters like this

kf = KFold(n_splits=2)

  1. Then use this object to split the data

for eg.

> for train_index, test_index in kf.split(X):
>         print("TRAIN:", train_index, "TEST:", test_index)
>         X_train, X_test = X[train_index], X[test_index]
>         y_train, y_test = y[train_index], y[test_index]

#Perform k-fold cross-validation with 5 folds
kf = KFold(data.shape[0], n_folds=5) change it to --> kf = KFold(n_splits=5)
error =
for train, test in kf : change it into --> for train, test in kf.split(data[predictors]):

It will work

© Copyright 2013-2019 Analytics Vidhya