<jupyter_start><jupyter_text>Imports<jupyter_code>import boto3
import json<jupyter_output><empty_output><jupyter_text>Essentials<jupyter_code># ENDPOINT_NAME = 'ENTER DEPLOYMENT ENDPOINT HERE'
ENDPOINT_NAME = 'predict-loan-default'
CONTENT_TYPE = 'text/csv'
sagemaker = boto3.client('runtime.sagemaker')<jupyter_output><empty_output><jupyter_text>Invoke SageMaker Endpoint for Prediction<jupyter_code>def predict(features):
    response = sagemaker.invoke_endpoint(EndpointName=ENDPOINT_NAME, 
                                         ContentType=CONTENT_TYPE, 
                                         Body=features)
    body = response['Body'].read()
    prediction = body.decode('utf-8').split(',')[0]
    return prediction<jupyter_output><empty_output><jupyter_text>Test Positive case<jupyter_code>features = '5000,4975.0,36,0.2728221178925404,162.87,b,b2,verified,2011-12-01,"(15,[1],[1.0])",27.65,1985-01-01,1,3,0,83.7,9,10.0,"",rent,24000.0,"(20007,[0],[2.5966152171060037])"'
prediction = predict(features)
print(f'Prediction = {prediction}')<jupyter_output>Prediction = fully paid<jupyter_text>Test Negative case<jupyter_code>features = '5600,5600.0,60,0.8273343766301512,152.39,f,f2,source verified,2011-12-01,"(15,[5],[1.0])",5.55,2004-04-01,2,11,0,32.6,13,4.0,"",own,40000.0,"(20007,[0],[2.5966152171060037])"'
prediction = predict(features)
print(f'Prediction = {prediction}')<jupyter_output>Prediction = charged off
{'fraction_non_alphanumeric': 0.1630510846745976, 'fraction_numerical': 0.13995801259622112, 'mean_word_length': 6.15, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '320081', 'license': 'Apache-2.0', 'n_tokens_mistral': 661, 'n_tokens_neox': 547, 'n_words': 49, 'path': 'finserv/tabular/loan-default-prediction/autopilot/real-time-inference.ipynb', 'repo_name': 'arunprsh/no-code-low-code', 'size': '1429'}