DEMAXIYAZHENGYI 2023-03-07 16:36 采纳率: 73.7%
浏览 65
已结题

scorecardpy的模型改写问题

我用了scorecardpy包来做一个评分卡模型,现在问题是,我想将它自带的逻辑回归预测模型替换为我自己的autogluon模型,但是报错了,代码是这样的

import pandas as pd
import numpy as np
import scorecardpy as sc


dat=pd.read_csv("dat.csv",index_col=0)
dat

dt_s = sc.var_filter(dat, y="isDefault")

dt_s.info()

train, test = sc.split_df(dt_s,'isDefault',ratio=0.8).values()
bins = sc.woebin(dt_s, y='isDefault',method="chimerge")
sc.woebin_plot(bins)
train_woe = sc.woebin_ply(train, bins)
test_woe = sc.woebin_ply(test, bins)
y_train = train_woe.loc[:,'isDefault']
X_train = train_woe.loc[:,train_woe.columns != 'isDefault']
y_test = test_woe.loc[:,'isDefault']
X_test = test_woe.loc[:,train_woe.columns != 'isDefault']
mport autogluon
from autogluon.tabular import TabularDataset,TabularPredictor  
import pandas as pd
import numpy as np
label='isDefault'
train_data=TabularDataset(train_woe )
metric = 'roc_auc'
time_limit=60
predictor=TabularPredictor(label=label,eval_metric=metric).fit(train_data,presets='best_quality',time_limit=time_limit,auto_stack=True)
test_data=TabularDataset(test_woe)
predictor.predict_proba(train_data)
train_proba=predictor.predict_proba(train_data)
train_proba=train_proba.values[:,1]
train_proba = np.array(train_proba).flatten() 
train_proba
predictor.predict_proba(test_data)
auto_proba=predictor.predict_proba(test_data)
auto_proba=auto_proba.values[:,1]
auto_proba = np.array(auto_proba).flatten() 
auto_proba
import toad
from toad.metrics import KS, AUC



print('Training error')
print('KS:', KS(train_proba,y_train))
print('AUC:', AUC(train_proba,y_train))




print('\nTest error')
print('KS:', KS(auto_proba,y_test))
print('AUC:', AUC(auto_proba,y_test))

card = sc.scorecard(bins,predictor, X_train.columns)

问题出在这个最后一句,我将我的模型predictor替换了scorecard包自带的lr,就显示报错
'TabularPredictor' object has no attribute 'coef_'
这个怎么解决?
谢谢各位了

  • 写回答

6条回答 默认 最新

  • mydmomo 2023-03-10 17:05
    关注

    目前来看难度较大,socrecardpy只能应用线性模型,你可以试试xgb回归与sgd回归,必须带有.coef_指令的模型

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(5条)

报告相同问题?

问题事件

  • 系统已结题 3月18日
  • 已采纳回答 3月10日
  • 赞助了问题酬金15元 3月7日
  • 创建了问题 3月7日

悬赏问题

  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程