鱼C论坛

 找回密码
 立即注册
查看: 1413|回复: 2

大家好,帮忙看一下

[复制链接]
发表于 2019-2-25 21:49:10 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
有没有大佬能教教我。。。我在用model_selection KFold() 时候(cross_validation不能用了)出现了TypeError: __init__() got multiple values for argument 'shuffle' 代码如下,万分感谢!!!


from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import KFold, cross_val_score
from sklearn.metrics import confusion_matrix, recall_score, classification_report

def printing_Kfold_scores(x_train_data, y_train_data):
fold = KFold(len(y_train_data), 5, shuffle=False, random_state=None)
c_param_range = [0.01, 0.1, 1, 10, 100] #惩罚力度
results_table = pd.DataFrame(index = range(len(c_param_range), 2), columns = ['C_parameter','Mean recall score'])
results_table['C_parameter'] = c_param_range
j = 0
for c_param in c_param_range:
print('_______________________________________________')
print('C parameter: ', c_param)
print('_______________________________________________')
print('')

recall_accs = []
for iteration, indices in enumerate(fold, start=1):
lr = LogisticRegression(C = c_param, penalty= 'l1')
lr.fit(x_train_data.iloc[indices[0],:], y_train_data.iloc[indices[0],:].values.ravel())
y_pred_undersample = lr.predict(x_train_data.iloc[indices[1],:].values)
recall_acc = recall_score(y_train_data.iloc[indices[1],:].values, y_pred_undersample)
recall_accs.append(recall_acc)
print('Iteration', iteration, ':recall_score = ', recall_acc)
results_table.ix[j, 'Mean recall score'] = np.mean(recall_accs)
j += 1
print('')
print('Mean recall score ', np.mean(recall_accs))
print('')

best_c = results_table.loc[results_table['Mean recall score'].idxmax()]['C_parameter']
print('************************************************************************')
print('Best model to choose from cross validation is with C parameter = ', best_c)
print('************************************************************************')

return best_c

best_c = printing_Kfold_scores(X_train_undersample, y_train_undersample)
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2019-2-25 22:20:15 | 显示全部楼层
    def __init__(self, n_splits='warn', shuffle=False,
                 random_state=None):
除了实例就3个参数位置,你传了4个
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2019-5-13 14:52:09 | 显示全部楼层
好的,谢谢
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2026-1-14 04:23

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表