Examples · Scorecards

build_scorecard

Collapse the compiled artifact into its exact scorecard, print every table and grid in full, and prove it by re-summing a decision.

Code#

build_scorecard.py
from _setup import artifact, row
 
from compileml.runtime import decide, score_micro
from compileml.scorecard import build_scorecard, score_from_scorecard, scorecard_to_markdown
 
card = build_scorecard(artifact)
 
print("base points (micro) ", card["base_points_micro"])
print("main effect tables ", len(card["main_effects"]))
print("interaction grids ", len(card["interactions"]))
print("whitebox max depth ", card["whitebox_max_depth"])
print("exact ", card["exact"])
 
# At depth 2 a tree can split on two different features, so most of the model
# lands in pairwise grids rather than one table per feature.
 
# The audit re-sum. The table below is the model, not a summary of it. Both
# sides are raw micro units: the scorecard reproduces the score before it is
# divided down to the display scale that decide() reports.
from_card = score_from_scorecard(card, row)
from_runtime = score_micro(artifact["model"], row)
 
print()
print("from the scorecard table :", from_card)
print("from the runtime :", from_runtime)
print("identical :", from_card == from_runtime)
print()
print("displayed as latent_int :", decide(artifact, row, explain=False)["latent_int"])
 
# The whole scorecard, as `compileml scorecard` prints it: base points plus
# every table and grid, each cell in micro units and display points.
print()
print(scorecard_to_markdown(card))

Output#

Captured from an actual run against compileml 0.9.0 and the UCI credit panel. If this script stops working, the build fails.

captured in CIbuild_scorecard.py
base points (micro) 221926
main effect tables 0
interaction grids 35
whitebox max depth 2
exact True
 
from the scorecard table : 341214
from the runtime : 341214
identical : True
 
displayed as latent_int : 341

Printed in full#

The rest of the same run's output, rendered as tables. Nothing is elided.

  • artifact: a31afc9bf476ce94…
  • trees: 30 · depth: 2 · exact: yes
  • base points: +221,926 µ (+221.9 pts)

Points are the artifact's integers (micro units); base + bins + grids re-sum to every decision's raw_micro exactly.

Interaction: LIMIT_BAL × PAY_1#

LIMIT_BAL \ PAY_1<= 0.5(0.5, 1.5](1.5, 3.5](3.5, 4.5]> 4.5
<= 45000+12,945 µ (+12.9 pts)+15,229 µ (+15.2 pts)+28,741 µ (+28.7 pts)-13,330 µ (-13.3 pts)-37,966 µ (-38.0 pts)
(45000, 75000]+6,491 µ (+6.5 pts)+8,775 µ (+8.8 pts)+22,287 µ (+22.3 pts)+4,403 µ (+4.4 pts)-20,233 µ (-20.2 pts)
(75000, 145000]-4,798 µ (-4.8 pts)+8,775 µ (+8.8 pts)+22,287 µ (+22.3 pts)+4,403 µ (+4.4 pts)-20,233 µ (-20.2 pts)
(145000, 245000]-6,071 µ (-6.1 pts)+7,502 µ (+7.5 pts)+21,014 µ (+21.0 pts)+21,014 µ (+21.0 pts)-3,622 µ (-3.6 pts)
> 245000-6,857 µ (-6.9 pts)+6,716 µ (+6.7 pts)+20,228 µ (+20.2 pts)+20,228 µ (+20.2 pts)+20,228 µ (+20.2 pts)

Interaction: LIMIT_BAL × PAY_3#

LIMIT_BAL \ PAY_3<= 1> 1
<= 225000+312 µ (+0.3 pts)+4,745 µ (+4.7 pts)
> 225000+0 µ (+0.0 pts)+0 µ (+0.0 pts)

Interaction: LIMIT_BAL × PAY_5#

LIMIT_BAL \ PAY_5<= 1> 1
<= 145000+2,509 µ (+2.5 pts)+13,133 µ (+13.1 pts)
> 145000+0 µ (+0.0 pts)+0 µ (+0.0 pts)

Interaction: LIMIT_BAL × PAY_6#

LIMIT_BAL \ PAY_6<= 1> 1
<= 145000+1,852 µ (+1.9 pts)+10,004 µ (+10.0 pts)
> 145000+0 µ (+0.0 pts)+0 µ (+0.0 pts)

Interaction: LIMIT_BAL × BILL_AMT1#

LIMIT_BAL \ BILL_AMT1<= 3746> 3746
<= 145000+0 µ (+0.0 pts)+0 µ (+0.0 pts)
> 145000+1,392 µ (+1.4 pts)-2,514 µ (-2.5 pts)

Interaction: LIMIT_BAL × BILL_AMT2#

LIMIT_BAL \ BILL_AMT2<= 172015(172015, 221900]> 221900
<= 25000+6,540 µ (+6.5 pts)+6,540 µ (+6.5 pts)+6,540 µ (+6.5 pts)
(25000, 165000]+937 µ (+0.9 pts)+937 µ (+0.9 pts)+937 µ (+0.9 pts)
(165000, 225000]-3,580 µ (-3.6 pts)+4,826 µ (+4.8 pts)+4,826 µ (+4.8 pts)
> 225000-7,521 µ (-7.5 pts)+885 µ (+0.9 pts)+10,661 µ (+10.7 pts)

Interaction: LIMIT_BAL × BILL_AMT5#

LIMIT_BAL \ BILL_AMT5<= 229044> 229044
<= 245000+0 µ (+0.0 pts)+0 µ (+0.0 pts)
> 245000-3,161 µ (-3.2 pts)+6,733 µ (+6.7 pts)

Interaction: LIMIT_BAL × PAY_AMT1#

LIMIT_BAL \ PAY_AMT1<= 921> 921
<= 145000+0 µ (+0.0 pts)+0 µ (+0.0 pts)
> 145000+2,429 µ (+2.4 pts)-5,187 µ (-5.2 pts)

Interaction: LIMIT_BAL × PAY_AMT2#

LIMIT_BAL \ PAY_AMT2<= 16652.5> 16652.5
<= 25000+4,870 µ (+4.9 pts)+0 µ (+0.0 pts)
> 25000-56 µ (-0.1 pts)+0 µ (+0.0 pts)

Interaction: LIMIT_BAL × PAY_AMT3#

LIMIT_BAL \ PAY_AMT3<= 0.5(0.5, 391]> 391
<= 45000+0 µ (+0.0 pts)+0 µ (+0.0 pts)+0 µ (+0.0 pts)
(45000, 145000]+2,961 µ (+3.0 pts)+2,961 µ (+3.0 pts)-2,294 µ (-2.3 pts)
> 145000+6,934 µ (+6.9 pts)-3,353 µ (-3.4 pts)-8,608 µ (-8.6 pts)

Interaction: PAY_1 × PAY_2#

PAY_1 \ PAY_2<= -0.5(-0.5, 1.5]> 1.5
<= 0.5-28,690 µ (-28.7 pts)-28,690 µ (-28.7 pts)+25,449 µ (+25.4 pts)
(0.5, 1.5]+10,714 µ (+10.7 pts)+39,982 µ (+40.0 pts)+94,121 µ (+94.1 pts)
> 1.5+31,613 µ (+31.6 pts)+109,116 µ (+109.1 pts)+109,116 µ (+109.1 pts)

Interaction: PAY_1 × PAY_3#

PAY_1 \ PAY_3<= -0.5(-0.5, 1.5]> 1.5
<= 1.5-10,446 µ (-10.4 pts)-10,446 µ (-10.4 pts)+28,779 µ (+28.8 pts)
> 1.5+49,014 µ (+49.0 pts)+95,086 µ (+95.1 pts)+95,086 µ (+95.1 pts)

Interaction: PAY_1 × PAY_4#

PAY_1 \ PAY_4<= 0.5(0.5, 1]> 1
<= 0.5-11,617 µ (-11.6 pts)-10,865 µ (-10.9 pts)+21,431 µ (+21.4 pts)
(0.5, 1.5]+16,580 µ (+16.6 pts)+17,332 µ (+17.3 pts)+17,332 µ (+17.3 pts)
> 1.5+51,995 µ (+52.0 pts)+47,198 µ (+47.2 pts)+47,198 µ (+47.2 pts)

Interaction: PAY_1 × PAY_5#

PAY_1 \ PAY_5<= 1> 1
<= 1.5-8,313 µ (-8.3 pts)+16,501 µ (+16.5 pts)
(1.5, 3.5]+93,516 µ (+93.5 pts)+77,247 µ (+77.2 pts)
> 3.5+93,516 µ (+93.5 pts)+51,307 µ (+51.3 pts)

Interaction: PAY_1 × BILL_AMT1#

PAY_1 \ BILL_AMT1<= 569.5(569.5, 1002.5]> 1002.5
<= 1.5+0 µ (+0.0 pts)+0 µ (+0.0 pts)+0 µ (+0.0 pts)
> 1.5-36,216 µ (-36.2 pts)-6,071 µ (-6.1 pts)+26,236 µ (+26.2 pts)

Interaction: PAY_1 × PAY_AMT2#

PAY_1 \ PAY_AMT2<= 1633.5> 1633.5
<= 0.5+2,348 µ (+2.3 pts)-12,802 µ (-12.8 pts)
> 0.5+0 µ (+0.0 pts)+0 µ (+0.0 pts)

Interaction: PAY_1 × PAY_AMT3#

PAY_1 \ PAY_AMT3<= 450.5> 450.5
<= 1.5+5,467 µ (+5.5 pts)-3,995 µ (-4.0 pts)
> 1.5+0 µ (+0.0 pts)+0 µ (+0.0 pts)

Interaction: PAY_1 × PAY_AMT6#

PAY_1 \ PAY_AMT6<= 836.5(836.5, 932.5]> 932.5
<= 1.5+3,206 µ (+3.2 pts)+1,355 µ (+1.4 pts)-5,731 µ (-5.7 pts)
> 1.5+0 µ (+0.0 pts)+4,273 µ (+4.3 pts)+4,273 µ (+4.3 pts)

Interaction: PAY_2 × PAY_4#

PAY_2 \ PAY_4<= 0.5> 0.5
<= 0.5+0 µ (+0.0 pts)+6,586 µ (+6.6 pts)
> 0.5+0 µ (+0.0 pts)+817 µ (+0.8 pts)

Interaction: PAY_2 × PAY_6#

PAY_2 \ PAY_6<= 1> 1
<= 1.5+0 µ (+0.0 pts)+17,728 µ (+17.7 pts)
(1.5, 3.5]+15,491 µ (+15.5 pts)+51,346 µ (+51.3 pts)
> 3.5+15,491 µ (+15.5 pts)+29,056 µ (+29.1 pts)

Interaction: PAY_2 × PAY_AMT2#

PAY_2 \ PAY_AMT2<= 16652.5> 16652.5
<= 1.5-342 µ (-0.3 pts)+0 µ (+0.0 pts)
> 1.5+5,572 µ (+5.6 pts)+0 µ (+0.0 pts)

Interaction: PAY_2 × PAY_AMT3#

PAY_2 \ PAY_AMT3<= 1301.5> 1301.5
<= 1.5+3,796 µ (+3.8 pts)-9,053 µ (-9.1 pts)
> 1.5+0 µ (+0.0 pts)+0 µ (+0.0 pts)

Interaction: PAY_3 × PAY_AMT1#

PAY_3 \ PAY_AMT1<= 2000.5(2000.5, 4569]> 4569
<= 1.5+2,369 µ (+2.4 pts)-6,154 µ (-6.2 pts)-6,154 µ (-6.2 pts)
> 1.5+15,247 µ (+15.2 pts)+15,247 µ (+15.2 pts)+4,825 µ (+4.8 pts)

Interaction: PAY_4 × PAY_5#

PAY_4 \ PAY_5<= 1> 1
<= 1.5+0 µ (+0.0 pts)+0 µ (+0.0 pts)
> 1.5+13,650 µ (+13.7 pts)+25,796 µ (+25.8 pts)

Interaction: PAY_4 × PAY_AMT2#

PAY_4 \ PAY_AMT2<= 1625.5> 1625.5
<= 1.5+3,954 µ (+4.0 pts)-7,483 µ (-7.5 pts)
> 1.5+0 µ (+0.0 pts)+0 µ (+0.0 pts)

Interaction: PAY_5 × PAY_6#

PAY_5 \ PAY_6<= 1> 1
<= 1+0 µ (+0.0 pts)+0 µ (+0.0 pts)
> 1+21,394 µ (+21.4 pts)+38,123 µ (+38.1 pts)

Interaction: PAY_6 × PAY_AMT4#

PAY_6 \ PAY_AMT4<= 0.5(0.5, 1000.5]> 1000.5
<= 1+3,559 µ (+3.6 pts)+1,755 µ (+1.8 pts)-7,948 µ (-7.9 pts)
> 1+0 µ (+0.0 pts)+5,890 µ (+5.9 pts)+5,890 µ (+5.9 pts)

Interaction: BILL_AMT1 × PAY_AMT1#

BILL_AMT1 \ PAY_AMT1<= 4524> 4524
<= 8304.5+3,550 µ (+3.5 pts)-5,472 µ (-5.5 pts)
(8304.5, 129626]-427 µ (-0.4 pts)-5,472 µ (-5.5 pts)
> 129626-427 µ (-0.4 pts)+2,198 µ (+2.2 pts)

Interaction: BILL_AMT1 × PAY_AMT3#

BILL_AMT1 \ PAY_AMT3<= 0.5> 0.5
<= 2+4,698 µ (+4.7 pts)-8,202 µ (-8.2 pts)
(2, 8371]+4,698 µ (+4.7 pts)-292 µ (-0.3 pts)
> 8371-1,218 µ (-1.2 pts)-292 µ (-0.3 pts)

Interaction: BILL_AMT1 × PAY_AMT4#

BILL_AMT1 \ PAY_AMT4<= 0.5> 0.5
<= 8564+6,661 µ (+6.7 pts)+0 µ (+0.0 pts)
> 8564-237 µ (-0.2 pts)+0 µ (+0.0 pts)

Interaction: BILL_AMT1 × PAY_AMT5#

BILL_AMT1 \ PAY_AMT5<= 713.5> 713.5
<= 8338+3,794 µ (+3.8 pts)+0 µ (+0.0 pts)
> 8338-551 µ (-0.6 pts)+0 µ (+0.0 pts)

Interaction: BILL_AMT1 × PAY_AMT6#

BILL_AMT1 \ PAY_AMT6<= 836.5> 836.5
<= 8287+4,282 µ (+4.3 pts)+0 µ (+0.0 pts)
> 8287-334 µ (-0.3 pts)+0 µ (+0.0 pts)

Interaction: BILL_AMT2 × PAY_AMT2#

BILL_AMT2 \ PAY_AMT2<= 16652.5> 16652.5
<= 177894+0 µ (+0.0 pts)-10,040 µ (-10.0 pts)
> 177894+0 µ (+0.0 pts)-2,617 µ (-2.6 pts)

Interaction: BILL_AMT3 × PAY_AMT5#

BILL_AMT3 \ PAY_AMT5<= 713.5> 713.5
<= 191588+0 µ (+0.0 pts)-1,360 µ (-1.4 pts)
> 191588+0 µ (+0.0 pts)+5,026 µ (+5.0 pts)

Interaction: BILL_AMT5 × PAY_AMT2#

BILL_AMT5 \ PAY_AMT2<= 16652.5> 16652.5
<= 14315+0 µ (+0.0 pts)-3,379 µ (-3.4 pts)
> 14315+0 µ (+0.0 pts)-7,138 µ (-7.1 pts)

Notes#

  • This artifact has no main-effect tables. At depth 2 its trees split on two different features, so every point sits in a pairwise grid; max_depth=1 gives the classic one-table-per-feature form.
  • To score an applicant, add the base points to one cell from each grid, chosen by the applicant's two feature values. The sum is the raw score in micro units, exactly.
  • The same tables come from the command line: compileml scorecard decision.json --format markdown, or --format csv.

API reference: build_scorecard →