blocks-transformer/post_processing.py
Admin User 295b9d22a7
All checks were successful
Build and Push Docker Image / test (push) Successful in 1m19s
Build and Push Docker Image / build_and_push (push) Successful in 2m54s
Upload files to "/"
2025-06-18 10:15:49 +00:00

67 lines
2.3 KiB
Python

import math
def post_processing(processing_output):
prediction = processing_output["prediction"]
shape_reasoncode = processing_output["shape_reasoncode"]
# grade mapping:
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,
'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",
'mt34s': "Not enough balance decreases on mortgage trades in the past 12 months",
'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",
'utlmag02': "Revolving account balances are too high in proportion to credit limits over the last 24 months",
'trv01': "Recency of a balance overlimit on a bankcard account",
# 'us34s': "Too high open unsecured installment credit utilization recently"
'us34s': "Not enough balance decreases on installment trades in the past 12 months"
}
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": "No suitable Product Offerings found"
}