blocks-transformer/post_processing.py
Admin User 95034efa4e
All checks were successful
Build and Push Docker Image / test (push) Successful in 2m30s
Build and Push Docker Image / build_and_push (push) Successful in 4m50s
Series M v1 model
2025-06-13 18:01:40 +00:00

62 lines
1.9 KiB
Python

import math
def post_processing(processing_output):
prediction = processing_output["prediction"]
shape_reasoncode = processing_output["shape_reasoncode"]
# grade mapping: [0.00,0.01]→M1, (0.01,0.02]→M2, … cap at M14
if prediction < 0:
grade = "M14"
else:
m = math.ceil(prediction / 0.01)
m = max(m, 1)
m = min(m, 14)
grade = f"M{m}"
# if prediction ≤ 0.04, not declined
if prediction <= 0.04:
return {
"grade": grade,
"reason_description": None
}
conditions = {
'evtg04': lambda x: x < 700,
'eads66': lambda x: x < 700,
's004s': lambda x: x < 12,
'mt34s': lambda x: x > 95,
'ct320': lambda x: x <= 3,
'us21s': lambda x: x <= 3,
'utlmag02': lambda x: x > 300,
'trv01': lambda x: x > 3,
'us34s': lambda x: x > 90
}
reason_map = {
'evtg04': "System Generated",
'eads66': "System Generated",
's004s': "Length of time on file is too short",
'mt34s': "Too high open mortgage credit utilization recently",
'ct320': "Insufficient payment activity",
'us21s': "Length of time since most recent installment account has been established is too short",
'utlmag02': "Too high revolving credit utilization over the last 24 months",
'trv01': "Recency of a balance overlimit on a bankcard account",
'us34s': "Too high open unsecured installment credit utilization recently"
}
for item in shape_reasoncode:
feat = item["feature"]
val = item["value"]
cond = conditions.get(feat)
if cond and cond(val):
return {
"grade": grade,
"reason_description": reason_map[feat]
}
return {
"grade": grade,
"reason_description": None
}