Modeling_Tool.Eval¶
模型评估层 —— Gains 表、ROC/KS、链式评估流水线。传入 weight_col 或 sample_weight 时走加权路径;未传则与历史未加权行为一致。
用户指南:模型评估 — 样本权重评估。
加权评估实现 — weighted_eval_utils¶
内部加权 ROC / Gains / 性能汇总实现;公开 API 在检测到权重参数时自动委托此模块。
weighted_eval_utils
¶
Native weighted evaluation helpers.
Shared implementation for public Eval APIs when sample_weight or
weight_col is supplied. Unweighted callers keep using the historical
implementations in evaluate_model.py and Model_Eval_Tool.py.
cross_risk_weighted_mean
¶
Weighted-mean cross-risk table after bin columns are assigned.
源代码位于: Modeling_Tool/Eval/weighted_eval_utils.py
模型评估主控 — Model_Eval_Tool¶
Model_Eval_Tool
¶
GainsTableCalculator
¶
收益表计算器。
整合了收益表计算的多种功能,支持基础收益表和自定义指标收益表。 提供面向对象的接口进行分组收益表计算。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
data
|
DataFrame
|
输入数据表 |
必需 |
dep
|
str
|
目标变量名 |
必需 |
nbins
|
int
|
分箱数量 |
10
|
precision
|
int
|
边界值精度 |
5
|
min_bin_prop
|
float
|
每箱最小样本占比 |
0.05
|
include_missing
|
bool
|
是否包含缺失值 |
True
|
score
|
str
|
分数字段名 |
None
|
model
|
sklearn-like model
|
机器学习模型 |
None
|
varlist
|
list
|
模型特征列表 |
None
|
equal_freq
|
bool
|
True为等频分箱 |
True
|
chi2_method
|
bool
|
是否使用卡方分箱 |
False
|
chi2_p
|
float
|
卡方检验显著性水平 |
0.95
|
init_equi_bins
|
int
|
初始等频分箱数量 |
100
|
fillna
|
any
|
缺失值填充值 |
-999999
|
spec_values
|
list
|
特殊值列表 |
[]
|
tree_binning
|
bool
|
是否使用决策树分箱 |
False
|
random_state
|
int
|
随机种子 |
42
|
ascending
|
bool
|
分箱顺序是否升序 |
False
|
示例:
>>> calc = GainsTableCalculator(data, dep='target', score='score', nbins=10)
>>> result = calc.calculate(grp_name='region')
源代码位于: Modeling_Tool/Eval/Model_Eval_Tool.py
1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 | |
calculate
¶
calculate(grp_name=None, min_data_size=100, grp_colname=None, sync_range=True, retSummary=False, withSummary=False, wholeGroup=False, add_func=None, weight_col=None)
计算收益表。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
grp_name
|
str
|
分组字段名 |
None
|
min_data_size
|
int
|
每组最小样本数 |
100
|
grp_colname
|
str
|
分组结果列名 |
None
|
sync_range
|
bool
|
是否同步分箱边界 |
True
|
retSummary
|
bool
|
是否只返回汇总指标 |
False
|
withSummary
|
bool
|
是否包含总体汇总行 |
False
|
wholeGroup
|
bool
|
是否使用全部数据分组 |
False
|
add_func
|
callable
|
自定义统计函数 |
None
|
返回:
| 类型 | 描述 |
|---|---|
DataFrame
|
收益表 |
源代码位于: Modeling_Tool/Eval/Model_Eval_Tool.py
PerformanceEvaluator
¶
性能评估器。
整合了模型性能评估的多种功能,支持多数据集、多分组的性能评估。 提供面向对象的接口进行性能指标计算和汇总。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
tgt_name
|
str or list of str
|
目标变量名。可传入多个 y 标签的 list/tuple → 逐标签评估后纵向拼接 (输出新增 tgt_name 列), 并为每个标签各自出图。 |
必需 |
scr_name
|
str
|
分数字段名 |
None
|
model
|
sklearn-like model
|
机器学习模型 |
None
|
feature_cols
|
list
|
模型特征列表 |
None
|
dist_bins
|
int
|
分布分箱数 |
20
|
pct_bins
|
int
|
百分比分箱数 |
10
|
precision
|
int
|
边界值精度 |
5
|
min_bin_prop
|
float
|
每箱最小样本占比 |
0.05
|
include_missing
|
bool
|
是否包含缺失值 |
False
|
equal_freq
|
bool
|
True为等频分箱 |
True
|
chi2_method
|
bool
|
是否使用卡方分箱 |
False
|
init_equi_bins
|
int
|
初始等频分箱数量 |
1000
|
chi2_p
|
float
|
卡方检验显著性水平 |
0.9
|
tree_binning
|
bool
|
是否使用决策树分箱 |
False
|
random_state
|
int
|
随机种子 |
42
|
weight_col
|
str
|
默认权重列;各 |
None
|
示例:
>>> evaluator = PerformanceEvaluator(tgt_name='target', model=model, feature_cols=features)
>>> evaluator.add_dataset('train', train_df)
>>> evaluator.add_dataset('validation', val_df)
>>> evaluator.add_dataset('oot', oot_df)
>>> result = evaluator.evaluate()
>>>
>>> # 多 y 标签: tgt_name 传 list → 输出含 tgt_name 列的纵向拼接表, 每个标签各自出图
>>> evaluator = PerformanceEvaluator(tgt_name=['bad_dpd7', 'bad_dpd30'], model=model, feature_cols=features)
>>> evaluator.add_dataset('train', train_df).add_dataset('oot', oot_df)
>>> result = evaluator.evaluate(to_show=True)
源代码位于: Modeling_Tool/Eval/Model_Eval_Tool.py
2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 | |
add_dataset
¶
添加数据集。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
name
|
str
|
数据集名称(如'train'、'validation'、'oot') |
必需 |
data
|
DataFrame
|
数据集 |
必需 |
返回:
| 类型 | 描述 |
|---|---|
self
|
返回自身以便链式调用 |
源代码位于: Modeling_Tool/Eval/Model_Eval_Tool.py
evaluate
¶
evaluate(oot_grp_name=None, min_data_size=100, grp_colname=None, fig_save_path=None, rpt_save_path=None, to_show=False, display=True, gains_table=False, benchmark_dataset=None, weight_col=None)
执行性能评估。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
oot_grp_name
|
str
|
oot分组字段名 |
None
|
min_data_size
|
int
|
每组最小样本数 |
100
|
grp_colname
|
str
|
分组结果列名 |
None
|
fig_save_path
|
str
|
图片保存路径 |
None
|
rpt_save_path
|
str
|
报告保存路径 |
None
|
to_show
|
bool
|
是否显示图形 |
False
|
display
|
bool
|
是否打印结果 |
True
|
gains_table
|
bool
|
是否计算收益表 |
True
|
benchmark_dataset
|
str or DataFrame
|
固定分箱边界的基准数据集。若传入str, 则从add_dataset添加的数据集中按名称获取; 若传入DataFrame, 则直接使用该DataFrame。默认None表示各数据集独立分箱。 |
None
|
返回:
| 类型 | 描述 |
|---|---|
DataFrame
|
性能评估汇总表。若实例的 |
源代码位于: Modeling_Tool/Eval/Model_Eval_Tool.py
2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 | |
get_gains_table
¶
get_gains_table(data, dep, nbins=10, precision=5, min_bin_prop=0.05, include_missing=True, score=None, model=None, varlist=None, equal_freq=True, chi2_method=False, grp_name=None, min_data_size=100, grp_colname=None, sync_range=True, chi2_p=0.95, init_equi_bins=100, fillna=-999999, spec_values=[], retSummary=False, tree_binning=False, random_state=42, ascending=False, withSummary=False, wholeGroup=False, add_func=None, weight_col=None, weighted_binning=None)
计算分组收益表。
根据分组字段对数据进行分组,分别计算每个分组的收益表。 若未指定分组字段,则计算整体收益表。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
data
|
DataFrame
|
输入数据表 |
必需 |
dep
|
str
|
目标变量名 |
必需 |
nbins
|
int
|
分箱数量 |
10
|
precision
|
int
|
边界值精度 |
5
|
min_bin_prop
|
float
|
每箱最小样本占比 |
0.05
|
include_missing
|
bool
|
是否包含缺失值 |
True
|
score
|
str
|
分数字段名 |
None
|
model
|
sklearn-like model
|
机器学习模型 |
None
|
varlist
|
list
|
模型特征列表 |
None
|
equal_freq
|
bool
|
True为等频分箱 |
True
|
chi2_method
|
bool
|
是否使用卡方分箱 |
False
|
grp_name
|
str
|
分组字段名 |
None
|
min_data_size
|
int
|
每组最小样本数 |
100
|
grp_colname
|
str
|
分组结果列名 |
None
|
sync_range
|
bool
|
是否同步分箱边界 |
True
|
chi2_p
|
float
|
卡方检验显著性水平 |
0.95
|
init_equi_bins
|
int
|
初始等频分箱数量 |
100
|
fillna
|
any
|
缺失值填充值 |
-999999
|
spec_values
|
list
|
特殊值列表 |
[]
|
retSummary
|
bool
|
是否只返回汇总指标 |
False
|
tree_binning
|
bool
|
是否使用决策树分箱 |
False
|
random_state
|
int
|
随机种子 |
42
|
ascending
|
bool
|
分箱顺序是否升序 |
False
|
withSummary
|
bool
|
是否包含总体汇总行 |
False
|
wholeGroup
|
bool
|
是否使用全部数据分组 |
False
|
add_func
|
callable
|
自定义统计函数 |
None
|
weight_col
|
str
|
样本权重列名;提供且无 |
None
|
weighted_binning
|
bool
|
True 时按累计权重等频分箱;False 时按行数(默认) |
None
|
返回:
| 类型 | 描述 |
|---|---|
DataFrame
|
分组收益表 |
源代码位于: Modeling_Tool/Eval/Model_Eval_Tool.py
754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 | |
get_perf_summary
¶
get_perf_summary(train, validation, oot, tgt_name, scr_name=None, model=None, feature_cols=None, fig_save_path=None, rpt_save_path=None, to_show=False, display=True, dist_bins=20, pct_bins=10, precision=5, min_bin_prop=0.05, include_missing=False, equal_freq=True, chi2_method=False, init_equi_bins=1000, chi2_p=0.9, oot_grp_name=None, min_data_size=100, grp_colname=None, tree_binning=False, random_state=42, gains_table=False, weight_col=None)
计算分组性能评估汇总。
对训练集、验证集和oot样本进行分组性能评估,根据oot_grp_name 字段分组后分别计算各组的性能指标。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
train
|
DataFrame
|
训练数据集 |
必需 |
validation
|
DataFrame
|
验证数据集 |
必需 |
oot
|
DataFrame
|
oot数据集 |
必需 |
tgt_name
|
str
|
目标变量名 |
必需 |
scr_name
|
str
|
分数字段名 |
None
|
model
|
sklearn-like model
|
机器学习模型 |
None
|
feature_cols
|
list
|
模型特征列表 |
None
|
fig_save_path
|
str
|
图片保存路径 |
None
|
rpt_save_path
|
str
|
报告保存路径 |
None
|
to_show
|
bool
|
是否显示图形 |
False
|
display
|
bool
|
是否打印结果 |
True
|
dist_bins
|
int
|
分布分箱数 |
20
|
pct_bins
|
int
|
百分比分箱数 |
10
|
precision
|
int
|
边界值精度 |
5
|
min_bin_prop
|
float
|
每箱最小样本占比 |
0.05
|
include_missing
|
bool
|
是否包含缺失值 |
False
|
equal_freq
|
bool
|
True为等频分箱 |
True
|
chi2_method
|
bool
|
是否使用卡方分箱 |
False
|
init_equi_bins
|
int
|
初始等频分箱数量 |
1000
|
chi2_p
|
float
|
卡方检验显著性水平 |
0.9
|
oot_grp_name
|
str
|
oot分组字段名 |
None
|
min_data_size
|
int
|
每组最小样本数 |
100
|
grp_colname
|
str
|
分组结果列名 |
None
|
tree_binning
|
bool
|
是否使用决策树分箱 |
False
|
random_state
|
int
|
随机种子 |
42
|
gains_table
|
bool
|
是否计算收益表 |
True
|
weight_col
|
str
|
各数据集 DataFrame 中的样本权重列;无分组时用于加权 AUC/KS 等指标 |
None
|
返回:
| 类型 | 描述 |
|---|---|
DataFrame
|
分组性能评估汇总表 |
源代码位于: Modeling_Tool/Eval/Model_Eval_Tool.py
1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 | |
cross_risk
¶
cross_risk(data, score_list, dep, nbins, agg_col=None, precision=5, min_bin_prop=0.05, include_missing=False, equal_freq=True, binning_numeric=[True, True], agg_func='mean', chi2_method=False, chi2_p=0.95, init_equi_bins=100, fillna=-999999, spec_values=[], tree_binning=False, random_state=42, weight_col=None, sample_weight=None, wgt_col=None)
创建交叉风险表。
对两个分数字段进行分箱后,计算交叉分组的风险聚合值。 支持对数值型变量进行自动分箱。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
data
|
DataFrame
|
输入数据表 |
必需 |
score_list
|
list
|
分数字段列表,长度为2 |
必需 |
dep
|
str
|
目标变量名 |
必需 |
nbins
|
int or list
|
分箱数量(整数或长度为2的列表) |
必需 |
agg_col
|
str
|
聚合列名,默认为dep |
None
|
precision
|
int or list
|
边界值精度 |
5
|
min_bin_prop
|
float or list
|
每箱最小样本占比 |
0.05
|
include_missing
|
bool
|
是否包含缺失值 |
False
|
equal_freq
|
bool
|
True为等频分箱 |
True
|
binning_numeric
|
list
|
是否对数值型字段分箱 |
[True, True]
|
agg_func
|
(str, callable, tuple or dict)
|
聚合函数。 常规用法与 也支持直接计算两个字段聚合后的比值:
当 |
'mean'
|
chi2_method
|
bool
|
是否使用卡方分箱 |
False
|
chi2_p
|
float
|
卡方检验显著性水平 |
0.95
|
init_equi_bins
|
int
|
初始等频分箱数量 |
100
|
fillna
|
any
|
缺失值填充值 |
-999999
|
spec_values
|
list
|
特殊值列表 |
[]
|
tree_binning
|
bool
|
是否使用决策树分箱 |
False
|
random_state
|
int
|
随机种子 |
42
|
weight_col
|
str
|
Column in |
None
|
sample_weight
|
array - like
|
Explicit per-row weights; must align with |
None
|
wgt_col
|
str
|
Alias for |
None
|
返回:
| 类型 | 描述 |
|---|---|
DataFrame
|
交叉风险表 |
示例:
源代码位于: Modeling_Tool/Eval/Model_Eval_Tool.py
1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 | |
get_gains_table_by_cust_metrics
¶
get_gains_table_by_cust_metrics(data, dep, nbins=10, precision=5, min_bin_prop=0.05, include_missing=True, score=None, model=None, varlist=None, equal_freq=True, chi2_method=False, grp_name=None, min_data_size=100, grp_colname=None, sync_range=True, chi2_p=0.95, init_equi_bins=100, fillna=-999999, spec_values=[], tree_binning=False, random_state=42, ascending=True, eval_metrics=['age', 'monthly_income', 'education'], metric_agg_func='mean', withSummary=False)
计算分组自定义指标收益表。
根据分组字段对数据进行分组,分别计算每个分组的自定义指标收益表。 收益表包含基础统计指标以及自定义指标的聚合值。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
data
|
DataFrame
|
输入数据表 |
必需 |
dep
|
str
|
目标变量名 |
必需 |
nbins
|
int
|
分箱数量 |
10
|
precision
|
int
|
边界值精度 |
5
|
min_bin_prop
|
float
|
每箱最小样本占比 |
0.05
|
include_missing
|
bool
|
是否包含缺失值 |
True
|
score
|
str
|
分数字段名 |
None
|
model
|
sklearn-like model
|
机器学习模型 |
None
|
varlist
|
list
|
模型特征列表 |
None
|
equal_freq
|
bool
|
True为等频分箱 |
True
|
chi2_method
|
bool
|
是否使用卡方分箱 |
False
|
grp_name
|
str
|
分组字段名 |
None
|
min_data_size
|
int
|
每组最小样本数 |
100
|
grp_colname
|
str
|
分组结果列名 |
None
|
sync_range
|
bool
|
是否同步分箱边界 |
True
|
chi2_p
|
float
|
卡方检验显著性水平 |
0.95
|
init_equi_bins
|
int
|
初始等频分箱数量 |
100
|
fillna
|
any
|
缺失值填充值 |
-999999
|
spec_values
|
list
|
特殊值列表 |
[]
|
tree_binning
|
bool
|
是否使用决策树分箱 |
False
|
random_state
|
int
|
随机种子 |
42
|
ascending
|
bool
|
分箱顺序是否升序 |
True
|
eval_metrics
|
list
|
需要统计的自定义指标列表 |
["age", "monthly_income", "education"]
|
metric_agg_func
|
str or callable
|
自定义指标的聚合函数 |
"mean"
|
withSummary
|
bool
|
是否包含总体汇总行 |
False
|
返回:
| 类型 | 描述 |
|---|---|
DataFrame
|
分组自定义指标收益表 |
源代码位于: Modeling_Tool/Eval/Model_Eval_Tool.py
1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 | |
tie_score_rate
¶
计算分数重复率。
计算分数中非唯一值的比例,即存在重复的样本占比。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
data
|
DataFrame
|
输入数据表 |
必需 |
score
|
str
|
分数字段名 |
必需 |
返回:
| 类型 | 描述 |
|---|---|
float
|
分数重复率(0到1之间) |
示例:
源代码位于: Modeling_Tool/Eval/Model_Eval_Tool.py
score_unique_rate
¶
计算分数唯一率。
计算分数中唯一值占总样本数的比例。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
data
|
DataFrame
|
输入数据表(此参数保留但未使用) |
必需 |
score
|
array - like
|
分数字段或数组 |
必需 |
返回:
| 类型 | 描述 |
|---|---|
float
|
分数唯一率(0到1之间) |
示例:
源代码位于: Modeling_Tool/Eval/Model_Eval_Tool.py
链式评估流水线 — Evaluation_Tool¶
Evaluation_Tool
¶
Model Evaluation Tool - Optimized Version
This module provides classes and functions for model evaluation, performance comparison, and gains analysis. It includes utilities for calculating various metrics and generating cross-risk summaries.
Author: Matrix Agent
EvaluationPipeline
¶
链式调用的流水线对象,支持 .group_by() 和 .subset_by() 链式添加条件, 最后通过 .apply(func) 执行。 支持 func 返回 pandas.DataFrame 或 dict(值为 DataFrame)。
源代码位于: Modeling_Tool/Eval/Evaluation_Tool.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | |
Utility_Functions
¶
Utility functions for data processing and calculations.
源代码位于: Modeling_Tool/Eval/Evaluation_Tool.py
valid_average
staticmethod
¶
Calculate the average of positive values in a Series.
This function filters out non-positive values (including zeros and negatives) before calculating the mean, useful for financial or count data where zero or negative values should not contribute to the average.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
x
|
Series
|
Input series of numeric values. |
必需 |
返回:
| 类型 | 描述 |
|---|---|
float
|
Rounded average of positive values, or 0 if no valid values exist. |
示例:
源代码位于: Modeling_Tool/Eval/Evaluation_Tool.py
Model_Evaluation_Tool
¶
A comprehensive tool for model evaluation, performance comparison, and gains analysis.
This class provides methods for: - Base score calculation and correlation analysis - Model performance comparison across multiple metrics - Gains table generation and analysis - Cross-risk analysis - Multi-dimensional evaluation with subsets and groupings
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
data
|
DataFrame
|
Input data containing features and target variables. |
必需 |
dep
|
str
|
Name of the dependent/target variable. |
必需 |
comp_scrlist
|
list
|
List of comparison score column names. |
必需 |
model
|
object
|
Trained model with predict_proba method. Default is None. |
None
|
base_score
|
str
|
Name of the base score column. Default is None. |
None
|
min_data_size
|
int
|
Minimum data size threshold. Default is 500. |
500
|
equal_freq
|
bool
|
Whether to use equal frequency binning. Default is True. |
True
|
precision
|
int
|
Decimal precision for rounding. Default is 5. |
5
|
chi2_method
|
bool
|
Whether to use chi-square method. Default is False. |
False
|
chi2_p
|
float
|
Chi-square p-value threshold. Default is 0.999. |
0.999
|
init_equi_bins
|
int
|
Initial number of equal frequency bins. Default is 500. |
500
|
tree_binning
|
bool
|
Whether to use tree-based binning. Default is False. |
False
|
random_seed
|
int
|
Random seed for reproducibility. Default is 3407. |
3407
|
nbins
|
int
|
Number of bins for analysis. Default is 10. |
10
|
min_bin_prop
|
float
|
Minimum proportion for each bin. Default is 0.05. |
0.05
|
include_missing
|
bool
|
Whether to include missing values. Default is True. |
True
|
missing_rate_ref
|
int or float
|
Reference value for missing rate. Default is -99999999. |
-99999999
|
excel_path
|
str
|
Path for Excel output. Default is None. |
None
|
属性:
| 名称 | 类型 | 描述 |
|---|---|---|
data |
DataFrame
|
The input data (may be modified during processing). |
dep |
str
|
Target variable name. |
base_score |
str or None
|
Name of the base score column. |
comp_scrlist |
list
|
List of comparison score names. |
eval_ylabels |
list
|
Labels for y-axis evaluation. |
gains_display_metric_list |
list
|
Metrics to display in gains summary. |
源代码位于: Modeling_Tool/Eval/Evaluation_Tool.py
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 | |
get_base_score
¶
Calculate base model scores using the provided model.
This method uses the model's predict_proba method to generate scores for the input data and optionally displays correlation analysis.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
scorename
|
str
|
Name for the score column. Default is 'base_model_score'. |
'_base_model_score_'
|
disp
|
bool
|
Whether to display intermediate results. Default is False. |
False
|
返回:
| 类型 | 描述 |
|---|---|
Model_Evaluation_Tool
|
Returns self for method chaining. |
引发:
| 类型 | 描述 |
|---|---|
AttributeError
|
If model is None or lacks required attributes. |
源代码位于: Modeling_Tool/Eval/Evaluation_Tool.py
get_score_correlation
¶
Calculate correlation matrix between score columns.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
score_list
|
list
|
List of score column names. If None, uses base_score and comp_scrlist. |
None
|
method
|
str
|
Correlation method ('pearson', 'spearman', 'kendall'). Default is 'pearson'. |
'pearson'
|
返回:
| 类型 | 描述 |
|---|---|
DataFrame
|
Correlation summary in long format with columns: 'base', 'compare', 'corr'. |
源代码位于: Modeling_Tool/Eval/Evaluation_Tool.py
model_perf_compare
¶
model_perf_compare(data: Optional[DataFrame] = None, grp_name: Optional[str] = None, dist_bins: int = 100, pct_bins: int = 10, min_data_size: int = 50, sync_data_size: bool = True, min_bin_prop: Optional[float] = None, include_missing: Optional[bool] = None, equal_freq: Optional[bool] = None) -> DataFrame
Compare model performance across different scores.
This method calculates performance metrics (AUC, KS, etc.) for the base score
and all comparison scores via PerformanceEvaluator, optionally filtering
by group.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
data
|
DataFrame
|
Data to use. If None, uses self.data. |
None
|
grp_name
|
str
|
Group name column for stratification. |
None
|
dist_bins
|
int
|
Number of distribution bins. Default is 100. |
100
|
pct_bins
|
int
|
Number of percentile bins. Default is 10. |
10
|
min_data_size
|
int
|
Minimum data size per bin. Default is 50. |
50
|
sync_data_size
|
bool
|
Whether to filter out zero/negative scores. Default is True. |
True
|
min_bin_prop
|
float
|
Minimum bin proportion. Defaults to the instance setting. |
None
|
include_missing
|
bool
|
Whether to include missing values in performance binning.
Defaults to |
None
|
equal_freq
|
bool
|
Use equal-frequency binning. Defaults to the instance setting. |
None
|
返回:
| 类型 | 描述 |
|---|---|
DataFrame
|
Performance comparison results sorted by score order. |
源代码位于: Modeling_Tool/Eval/Evaluation_Tool.py
589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 | |
get_gains_summary
¶
get_gains_summary(data: Optional[DataFrame] = None, grp_name: Optional[str] = None, disp: bool = True, grp_disp_metric: List[str] = None, grp_nbins: int = 5, withSummary: bool = True, add_func: Optional[Callable] = None, sync_range: bool = True, spec_values=None, include_missing: Optional[bool] = None, fillna=None) -> DataFrame
Generate gains summary table for score analysis.
This method creates gains tables via GainsTableCalculator, showing the
distribution of targets across score bins, with optional group stratification.
Custom metrics can be injected through add_func.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
data
|
DataFrame
|
Data to use. If None, uses self.data. |
None
|
grp_name
|
str
|
Group name for stratified analysis. |
None
|
disp
|
bool
|
Whether to display results. Default is True. |
True
|
grp_disp_metric
|
list
|
Metrics to display for grouped analysis. |
None
|
grp_nbins
|
int
|
Number of bins for grouped analysis. Default is 5. |
5
|
withSummary
|
bool
|
Include summary row. Default is True. |
True
|
add_func
|
callable
|
Custom metric function merged into each gains table. |
None
|
sync_range
|
bool
|
Synchronize bin ranges. Default is True. |
True
|
spec_values
|
list
|
Special values to treat separately during binning. |
None
|
include_missing
|
bool
|
Whether to include missing values. Defaults to the instance setting. |
None
|
fillna
|
any
|
Missing-value fill for score binning. Defaults to the instance setting. |
None
|
返回:
| 类型 | 描述 |
|---|---|
DataFrame
|
Gains summary results with score names. |
源代码位于: Modeling_Tool/Eval/Evaluation_Tool.py
708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 | |
get_cross_risk_summary
¶
get_cross_risk_summary(cross_agg_dict: Optional[Dict] = None, nbins: int = 5, equal_freq: Optional[bool] = None, disp: bool = True, spec_values=None, binning_numeric=None) -> DataFrame
Generate cross-risk analysis summary between base and comparison scores.
This method creates a comprehensive cross-tabulation showing risk metrics across different score ranges for both base and comparison scores.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
cross_agg_dict
|
dict
|
Dictionary of column names and aggregation functions. |
None
|
nbins
|
int
|
Number of bins. Default is 5. |
5
|
equal_freq
|
bool
|
Use equal frequency binning. If None, uses self.equal_freq. |
None
|
disp
|
bool
|
Whether to display results. Default is True. |
True
|
spec_values
|
list
|
Special values to keep separate during binning. |
None
|
binning_numeric
|
bool or list/tuple of bool
|
Whether numeric score columns should be binned before cross-risk aggregation. If None, defaults to [True, True] for backward compatibility. Passing a bool applies the same setting to both base and comparison score. |
None
|
返回:
| 类型 | 描述 |
|---|---|
DataFrame
|
Cross-risk summary with base score range, comparison score range, and metrics. |
源代码位于: Modeling_Tool/Eval/Evaluation_Tool.py
876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 | |
multi_subset_wrapper
¶
multi_subset_wrapper(condition_dict: Optional[Dict[str, str]] = None, subset_var_name: str = 'eval_subset', func: Optional[Callable] = None, min_subset_size=10, **kwargs) -> DataFrame
Apply evaluation function across multiple data subsets.
This method iterates over predefined subset conditions, filters the data accordingly, and applies the evaluation function to each subset.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
condition_dict
|
dict
|
Dictionary mapping subset names to query conditions. If None, uses self.subset_condition_dict. |
None
|
subset_var_name
|
str
|
Column name for subset identifier in results. Default is 'eval_subset'. |
'eval_subset'
|
func
|
callable
|
Function to apply to each subset. If None, uses model_perf_compare. |
None
|
**kwargs
|
Additional keyword arguments passed to the evaluation function. |
{}
|
返回:
| 类型 | 描述 |
|---|---|
DataFrame
|
Combined results from all subsets. |
源代码位于: Modeling_Tool/Eval/Evaluation_Tool.py
1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 | |
multi_ylabel_wrapper
¶
multi_ylabel_wrapper(ylabels: Optional[List[str]] = None, ylabel_var_name: str = 'eval_ylabel', eval_func: Optional[Callable] = None, **kwargs) -> DataFrame
Apply evaluation function across multiple target labels.
This method iterates over different target/label columns, temporarily updating the dependent variable for each iteration.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
ylabels
|
list
|
List of target column names. If None, uses self.eval_ylabels. |
None
|
ylabel_var_name
|
str
|
Column name for label identifier in results. Default is 'eval_ylabel'. |
'eval_ylabel'
|
eval_func
|
callable
|
Function to apply for each label. If None, uses model_perf_compare. |
None
|
**kwargs
|
Additional keyword arguments passed to the evaluation function. |
{}
|
返回:
| 类型 | 描述 |
|---|---|
DataFrame
|
Combined results from all labels. |
源代码位于: Modeling_Tool/Eval/Evaluation_Tool.py
multi_group_wrapper
¶
multi_group_wrapper(group_name: Optional[str] = None, group_var_name: str = 'group_name', group_eval_func: Optional[Callable] = None, min_subset_size: int = 10, **kwargs) -> DataFrame
Apply evaluation function across multiple groups.
This method splits data by a grouping column and applies the evaluation function to each group separately.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
group_name
|
str
|
Column name to group by. If None, processes all data together. |
None
|
group_var_name
|
str
|
Column name for group identifier in results. Default is 'group_name'. |
'group_name'
|
group_eval_func
|
callable
|
Function to apply to each group. If None, uses model_perf_compare. |
None
|
min_subset_size
|
int
|
Minimum data size required to process a group. Default is 10. |
10
|
**kwargs
|
Additional keyword arguments passed to the evaluation function. |
{}
|
返回:
| 类型 | 描述 |
|---|---|
DataFrame
|
Combined results from all groups. |
源代码位于: Modeling_Tool/Eval/Evaluation_Tool.py
1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 | |
multi_dim_eval
¶
multi_dim_eval(condition_dict: Optional[Dict[str, str]] = None, eval_ylabels: Optional[List[str]] = None, grp_namelist: Optional[List[str]] = None, eval_func: Optional[Callable] = None, subset_var_name: str = 'eval_subset', ylabel_var_name: str = 'eval_ylabel', var_name: str = 'group_name', value_name: str = 'group_value', **kwargs) -> DataFrame
Perform multi-dimensional evaluation across subsets, labels, and groups.
This method combines multi_subset_wrapper and multi_ylabel_wrapper to evaluate model performance across different dimensions.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
condition_dict
|
dict
|
Subset conditions. If None, uses self.subset_condition_dict. |
None
|
eval_ylabels
|
list
|
Target labels. If None, uses self.eval_ylabels. |
None
|
grp_namelist
|
list
|
Group columns. If None, uses self.grp_namelist. |
None
|
eval_func
|
callable
|
Evaluation function. If None, uses model_perf_compare. |
None
|
subset_var_name
|
str
|
Column name for subset identifier. |
'eval_subset'
|
ylabel_var_name
|
str
|
Column name for label identifier. |
'eval_ylabel'
|
var_name
|
str
|
Column name for group name in results. |
'group_name'
|
value_name
|
str
|
Column name for group value in results. |
'group_value'
|
**kwargs
|
Additional keyword arguments. |
{}
|
返回:
| 类型 | 描述 |
|---|---|
DataFrame
|
Multi-dimensional evaluation results. |
源代码位于: Modeling_Tool/Eval/Evaluation_Tool.py
1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 | |
cross_perf_eval
¶
cross_perf_eval(bad_list: List[str], scr_list: List[str], data: Optional[DataFrame] = None, eval_metric: List[str] = None, melt: bool = True) -> DataFrame
Cross-evaluate model performance across multiple bad flags and scores.
This method calculates performance metrics for all combinations of bad flags and scores, useful for comparing model behavior across different definitions of "bad" outcomes.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
bad_list
|
list
|
List of bad/negative outcome column names. |
必需 |
scr_list
|
list
|
List of score column names. |
必需 |
data
|
DataFrame
|
Data to use. If None, uses self.data. |
None
|
eval_metric
|
list
|
Metrics to extract. If None, uses ['AUC', 'KS', 'N']. |
None
|
melt
|
bool
|
Whether to melt the pivot table. Default is True. |
True
|
返回:
| 类型 | 描述 |
|---|---|
DataFrame
|
Cross performance evaluation results. |
源代码位于: Modeling_Tool/Eval/Evaluation_Tool.py
1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 | |
run_variable_analysis_summary
¶
run_variable_analysis_summary(varlist: List[str], data: Optional[DataFrame] = None, dep: Optional[str] = None, nbins: Optional[int] = None, equal_freq: Optional[bool] = None, min_bin_prop: Optional[float] = None, precision: Optional[int] = None, chi2_method: Optional[bool] = None, chi2_p: Optional[float] = None, init_equi_bins: Optional[int] = None, tree_binning: Optional[bool] = None, include_missing: Optional[bool] = None, missing_rate_ref: Optional[Union[int, float]] = None, seed: Optional[int] = None, spec_values=[]) -> DataFrame
Run comprehensive variable analysis and generate summary report.
This method performs binning analysis on specified variables, calculating metrics like IV (Information Value) and chi-square statistics.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
varlist
|
list
|
List of variable names to analyze. |
必需 |
data
|
DataFrame
|
Data to use. If None, uses self.data. |
None
|
dep
|
str
|
Target variable name. If None, uses self.dep. |
None
|
nbins
|
int
|
Number of bins. If None, uses self.nbins. |
None
|
equal_freq
|
bool
|
Use equal frequency binning. If None, uses self.equal_freq. |
None
|
min_bin_prop
|
float
|
Minimum bin proportion. If None, uses self.min_bin_prop. |
None
|
precision
|
int
|
Decimal precision. If None, uses self.precision. |
None
|
chi2_method
|
bool
|
Use chi-square method. If None, uses self.chi2_method. |
None
|
chi2_p
|
float
|
Chi-square p-value. If None, uses self.chi2_p. |
None
|
init_equi_bins
|
int
|
Initial equal bins. If None, uses self.init_equi_bins. |
None
|
tree_binning
|
bool
|
Use tree binning. If None, uses self.tree_binning. |
None
|
include_missing
|
bool
|
Include missing values. If None, uses self.include_missing. |
None
|
missing_rate_ref
|
int or float
|
Missing reference. If None, uses self.missing_rate_ref. |
None
|
seed
|
int
|
Random seed. If None, uses self.seed. |
None
|
返回:
| 类型 | 描述 |
|---|---|
DataFrame
|
Variable analysis summary with IV and other metrics. |
源代码位于: Modeling_Tool/Eval/Evaluation_Tool.py
1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 | |
pipe
¶
返回一个 EvaluationPipeline 对象,用于链式分组和子集评估。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
data
|
DataFrame
|
指定数据,默认使用 self.data |
None
|
返回:
| 类型 | 描述 |
|---|---|
EvaluationPipeline
|
|
源代码位于: Modeling_Tool/Eval/Evaluation_Tool.py
单/多模型绘图 — evaluate_model¶
evaluate_model
¶
calc_pr
¶
计算P-R曲线相关统计量. 基于sklearn.metrics.precision_recall_curve
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
y_true
|
实际样本标签序列, 只接受0-1 |
必需 | |
y_score
|
预测概率值序列 |
必需 |
返回:
| 名称 | 类型 | 描述 |
|---|---|---|
pr_df |
DataFrame
|
PR相关的Precision、Recall、Thresholds等统计量数据集 |
源代码位于: Modeling_Tool/Eval/evaluate_model.py
summarize_pr
¶
统计P-R曲线信息. 统计量如下: 1.平衡点(Break-Even Point, 简称BEP)阈值及对应Precision、Recall等统计量
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
pr_df
|
PR相关的Precision、Recall、Thresholds等统计量数据集 |
必需 |
返回:
| 名称 | 类型 | 描述 |
|---|---|---|
pr_info |
dict
|
P-R曲线统计信息字典 |
源代码位于: Modeling_Tool/Eval/evaluate_model.py
plot_pr_curve
¶
绘制P-R曲线图.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
pr_dfs
|
单个或多个Score名下的PR数据集. 键值对格式为: {name: pr_df} |
必需 | |
square_figsize
|
正方形图边英寸. 默认值为8 |
8
|
|
to_show
|
是否展示图片. 默认为True |
True
|
|
save_path
|
结果图片存放文件地址. 默认值为None, 即不保存 |
None
|
源代码位于: Modeling_Tool/Eval/evaluate_model.py
calc_roc
¶
计算ROC曲线相关统计量. 基于sklearn.metrics.roc_curve
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
y_true
|
实际样本标签序列, 只接受0-1 |
必需 | |
y_score
|
预测概率值序列 |
必需 |
返回:
| 名称 | 类型 | 描述 |
|---|---|---|
roc_df |
DataFrame
|
ROC相关的TPR、FPR、Thresholds等统计量数据集 |
源代码位于: Modeling_Tool/Eval/evaluate_model.py
summarize_roc
¶
统计ROC曲线信息. 统计量如下: 1. AUC 2. KS及其对应阈值
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
roc_df
|
ROC相关的TPR、FPR、Thresholds等统计量数据集 |
必需 |
返回:
| 名称 | 类型 | 描述 |
|---|---|---|
roc_info |
dict
|
ROC曲线统计信息字典 |
源代码位于: Modeling_Tool/Eval/evaluate_model.py
plot_ks_curve
¶
绘制KS曲线图. 只能绘制单个Score的KS曲线.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
roc_df
|
ROC相关的TPR、FPR、Thresholds等统计量数据集 |
必需 | |
square_figsize
|
正方形图边英寸. 默认值为8 |
8
|
|
to_show
|
是否展示图片. 默认为True |
True
|
|
save_path
|
结果图片存放文件地址. 默认值为None, 即不保存 |
None
|
源代码位于: Modeling_Tool/Eval/evaluate_model.py
plot_roc_curve
¶
plot_roc_curve(roc_dfs, square_figsize=8, fontdicts=fontdicts['main'], to_show=True, save_path=None)
绘制ROC曲线图. 可绘制单个或多个Score的曲线.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
roc_dfs
|
单个或多个Score名下的ROC相关统计量字典 键值对格式为: {name: roc_df} |
必需 | |
square_figsize
|
正方形图边英寸. 默认值为8 |
8
|
|
to_show
|
是否展示图片. 默认为True |
True
|
|
save_path
|
结果图片存放文件地址. 默认值为None, 即不保存 |
None
|
源代码位于: Modeling_Tool/Eval/evaluate_model.py
plot_kde_curve
¶
plot_kde_curve(y_true, y_score_dict, bins=20, square_figsize=8, fontdicts=fontdicts['main'], to_show=True, save_path=None)
绘制Score核密度估计(kernel density estimate, 简称KDE)曲线.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
y_true
|
实际样本标签序列, 只接受0-1 |
必需 | |
y_score_dict
|
单个或多个Score序列字典. 键值对格式为: {name: Score} |
必需 | |
bins
|
分组数 |
20
|
|
square_figsize
|
正方形图边英寸. 默认值为8 |
8
|
|
fontdicts
|
绘图相关字体字典 |
fontdicts['main']
|
|
to_show
|
是否展示图片. 默认为True |
True
|
|
save_path
|
结果图片存放文件地址. 默认值为None, 即不保存 |
None
|
源代码位于: Modeling_Tool/Eval/evaluate_model.py
calc_equid_dist
¶
将Score等距分组, 计算各组统计量.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
y_true
|
实际样本标签序列, 只接受0-1 |
必需 | |
y_score
|
预测概率值序列 |
必需 | |
y_group
|
数据组别序列. 默认为None, 即无组别 |
None
|
|
bins
|
分组数 |
10
|
返回:
| 名称 | 类型 | 描述 |
|---|---|---|
dist_df |
DataFrame
|
等距分组后各组统计量数据集 |
源代码位于: Modeling_Tool/Eval/evaluate_model.py
calc_equid_pct
¶
将Score严格的等分分组, 计算各组统计量.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
y_true
|
实际样本标签序列, 只接受0-1 |
必需 | |
y_score
|
预测概率值序列 |
必需 | |
y_group
|
数据组别序列. 默认为None, 即无组别 |
None
|
|
bins
|
分组数 |
10
|
|
ascending
|
y_score是否按升序排序, 默认为True |
True
|
返回:
| 名称 | 类型 | 描述 |
|---|---|---|
pct_df |
DataFrame
|
等分分组后各组统计量数据集 |
源代码位于: Modeling_Tool/Eval/evaluate_model.py
calc_fixed_pct
¶
使用固定Score边界分组, 计算各组统计量.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
y_true
|
实际样本标签序列, 只接受0-1 |
必需 | |
y_score
|
预测概率值序列 |
必需 | |
y_group
|
数据组别序列. 默认为None, 即无组别 |
None
|
|
bin_edges
|
固定分箱边界, 通常来自benchmark数据集 |
None
|
|
ascending
|
y_score是否按升序分箱. 默认为True |
True
|
返回:
| 名称 | 类型 | 描述 |
|---|---|---|
pct_df |
DataFrame
|
固定分箱后各组统计量数据集 |
源代码位于: Modeling_Tool/Eval/evaluate_model.py
summarize_pct
¶
统计等分分组信息.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
pct_df
|
等分分组后各组统计量数据集 |
必需 |
返回:
| 名称 | 类型 | 描述 |
|---|---|---|
pct_info |
dict
|
等分分组统计信息字典 |
源代码位于: Modeling_Tool/Eval/evaluate_model.py
plot_dist_curve
¶
plot_dist_curve(dist_dfs, square_figsize=8, fontdicts=fontdicts['main'], to_show=True, save_path=None)
绘制Score分布曲线图.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
dist_dfs
|
单个或多个Score名下的相同组数, 等距分组后各组统计量数据集. 键值对格式为: {name: dist_df} |
必需 | |
square_figsize
|
正方形图边英寸. 默认值为8 |
8
|
|
fontdicts
|
绘图相关字体字典 |
fontdicts['main']
|
|
to_show
|
是否展示图片. 默认为True |
True
|
|
save_path
|
结果图片存放文件地址. 默认值为None, 即不保存 |
None
|
源代码位于: Modeling_Tool/Eval/evaluate_model.py
plot_cumdist_curve
¶
plot_cumdist_curve(dist_dfs, square_figsize=8, fontdicts=fontdicts['main'], to_show=True, save_path=None)
绘制Score分布曲线图.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
dist_dfs
|
单个或多个Score名下的相同组数, 等距分组后各组统计量数据集. 键值对格式为: {name: dist_df} |
必需 | |
square_figsize
|
正方形图边英寸. 默认值为8 |
8
|
|
fontdicts
|
绘图相关字体字典 |
fontdicts['main']
|
|
to_show
|
是否展示图片. 默认为True |
True
|
|
save_path
|
结果图片存放文件地址. 默认值为None, 即不保存 |
None
|
源代码位于: Modeling_Tool/Eval/evaluate_model.py
plot_pct_curve
¶
plot_pct_curve(pct_dfs, square_figsize=8, fontdicts=fontdicts['main'], to_show=True, save_path=None)
绘制Score分布曲线图.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
pct_dfs
|
单个或多个Score名下的等分组后各组统计量数据集. 键值对格式为: {name: pct_df} |
必需 | |
square_figsize
|
正方形图边英寸. 默认值为8 |
8
|
|
to_show
|
是否展示图片. 默认为True |
True
|
|
save_path
|
结果图片存放文件地址. 默认值为None, 即不保存 |
None
|
源代码位于: Modeling_Tool/Eval/evaluate_model.py
plot_cumpct_curve
¶
plot_cumpct_curve(pct_dfs, square_figsize=8, fontdicts=fontdicts['main'], to_show=True, save_path=None)
绘制Score分布曲线图.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
pct_dfs
|
单个或多个Score名下的等分组后各组统计量数据集. 键值对格式为: {name: pct_df} |
必需 | |
square_figsize
|
正方形图边英寸. 默认值为8 |
8
|
|
to_show
|
是否展示图片. 默认为True |
True
|
|
save_path
|
结果图片存放文件地址. 默认值为None, 即不保存 |
None
|
源代码位于: Modeling_Tool/Eval/evaluate_model.py
plot_gain_curve
¶
plot_gain_curve(pct_dfs, square_figsize=8, fontdicts=fontdicts['main'], to_show=True, save_path=None)
绘制Score分布曲线图.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
pct_dfs
|
单个或多个Score名下的等分组后各组统计量数据集. 键值对格式为: {name: pct_df} |
必需 | |
square_figsize
|
正方形图边英寸. 默认值为8 |
8
|
|
to_show
|
是否展示图片. 默认为True |
True
|
|
save_path
|
结果图片存放文件地址. 默认值为None, 即不保存 |
None
|
源代码位于: Modeling_Tool/Eval/evaluate_model.py
evaluate_performance
¶
evaluate_performance(datasets, dist_bins=20, pct_bins=10, square_figsize=5, fontdicts=fontdicts['sub'], to_show=True, save_path=None, gains_table=True, equal_freq=True, pct_bin_edges=None, sample_weight=None)
绘制单模型预测效果评价图.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
datasets
|
数据集字典. 键值对格式为: {dataname: {'y_true': y_true, 'y_score': y_score}} |
必需 | |
dist_bins
|
等距分组数. 默认值为20 |
20
|
|
pct_bins
|
等分分组数. 默认值为10 |
10
|
|
square_figsize
|
正方形图边英寸. 默认值为8 |
5
|
|
fontdicts
|
绘图相关字体字典. 默认值为fontdicts['sub'] |
fontdicts['sub']
|
|
to_show
|
是否展示图片. 默认为True |
True
|
|
save_path
|
结果图片存放文件地址. 默认值为None, 即不保存 |
None
|
返回:
| 名称 | 类型 | 描述 |
|---|---|---|
result_df |
DataFrame
|
模型评价指标汇总数据集 |
源代码位于: Modeling_Tool/Eval/evaluate_model.py
1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 | |
evaluate_distribution
¶
evaluate_distribution(datasets, dist_bins=10, square_figsize=5, fontdicts=fontdicts['sub'], toplot=True, save_path=None)
绘制单模型在多样本集上模型分分布.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
datasets
|
数据集字典. 键值对格式为: {dataname: {'y_true': y_true, 'y_score': y_score, 'y_group': y_group}} |
必需 | |
dist_bins
|
等距分组数. 默认值为20 |
10
|
|
square_figsize
|
正方形图边英寸. 默认值为8 |
5
|
|
fontdicts
|
绘图相关字体字典. 默认值为fontdicts['sub'] |
fontdicts['sub']
|
|
toplot
|
是否展示图片. 默认为True |
True
|
|
save_path
|
结果图片存放文件地址. 默认值为None, 即不保存 |
None
|
返回:
| 名称 | 类型 | 描述 |
|---|---|---|
result_df |
DataFrame
|
模型评价指标汇总数据集 |
源代码位于: Modeling_Tool/Eval/evaluate_model.py
comparison_performance
¶
comparison_performance(datasets, pct_bins=10, square_figsize=5, fontdicts=fontdicts['sub'], to_show=True, save_path=None)
绘制多个模型预测效果对比图.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
datasets
|
数据集字典. 键值对格式为: {dataname: {'y_true': y_true, 'y_score': y_score, 'y_group': y_group}} |
必需 | |
pct_bins
|
等分分组数. 默认值为10 |
10
|
|
square_figsize
|
正方形图边英寸. 默认值为5 |
5
|
|
fontdicts
|
绘图相关字体字典. 默认值为fontdicts['sub'] |
fontdicts['sub']
|
|
to_show
|
是否展示图片. 默认为True |
True
|
|
save_path
|
结果图片存放文件地址. 默认值为None, 即不保存 |
None
|
返回:
| 名称 | 类型 | 描述 |
|---|---|---|
result_df |
DataFrame
|
模型评价指标汇总数据集 |
源代码位于: Modeling_Tool/Eval/evaluate_model.py
calc_lift_apt
¶
给定Lift取值范围, 求解Lift表.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
y_true
|
实际样本标签序列, 只接受0-1 |
必需 | |
y_score
|
预测概率值序列 |
必需 | |
start
|
起始值 |
必需 | |
stop
|
终止值 |
必需 | |
step
|
步长 |
必需 | |
score_ascending
|
y_score为升序序列, 即数值越大y_true=1可能性越大. 默认为True |
True
|
返回:
| 名称 | 类型 | 描述 |
|---|---|---|
lift_df |
DataFrame
|
Lift表 |
源代码位于: Modeling_Tool/Eval/evaluate_model.py
1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 | |