Task 3: Score H2O Driverless AI model
Score model
Once the deployed model reaches a Healthy, you can start scoring the model (also known as "inference" or "prediction"). Let's score the deployed model.
The core of scoring a deployed model involves using the endpoint URL associated with it. An endpoint URL is a specific web address that allows you to send requests to the deployed model and receive predictions or other responses.
- In the Deployments table, click model-to-h2o-mlops.
For example, with the endpoint URL, you can score the deployed model using a cURL request or a Python script. Let's explore both example options. Let's predict the following cardholder profile and let's explore whether it will default on its next payment:
Cardholder: This cardholder is a young, married female with a university education and a credit limit of 20,000. She has recently faced some payment difficulties, falling two months behind in September and August. However, she made payments on time or early in the months prior. Her recent bill amounts have decreased, and she has made minimal payments in the past few months.
cURL request
- Click Show Sample cURL Request.
- Click Copy (this copies the sample cURL request with the endpoint URL for the deployed model).
- Click Close.
- Once copied, modify the rows in the copied sample cURL request using the following values in your preferred text editor to represent the cardholder for whom we want to make a prediction:
[
"20000",
"2",
"2",
"1",
"20",
"2",
"2",
"-1",
"-1",
"-2",
"-2",
"3913",
"3100",
"689",
"0",
"0",
"0",
"0",
"689",
"0",
"0",
"0",
"0"
] - Enter the edited sample cURL request into any terminal or command line interface.
Response: {"id":"61f4cbba-63fb-11ef-a5c9-4e2deba1b09a","fields":["default payment next month.0","default payment next month.1"],"score":[["0.2999744552406185","0.7000255447593815"]]}
Python script
Create a Python script (for example, scoring.py).
Create a Python environemnt with the opencv-python and requests packages.
python3 -m venv venv
source venv/bin/activate
pip install opencv-python
pip install requests
Paste the following inside the scoring.py script (the Python code has already been modified to reflect the cardholder profile that we want to predict):
scoring.pyimport base64
import json
import cv2
import requests
URL = "endpoint_url"
data = {
"fields": [
"LIMIT_BAL", # Credit limit balance
"SEX", # Gender (1 = male; 2 = female)
"EDUCATION", # Education (1 = graduate school; 2 = university; 3 = high school; 4 = others)
"MARRIAGE", # Marital status (1 = married; 2 = single; 3 = others)
"AGE", # Age
"PAY_1", # Repayment status in September (The repayment status is categorized on a scale where -1 indicates payment made duly, and values from 1 to 9 indicate payment delays of one month up to nine months or more.)
"PAY_2", # Repayment status in August
"PAY_3", # Repayment status in July
"PAY_4", # Repayment status in June
"PAY_5", # Repayment status in May
"PAY_6", # Repayment status in April
"BILL_AMT1", # Bill statement amount in September
"BILL_AMT2", # Bill statement amount in August
"BILL_AMT3", # Bill statement amount in July
"BILL_AMT4", # Bill statement amount in June
"BILL_AMT5", # Bill statement amount in May
"BILL_AMT6", # Bill statement amount in April
"PAY_AMT1", # Previous payment amount in September
"PAY_AMT2", # Previous payment amount in August
"PAY_AMT3", # Previous payment amount in July
"PAY_AMT4", # Previous payment amount in June
"PAY_AMT5", # Previous payment amount in May
"PAY_AMT6", # Previous payment amount in April
],
"rows": [
[
"20000", # LIMIT_BAL
"2", # SEX
"2", # EDUCATION
"1", # MARRIAGE
"20", # AGE
"2", # PAY_1
"2", # PAY_2
"-1", # PAY_3
"-1", # PAY_4
"-2", # PAY_5
"-2", # PAY_6
"3913", # BILL_AMT1
"3100", # BILL_AMT2
"689", # BILL_AMT3
"0", # BILL_AMT4
"0", # BILL_AMT5
"0", # BILL_AMT6
"0", # PAY_AMT1
"689", # PAY_AMT2
"0", # PAY_AMT3
"0", # PAY_AMT4
"0", # PAY_AMT5
"0", # PAY_AMT6
]
],
}
r = requests.post(url=URL, json=data)
if r.status_code != 200:
raise ValueError(
f"Error in H2O MLOps deployment with status code: {r.status_code}."
"Please check the H2O MLOps deployment logs."
)
else:
ret = r.json()
print(ret)Click
Copy (this copies the endpoint URL of the deployed model).On line 6 of the scoring.py script, paste the copied endpoint URL of the deployed model.
Run the scoring.py script.
Response: {'id': '61f4cbba-63fb-11ef-a5c9-4e2deba1b09a', 'fields': ['default payment next month.0', 'default payment next month.1'], 'score': [['0.2999744552406185', '0.7000255447593815']]}
- Submit and view feedback for this page
- Send feedback about H2O Driverless AI | Tutorials to cloud-feedback@h2o.ai