Make an inference Stay organized with collections Save and categorize content based on your preferences.
df_for_prediction to make an inferencerequest. The inference request invokes your model to predict what species ofpenguin is represented by the penguin characteristics in each row indf_for_prediction.Prepare inference test data
Before you can use the test data to create inferences, you remove thespeciescolumn. Because the species of penguin is what you're predicting, it can't beincluded in the test data used to create an inference. After you remove thespecies column, you convert the data to a Python list because that's what thepredict method takes as input. Run the following code convert your datato a Python list:
# Remove the species columndf_for_prediction.pop(LABEL_COLUMN)# Convert data to a Python listtest_data_list = df_for_prediction.values.tolist()(Optional) View test data
To help you understand the test data, you can run the following line of code toview it:
test_data_listIn each row, the respective values in each of the six columns refer to the followingcharacteristics of one penguin:
| Column | Penguin characteristic |
|---|---|
| 0 | island - The island where a species of penguin is found. The island value mapping is0 forDream,1 forBiscoe, and2 forTorgersen. |
| 1 | culmen_length_mm - The length of the ridge along the top of the bill of a penguin. |
| 2 | culmen_depth_mm - The height of the bill of a penguin. |
| 3 | flipper_length_mm - The length of the flipper-like wing of a penguin. |
| 4 | body_mass_g - The mass of the body of a pen. |
| 5 | sex - The sex of the penguin.0 isFEMALE and1 isMALE. |
Send the inference request
To create an inference request, pass the Python list of test data you created totheendpoint'spredict method.
Thepredict method evaluates the characteristics in each row and uses them topredict what kind of penguin they represent. Run the following code to createyour inferences. The returned inferences contain a list of rows, where eachrow has three columns (Adelie Penguin (Pygoscelis adeliae) (column 1),Chinstrap penguin (Pygoscelis antarctica) (column 2), orGentoo penguin(Pygoscelis papua) (column 3)).
# Get your inferences.predictions = endpoint.predict(instances=test_data_list)# View the inferencespredictions.predictionsEach column in a row contains a value, and the higher the value, the greater theconfidence that the species of the penguin represented by that column is acorrect inference. For example, in the following sample inference output row,the model uses the characteristics of the sample penguin data row to predictthat the penguin is most likely of theAdelie Penguin (Pygoscelis adeliae)species. This is because the highest value,0.732703805, is in the firstcolumn.
[0.732703805, 0.233752429, 0.0335437432]
In the following code, the NumPyargmax method returns the column for each rowthat contains the highest value. The highest value corresponds to the inferencethat is most likely correct. The second line displays the array of inferences.
# Get the inference for each set of input data.species_predictions = np.argmax(predictions.predictions, axis=1)# View the best inference for the penguin characteristics in each row.species_predictionsEach result in thespecies_predictions array predicts which penguin speciesthe values in the corresponding row of test data corresponds to. For example,the first value is0, which maps to theAdelie Penguin (Pygoscelis adeliae)species. This means that your model predicts that the species of a penguin withthe characteristics in the first row of your test data isAdelie Penguin(Pygoscelis adeliae).
Clean up resources
Now that you're done, you can continue to use your notebook to explore and learnmore about the resources you created and how they work.
Delete your resources
When you're ready, we recommend that you delete the Google Cloud resources youcreated during this tutorial so that you don't incur unnecessary charges. Thereare two ways to delete your resources:
Delete your project, which also deletes all the resources associated with yourproject. For more information, seeShutting down (deleting)projects.
Run code that deletes your training job (a
CustomTrainingJobobject), model(aModelobject), endpoint (anEndpointobject), and Cloud Storagebucket. This option retains your project and any other resources you mighthave created that you don't explicitly delete with your code.You must undeploy your model before you can delete it by passing
force=Trueto theendpoint.deletemethod.To retain your project and delete only resources you created during thistutorial, run the following code in your notebook:
importos# Delete the training jobjob.delete()# Delete the endpoint and undeploy the model from itendpoint.delete(force=True)# Delete the modelmodel.delete()# Delete the storage bucket and its contentsbucket.delete(force=True)Delete your Vertex AI Workbench instance
You can keep your Vertex AI Workbench instance to use for futurework. If you keep it, make sure you are aware of its cost. For moreinformation, seeVertex AI Workbenchpricing.
If you want to delete the Vertex AI Workbench instance,do the following:
In the Google Cloud console, go to theVertex AI WorkbenchInstances page.
Select your Vertex AI Workbench instance.
In the upper menu, click Delete.
In theDelete instance confirmation dialog, clickConfirm. It takesa few minutes for the deletion to complete.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-12-15 UTC.