In a previous article, I outlined the steps to POST an API call to realtime-predictions with Postman. In this article, we will look at how to do this in Python and send a file with records to predict against.
As before, we use iris.csv dataset, a common data science example. Variety is the target variable.
Steps
Upload, train and deploy the model for iris.csv. Seethis article for steps on how to deploy a model.
XGBoost Classification was the champion model which I choose to deploy.
Open the Deployed model and navigate to the Real-time predictions tab
Copy the Realtime-predictions URL to a safe place
Open a Python instance (in this case a jupyter notebook) and import the required packages.
Set the API key and API URL as string variables.
Read a local data file to a dataframe
Set the proper header, json_data, and parameter values
Get the response and print the result
In our example, we print response.text, but this could also have been saved as a file. This is a powerful option for generating prediction results locally or in a location python has access to.
Additionally, with pandas, we can send a larger amount of records (from CSV to dataframe) in one POST call rather than having manual JSON entries with Postman.
The information in this article is provided as-is and to be used at own discretion. Depending on tool(s) used, customization(s), and/or other factors ongoing support on the solution below may not be provided by Qlik Support.