小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

Py之scorecardpy:scorecardpy的簡(jiǎn)介、安裝、使用方法之詳細(xì)攻略

 處女座的程序猿 2022-06-22 發(fā)布于上海

Py之scorecardpy:scorecardpy的簡(jiǎn)介、安裝、使用方法之詳細(xì)攻略


scorecardpy的簡(jiǎn)介

? ? ? ?Scorecardpy,由謝士晨博士開(kāi)發(fā),這個(gè)包是 R 包評(píng)分卡的 python 版本。 其目標(biāo)是通過(guò)為一些常見(jiàn)任務(wù)提供功能,使傳統(tǒng)信用風(fēng)險(xiǎn)評(píng)分卡模型的開(kāi)發(fā)更容易、更高效。

  • 數(shù)據(jù)切分(split_df)
  • 變量選擇(iv,var_filter)
  • 證據(jù)權(quán)重 (woe) 分箱(woebin、woebin_plot、woebin_adj、woebin_ply)
  • 評(píng)分卡縮放 (scorecard, scorecard_ply)
  • 性能評(píng)估(perf_eva、perf_psi)

Githubhttps://github.com/shichenxie/scorecardpy
案例
scorecardpy庫(kù)的使用簡(jiǎn)介 - 知乎

評(píng)分卡建模工具scorecardpy全解讀 - 知乎

scorecardpy的安裝

pip install scorecardpy

scorecardpy的使用方法

1、基礎(chǔ)案例

# Traditional Credit Scoring Using Logistic Regression
import scorecardpy as sc

# data prepare ------
# load germancredit data
dat = sc.germancredit()

# filter variable via missing rate, iv, identical value rate
dt_s = sc.var_filter(dat, y="creditability")

# breaking dt into train and test
train, test = sc.split_df(dt_s, 'creditability').values()

# woe binning ------
bins = sc.woebin(dt_s, y="creditability")
# sc.woebin_plot(bins)

# binning adjustment
# # adjust breaks interactively
# breaks_adj = sc.woebin_adj(dt_s, "creditability", bins) 
# # or specify breaks manually
breaks_adj = {
    'age.in.years': [26, 35, 40],
    'other.debtors.or.guarantors': ["none", "co-applicant%,%guarantor"]
}
bins_adj = sc.woebin(dt_s, y="creditability", breaks_list=breaks_adj)

# converting train and test into woe values
train_woe = sc.woebin_ply(train, bins_adj)
test_woe = sc.woebin_ply(test, bins_adj)

y_train = train_woe.loc[:,'creditability']
X_train = train_woe.loc[:,train_woe.columns != 'creditability']
y_test = test_woe.loc[:,'creditability']
X_test = test_woe.loc[:,train_woe.columns != 'creditability']

# logistic regression ------
from sklearn.linear_model import LogisticRegression
lr = LogisticRegression(penalty='l1', C=0.9, solver='saga', n_jobs=-1)
lr.fit(X_train, y_train)
# lr.coef_
# lr.intercept_

# predicted proability
train_pred = lr.predict_proba(X_train)[:,1]
test_pred = lr.predict_proba(X_test)[:,1]

# performance ks & roc ------
train_perf = sc.perf_eva(y_train, train_pred, title = "train")
test_perf = sc.perf_eva(y_test, test_pred, title = "test")

# score ------
card = sc.scorecard(bins_adj, lr, X_train.columns)
# credit score
train_score = sc.scorecard_ply(train, card, print_step=0)
test_score = sc.scorecard_ply(test, card, print_step=0)

# psi
sc.perf_psi(
  score = {'train':train_score, 'test':test_score},
  label = {'train':y_train, 'test':y_test}
)

    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章