Step 7: Sample Python code for prediction and stability requests

Minitab Model Ops accepts various source code for prediction and stability requests.

For more information on generating the required code format, go to Data integration. The sections below are examples of code for the HeartBinary model. You must use your API key.

Sample Python code for a prediction request

Use this format to create a prediction request. You must enter your API key for key_secret.
import requests

key_secret = "ENTER.YOUR.API.KEY"
headers = {"ApiKey": key_secret, "Content-Type": "application/json"}

payload = {'Age': ['1.23'], 'Rest Blood Pressure': ['1.23'], 'Cholesterol': ['1.23'], 'Max Heart Rate': ['1.23'], 'Old Peak': ['1.23'], 'Sex': ['Male'], 'Fasting Blood Sugar': ['False'],
           'Exercise Angina': ['No'], 'Rest ECG': ['0'], 'Slope': ['1'], 'Thal': ['Normal'], 'Chest Pain Type': ['1'], 'Major Vessels': ['0'], 'ObservationID': ['003a']}

url = "https://modelops.minitab.com/api/score"

r = requests.post(url, json=payload, headers=headers)


print('Request URL: ', r.url)

print('Response Code:', r.status_code)
print('Response Headers:\n', r.headers)
print('Response Content:\n', r.text)
Note

All sample code uses a period as the decimal separator for numeric values. For files, you can specify a regional setting if your data have commas as separators. For more information, go to Region headers with files.

Sample Python code for a stability request

Use this format to create a stability request. You must enter your API key for key_secret.
import requests

key_secret = "ENTER.YOUR.API.KEY"
headers = {"ApiKey": key_secret, "Content-Type": "application/json"}
payload = {'ObservationID':['003a'], 'Heart Disease':['No']}

url = "https://modelops.minitab.com/api/stability"

r = requests.post(url, json=payload, headers=headers)


print('Request URL: ', r.url)

print('Response Code:', r.status_code)
print('Response Headers:\n', r.headers)
print('Response Content:\n', r.text)
Note

All sample code uses a period as the decimal separator for numeric values. For files, you can specify a regional setting if your data have commas as separators. For more information, go to Region headers with files.