python信用卡欺诈_python信用卡欺诈模型:逻辑回归

def

printing_Kfold_scores(x_train_data,y_train_data):

#定一个函数,函数里面是两个参数

#different C

parameters 定义不同的参数

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'])

#定一个空的表格,5行2列,且列名分别为 参数和 得分均值

results_table['C_parameter'] = c_param_range

#给参数列赋值

j =

0  #缩进低于def

for c_param in

c_param_range:

print('-------------------------------------------')

print('C parameters : ',c_param)

print('-------------------------------------------')

print('')

recall_accs=[]

#定义一个空的数据集,把得分都放置到这个数据集里

#iteration 交叉验证

fold = KFold(5,shuffle=False)

for train_index, test_index in

fold.split(x_train_data):

# Call the

logistic regression model with a certain C parameter

lr =

LogisticRegression(C = c_param, penalty = 'l1')

# Use the

training data to fit the model. In this case, we use the portion of

the fold to train the model

lr.fit(x_train_data.iloc[train_index,:],

y_train_data.iloc[train_index,:].values.ravel())

# Predict

values using the test indices in the training data

y_pred_undersample =

lr.predict(x_train_data.iloc[test_index,:].values)

#

Calculate the recall score and append it to a list for recall

scores representing the current c_parameter

recall_acc

=

recall_score(y_train_data.iloc[test_index,:].values,y_pred_undersample)

recall_accs.append(recall_acc)

print('recall score = ',

recall_acc)

results_table.loc[j,'Mean recall score'] =

np.mean(recall_accs)

j +=1

print('')

print('Mean recall score

:',np.mean(recall_accs))

print('')

return

results_table

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值