Request a prediction from a hosted model
You may ask the model for predictions by sending them to an endpoint inside your project, which will submit the request to the hosted model and return the results. You may use this as practice by sending a prediction to the AutoML Proxy, which is quite similar to how you would interact with the model you just generated.
Step10 – Creating AutoML proxy endpoint
Get the name of the AutoML proxy endpoint
- In the Google Cloud Console, navigate to the left panel, locate and click Cloud Run.
- Click automl-proxy.
Step 11: – Using AutoML proxy URL for prediction
- Copy the URL to the endpoint. It should look something like: https://automl-proxy-xfpm6c62ta-uc.a.run.app.
This endpoint is essential for making prediction request later on.
Create a prediction request
You may use the Google Cloud interface, the Vertex AI API, or the Vertex SDK for Python to obtain real-time or batch predictions from your endpoint. Here, I’ll demonstrate how to use the GCP console to obtain forecasts.
Step 12 – Making Prediction
- Open a new Cloud Shell window.
- After its open, navigate to Cloud Shell toolbar and click on editor.
- Click File > New File.
- In the new file, paste the below mentioned helper code:
{
“instances”: [
{ “Age”: “39.0”, “Job”: “blue-collar”, “MaritalStatus”: “married”, “Education”: “secondary”, “Default”: “no”, “Balance”: “455”, “Housing”: “yes”, “Loan”: “no”, “Contact”: “cellular”, “Day”: “16.0”, “Month”: “May”, “Duration”: “180.0”, “Campaign”: “2.0”, “PDays”: “-1.0”, “Previous”: “0.0”, “POutcome”: “unknown”}
]
}
- Save the file and name it payload.json. It is the query that we used for prediction and to get results from our model.
(Note: In case you are unable to save the file, take help of Nano or similar editors to create the file.)
Step 13 – initializing environment variables
- Next, set the following environment variables. Your AUTOML_PROXY should look something like:
"https://automl-proxy-xfpm6c62ta-uc.a.run.app/v1"
AUTOML_PROXY=<automl-proxy url>/v1
INPUT_DATA_FILE=payload.json
(Note: Adding /v1 at the end of your proxy URL is essential to avoid any future issues. Make sure that you have done this before continuing.)
Step 14 – API request for prediction
- Next step is to perform an API request to the AutoML Proxy endpoint. That API request will assign another request for prediction from the hosted model:
curl -X POST -H “Content-Type: application/json” $AUTOML_PROXY -d “@${INPUT_DATA_FILE}”
If you run a successful prediction, your output should resemble the following:
A forecast result of 1 indicates a failure in this model—a bank deposit is not made. A deposit is made at the bank when the forecast result is 2, which is a favorable outcome.
You can see from the forecast that it gave that it would anticipate a negative result (1) with 99% accuracy and a positive outcome (2) with 0.01% accuracy based on the tabular data it was provided.
Modify the JSON file you produced’s values. Consider raising the time to a much higher amount, such as 1000.0, and observe how the model forecast changes. Rerun the command for the prediction request.
Your output might resemble the following:
{“predictions”:[{“scores”:[0.3821603059768677,0.6178396940231323],”classes”:[“1″,”2″]}],”deployedModelId”:”8716862214310461440″,”model”:”projects/1030115194620/locations/us-central1/models/3627073355753979904″,”modelDisplayName”:”Structured_AutoML_Tutorial”}
You can make changes to your model by playing around with the data and then notice how differently the features are weighted within the model.
Vertex AI for AutoML users
The whole machine-learning process, from the preparation of the data through the model deployment, is automated using the AutoML technique. For users with various degrees of expertise and resources, it aims to make machine learning simpler and more efficient. Using diverse methods, such as AutoML or custom code training, and a variety of data types, such as photos, texts, or tables, you may develop and compare models using AutoML. AutoML may also assist you in tracking and explaining the behaviour and performance of your models.
Table of Content
- What is AutoML?
- What is Vertex AI?
- Vertex AI for AutoML users
- What are the benefits of Vertex AI for AutoML users?
- How to use Vertex AI for AutoML?
- Train an AutoML classification model
- Request a prediction from a hosted model
- Conclusion