PD v1 Processing block
This commit is contained in:
parent
70590db6b5
commit
88c2489d18
10
README.md
10
README.md
@ -1 +1,9 @@
|
|||||||
**Hello world!!!**
|
## Overview
|
||||||
|
This block (`block.py`) is responsible for loading and scoring the model for the passed in probability.
|
||||||
|
|
||||||
|
## Key Inputs & Outputs
|
||||||
|
- **Request**: Refer to `request_schema.json` for detailed input fields and validation rules.
|
||||||
|
- **Response**: Refer to `response_schema.json` for the returned structure and data types.
|
||||||
|
|
||||||
|
## Implementation Details
|
||||||
|
- All core logic resides in `block.py` within the `__main__` function.
|
||||||
|
|||||||
69
block.py
69
block.py
@ -1,21 +1,58 @@
|
|||||||
@flowx_block
|
import logging
|
||||||
def example_function(request: dict) -> dict:
|
import requests
|
||||||
|
|
||||||
# Processing logic here...
|
# Configure logging
|
||||||
|
logging.basicConfig(
|
||||||
|
level=logging.INFO,
|
||||||
|
format="%(asctime)s [%(levelname)s] %(name)s - %(message)s",
|
||||||
|
)
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
return {
|
url = "http://centurion-h2o-server.default.svc.cluster.local:8000/scoring"
|
||||||
"meta_info": [
|
headers = {
|
||||||
{
|
"accept": "application/json",
|
||||||
"name": "created_date",
|
"Content-Type": "application/json"
|
||||||
"type": "string",
|
|
||||||
"value": "2024-11-05"
|
|
||||||
}
|
}
|
||||||
],
|
|
||||||
"fields": [
|
def __main__(pti: float, score_results: int, revolving_amount_monthly_payment: int, AT31S: int, total_amount_high_credit: int, AT20S: int, BALMAG01: int, record_counts_revolving_trade_count: int, PAYMNT10: int, closed_with_balance_amount_current_balance: int, REV83: int, AGG102: int, BC21S: int, record_counts_total_trade_count: int, revolving_amount_current_balance: int, total_amount_current_balance: int, revolving_amount_high_credit: int, US01S: int, AGG101: int, closed_with_balance_amount_monthly_payment: int, revolving_amount_credit_limit: int, revolving_amount_percent_available_credit: int, AT09S: int) -> dict:
|
||||||
{
|
input_data = {
|
||||||
"name": "",
|
"pti": pti, "score_results": score_results, "revolving_amount_monthly_payment": revolving_amount_monthly_payment,
|
||||||
"type": "",
|
"AT31S": AT31S, "total_amount_high_credit": total_amount_high_credit, "AT20S": AT20S, "BALMAG01": BALMAG01,
|
||||||
"value": ""
|
"record_counts_revolving_trade_count": record_counts_revolving_trade_count, "PAYMNT10": PAYMNT10,
|
||||||
|
"closed_with_balance_amount_current_balance": closed_with_balance_amount_current_balance, "REV83": REV83,
|
||||||
|
"AGG102": AGG102, "BC21S": BC21S, "record_counts_total_trade_count": record_counts_total_trade_count,
|
||||||
|
"revolving_amount_current_balance": revolving_amount_current_balance, "total_amount_current_balance": total_amount_current_balance,
|
||||||
|
"revolving_amount_high_credit": revolving_amount_high_credit, "US01S": US01S, "AGG101": AGG101,
|
||||||
|
"closed_with_balance_amount_monthly_payment": closed_with_balance_amount_monthly_payment,
|
||||||
|
"revolving_amount_credit_limit": revolving_amount_credit_limit, "revolving_amount_percent_available_credit": revolving_amount_percent_available_credit,
|
||||||
|
"AT09S": AT09S
|
||||||
}
|
}
|
||||||
]
|
|
||||||
|
filtered_data = {key: value for key, value in input_data.items() if value is not None}
|
||||||
|
data = {
|
||||||
|
"model_name": "pd_v1",
|
||||||
|
"features": filtered_data
|
||||||
}
|
}
|
||||||
|
try:
|
||||||
|
try:
|
||||||
|
response = requests.post(url, headers=headers, json=data)
|
||||||
|
response.raise_for_status() # Raise an error for HTTP issues
|
||||||
|
|
||||||
|
# Parse the response and return the "p1" value
|
||||||
|
response_data = response.json()
|
||||||
|
print("response json", response_data)
|
||||||
|
p1_value = response_data.get("prediction", {}).get("p1")
|
||||||
|
except requests.RequestException as error:
|
||||||
|
logger.error(f"Error while predicting: {error}")
|
||||||
|
return None
|
||||||
|
|
||||||
|
if p1_value is not None:
|
||||||
|
logger.info(f"Prediction p1: {p1_value}")
|
||||||
|
return {'probability': float(p1_value)}
|
||||||
|
else:
|
||||||
|
logger.error("Response does not contain 'p1'")
|
||||||
|
return None
|
||||||
|
|
||||||
|
except Exception as error:
|
||||||
|
logger.error(f"Error while predicting: {error}")
|
||||||
|
return {'error': str(error)}
|
||||||
@ -1 +1,99 @@
|
|||||||
{}
|
{
|
||||||
|
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"pti": {
|
||||||
|
"type": ["number", "null"],
|
||||||
|
"description": "External + internal monthly payment to income ratio"
|
||||||
|
},
|
||||||
|
"score_results": {
|
||||||
|
"type": ["number", "null"],
|
||||||
|
"description": "TransUnion score"
|
||||||
|
},
|
||||||
|
"revolving_amount_monthly_payment": {
|
||||||
|
"type": ["number", "null"],
|
||||||
|
"description": "Minimum amount the borrower is required to pay each month to maintain the account in good standing"
|
||||||
|
},
|
||||||
|
"AT31S": {
|
||||||
|
"type": ["integer", "null"],
|
||||||
|
"description": "Percentage of open trades > 75% of credit line verified in past 12 months"
|
||||||
|
},
|
||||||
|
"total_amount_high_credit": {
|
||||||
|
"type": ["number", "null"],
|
||||||
|
"description": "The highest credit amount extended across all credit accounts"
|
||||||
|
},
|
||||||
|
"AT20S": {
|
||||||
|
"type": ["integer", "null"],
|
||||||
|
"description": "Months since oldest trade opened"
|
||||||
|
},
|
||||||
|
"BALMAG01": {
|
||||||
|
"type": ["number", "null"],
|
||||||
|
"description": "Non-mortgage balance magnitude"
|
||||||
|
},
|
||||||
|
"record_counts_revolving_trade_count": {
|
||||||
|
"type": ["integer", "null"],
|
||||||
|
"description": "Records in the database related to revolving trade accounts (a credit card account)"
|
||||||
|
},
|
||||||
|
"PAYMNT10": {
|
||||||
|
"type": ["number", "null"],
|
||||||
|
"description": "Number of payments in the last quarter"
|
||||||
|
},
|
||||||
|
"closed_with_balance_amount_current_balance": {
|
||||||
|
"type": ["number", "null"],
|
||||||
|
"description": "The current balance of closed credit accounts"
|
||||||
|
},
|
||||||
|
"REV83": {
|
||||||
|
"type": ["number", "null"],
|
||||||
|
"description": "Months since a revolving account last exceeded 75% utilization"
|
||||||
|
},
|
||||||
|
"AGG102": {
|
||||||
|
"type": ["number", "null"],
|
||||||
|
"description": "Aggregate non-mortgage balances for month 2"
|
||||||
|
},
|
||||||
|
"BC21S": {
|
||||||
|
"type": ["integer", "null"],
|
||||||
|
"description": "Months since most recent credit card trade opened"
|
||||||
|
},
|
||||||
|
"record_counts_total_trade_count": {
|
||||||
|
"type": ["integer", "null"],
|
||||||
|
"description": "Total number of trade-related (transaction) records"
|
||||||
|
},
|
||||||
|
"revolving_amount_current_balance": {
|
||||||
|
"type": ["number", "null"],
|
||||||
|
"description": "The current owed balance on revolving credit accounts"
|
||||||
|
},
|
||||||
|
"total_amount_current_balance": {
|
||||||
|
"type": ["number", "null"],
|
||||||
|
"description": "The total current balance across all credit accounts"
|
||||||
|
},
|
||||||
|
"revolving_amount_high_credit": {
|
||||||
|
"type": ["number", "null"],
|
||||||
|
"description": "The highest credit amount that has been extended to the borrower in revolving credit accounts"
|
||||||
|
},
|
||||||
|
"US01S": {
|
||||||
|
"type": ["integer", "null"],
|
||||||
|
"description": "Number of unsecured installment trades"
|
||||||
|
},
|
||||||
|
"AGG101": {
|
||||||
|
"type": ["number", "null"],
|
||||||
|
"description": "Aggregate non-mortgage balances for month 1"
|
||||||
|
},
|
||||||
|
"closed_with_balance_amount_monthly_payment": {
|
||||||
|
"type": ["number", "null"],
|
||||||
|
"description": "The monthly payment amount for closed credit accounts (loans)"
|
||||||
|
},
|
||||||
|
"revolving_amount_credit_limit": {
|
||||||
|
"type": ["number", "null"],
|
||||||
|
"description": "The total credit limit on revolving credit accounts"
|
||||||
|
},
|
||||||
|
"revolving_amount_percent_available_credit": {
|
||||||
|
"type": ["number", "null"],
|
||||||
|
"description": "The percentage of available credit that has been utilized in revolving credit accounts"
|
||||||
|
},
|
||||||
|
"AT09S": {
|
||||||
|
"type": ["integer", "null"],
|
||||||
|
"description": "Number of trades opened in past 24 months"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": []
|
||||||
|
}
|
||||||
|
|||||||
@ -1 +1,2 @@
|
|||||||
{}
|
jsonschema==4.23.0
|
||||||
|
requests==2.32.3
|
||||||
@ -1 +1,10 @@
|
|||||||
{}
|
{
|
||||||
|
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"probability": {
|
||||||
|
"type": "number",
|
||||||
|
"description": "Model predicted score."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user