I try to use the KFold function but give me this error:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-175-38368ff78797> in <module>()
1 cs = np.logspace(-4,5,10)
2
----> 3 aucs_l2=kfoldlr(train, 5, 3)
2 frames
/usr/local/lib/python3.6/dist-packages/sklearn/model_selection/_split.py in __init__(self, n_splits, shuffle, random_state)
286 if not isinstance(shuffle, bool):
287 raise TypeError("shuffle must be True or False;"
--> 288 " got {0}".format(shuffle))
289
290 if not shuffle and random_state is not None: # None is the default
TypeError: shuffle must be True or False; got 5
Here my Code:
from sklearn.model_selection import KFold
from sklearn import metrics
from sklearn import preprocessing
def kfoldlr(dataset , k , cs, l1_penalty = False):
'''Performs kfold cross validation for the dataset and also searches for the optimal regularixation parameter '''
aucs = {}
kf = KFold(len(dataset),k) #Provides indices to split data in train/test sets
for train_idx, vali_idx in kf: #For loop to extract and append AUC values to array from training data
cv_train,cv_validate=dataset.iloc[train_idx,:], dataset.iloc[vali_idx,:]
for c in cs:
auc, f_imp, tpr, fpr, threshold, accuracy = LRmodel(cv_train,cv_validate,c, l_1 = l1_penalty)
if c in aucs:
aucs[c].append(auc)
else:
aucs[c]=[]
aucs[c].append(auc)
return aucs
aucs_l2=kfoldlr(train, 5, 3)
I know that comes from the old version from sklearn. But I don't know where I can set the shuffle in the function.
Thank you for your help !