This notebook assumes a deployed binary classification model that predicts the possibility for a tent purchase based on age, sex, marital status and job profession for an individual. To create the model, follow these steps:
To run the code samples in this notebook, you must supply information, such as the apikey, and deployment ID for the scoring endpoint. The details on how to do this are described in the following steps:
After updating the first two code cells with your information, run those cells.
# Add API credentials to access your Watson Machine Learning service instance
wml_credentials={
"url": "https://us-south.ml.cloud.ibm.com",
"apikey": "insert_your_apikey_here",
}
# Add the deployment ID from your model deployment from the scoring endpoint
scoring_endpoint = 'insert_your_deployment_ID_here'
# Import the installed WML API client from the ibm_watson_machine_learning python package
from ibm_watson_machine_learning import APIClient
# Create API client
client = APIClient(wml_credentials)
# Set the deployment space
client.set.default_space('insert_your_deployment_space_ID_here')
The result should show that the prediction is TRUE for a Male, 20-year-old, Single, Professional, who previously purchased camping equipment in the amount of $144.78 to buy a tent, and the probability of that event is very high.
# Call the scoring endpoint with some initial sample data and output the prediction and probability
payload_scoring = {"input_data":[{"fields":["GENDER","AGE","MARITAL_STATUS","PROFESSION","PRODUCT_LINE","PURCHASE_AMOUNT"],"values":[["M",20,"Single","Professional","Camping Equipment",144.78]]}]}
client.deployments.score( scoring_endpoint, payload_scoring )
© Copyright 2024 IBM Corporation.