基于贷款表开展logistic regression时如何计算优质贷款Sum of Predicted Values以确定最优阈值
贷款Logistic回归最优利润阈值计算方案
核心逻辑
- 遍历0~1范围内的所有候选判定阈值,根据精度需求设置步长(常规用0.01或0.001)
- 对每个阈值,筛选所有预测属于
new_status优质类别的概率大于等于该阈值的贷款,累加对应单笔利润值,即为该阈值下Sum of Predicted Values维度的总利润 - 遍历完成后,取总利润最大时对应的阈值,即为最大化利润的最优判定阈值
数据集参考

Python 实现代码(Pandas)
前提字段说明
贷款数据集需提前包含以下列(可根据实际列名调整):
pred_prob:Logistic回归针对new_status优质类输出的预测概率(取值范围0~1)profit:单笔贷款对应的利润值(优质贷款为正收益,不良贷款为负损失,已提前核算完成)
计算代码
import pandas as pd import numpy as np # 生成候选阈值列表,步长可按需调整 thresholds = np.arange(0, 1.01, 0.01) profit_list = [] for thresh in thresholds: # 筛选预测概率高于当前阈值的贷款,累加利润 total_profit = loan_df.loc[loan_df["pred_prob"] >= thresh, "profit"].sum() profit_list.append(total_profit) # 生成阈值-利润对应结果表 threshold_result = pd.DataFrame({ "判定阈值": thresholds, "总利润": profit_list }) # 定位最优阈值与对应最大利润 best_threshold = threshold_result.loc[threshold_result["总利润"].idxmax(), "判定阈值"] max_total_profit = threshold_result["总利润"].max()
注意事项
- 若需更精细的最优阈值结果,可将阈值步长调整为0.001,计算量无明显增加
- 可基于
threshold_result绘制折线图,直观对比不同阈值下的利润变化趋势
内容的提问来源于stack exchange,提问作者Feverish123
相关产品推荐
相关产品推荐

