Sklearn调用KFold函数报错

init() got multiple values for argument ‘n_splits’

Sklearn调用KFold函数报错

报错如题,代码如下:

#KFold_validation:做k_折交叉验证;
#x_all_data:全部的X数据;
#y_all_data:全部的y数据(只有一列)
#返回值为train和test的c_table表,locals()["train_c_table"+"_"+str(k)]和locals()["test_c_table"+"_"+str(k)]
def KFold_validation(x_all_data,y_all_data,n_splits):
    #from sklearn import cross_validation as CV
    from sklearn.model_selection import KFold
    #from sklearn.cross_validation import KFold
    kf=KFold(len(x_all_data),n_splits=n_splits)
    k=1
    parameter=pd.DataFrame()
    for train_index,test_index in cv:
        x_train,x_test=x_all_data.iloc[train_index,:],x_all_data.iloc[test_index,:]
        y_train,y_test=y_all_data[train_index],y_all_data.iloc[test_index]
        globals()["train_c_table"+"_"+str(k)],globals()["train_params"+"_"+str(k)],globals()["train_pred_p"+"_"+str(k)]=cal_cutoff_table(x_data=x_train,y_data=y_train)
        globals()["test_c_table"+"_"+str(k)],globals()["test_params"+"_"+str(k)],globals()["test_pred_p"+"_"+str(k)]=cal_cutoff_table(x_data=x_test,y_data=y_test)
        globals()["train_index_"+str(k)]=train_index
        globals()["test_index_"+str(k)]=test_index
        k=k+1
       
    #for k in range(1,n_folds+1):
        #return locals()["train_c_table"+"_"+str(k)],locals()["test_c_table"+"_"+str(k)]
#5折交叉验证
from sklearn.model_selection import train_test_split
x=xw_select_var.drop(columns='type1')
y=xw_select_var["type1"]    
KFold_validation(x_all_data=x,y_all_data=y,n_splits=5)
#cutoff_low=0.31
#cutoff_low=0.33
#确定cutoff并输出结果
#for k in range(1,6):
    #["train_c_table"+"_"+str(k)][[("train_c_table"+"_"+str(k)]["CutOff"]>cutoff_low)&("train_c_table"+"_"+str(k)]["CutOff"]<cutoff_up)]

你可能感兴趣的:(Sklearn调用KFold函数报错)