Machine Learning for the Lazy Engineer – Vertex AI

Test from the console


Using the same dataset and problem that I was trying to solve in Machine Learning for the Lazy Engineer – BigQuery, I am going to show you how to come up with a solution using Vertex AI. I suggest you read through the previous post to get the context.


Quoting the heading from the product page for Vertex AI:

Build, deploy, and scale machine learning (ML) models faster, with fully managed ML tools for any use case.

I am going one step further with this solution by exposing an HTTPS endpoint (online prediction) that can accept a message and predict if the message as either Ham or Spam.


  1. Create a Dataset
    From the Vertex AI service page, select Create Dataset option and then select Text data type:

    Create Vertex AI Dataset Step 1

  2. Import data into the Dataset
    Use the same Dataset as was used previously. But, swap the columns so that the message is in the first column and remove the first row (header). Then upload it into a GCS bucket. One uploaded, selected the previously selected dataset and click import:

    Import comments

    You will receive an email once the import is complete. Once the import is complete, you should see something like this:

    Vertex AI imported dataset.
  3. Train the model

    Click on the “TRAIN NEW MODEL” button in the above screenshot, you should see a screen like this:

    Train the new model
  4. Expose an Endpoint for prediction

    The model training took more than 4 hours for me. Once the model is trained you will receive an email.

    Then select Online Prediction and then create an endpoint as shown in the two screenshots below:

    Expose model endpoint step 1

    Expose model endpoint step 2

    The endpoint can be tested using REST API, SDKs or you can test it from the console, as shown in the screenshots below. The bottom screenshot shows the probabilities of the message being Spam and Ham while testing from the console.

    Call the endpoint using REST API
    Test from the console
  5. Conclusion
    It is pretty easy to train and deploy a model in Vertex AI. I noticed that predictions were much quicker (sub 300ms) than when using BigQuery. But, this solution costs a bit more (around $10 for 6 hours compared to little to nothing when using BigQuery). I encourage you to give this a try, but, please delete the endpoint after you have no use for it (to save money):

    vertex ai undeploy model

    vertex ai delete endpoint

Leave a Reply

Your email address will not be published. Required fields are marked *