Model builder tutorial: Build a machine learning model to recognize handwritten digits using the MNIST data set

This tutorial guides you through using the MNIST computer vision data set to train a model to recognize handwritten digits. In this tutorial, you will train a sample model using the model builder in IBM Watson Studio, and then deploy and test the model in Watson Studio.

 

Prerequisite

  • Create a new project or open an existing one.

 

Steps overview

This tutorial presents the basic steps for building and training a machine learning model using model builder in Watson Studio:

  1. Train a sample model
  2. Deploy the trained model
  3. Test the deployed model

 

Step 1: Train a sample model in model builder in Watson Studio

The model builder in Watson Studio guides you, step by step, through creating machine learning models:

  • Uploading training data
  • Selecting machine learning techniques and estimators from a list that is recommended based on properties of your training data
  • Training the model to fit the training data

The model builder also has built-in samples that you can build without having to choose the algorithms yourself.

This tutorial uses one of the built-in samples:

  1. From the Assets page of your project in Watson Studio, in the Models section, click New model.

  2. In the page that opens, fill in the basic fields:

    • Specify a name for your new model.
    • Confirm that the IBM Watson Machine Learning service instance that you associated with your project is selected in the Machine Learning Service section.

  3. Click the radio button labeled From sample.

  4. Scroll down to find the card titled "Handwritten Digits Recognition", and then click that card to select it.

  5. Click Create

After you click Create in the model builder, training takes very little time. When training is complete, the model details page opens automatically.

 

Step 2: Deploy the trained model

You can deploy the model from the model details page:

  1. Click the Deployments tab.

  2. Click Add Deployment.

  3. In the page that opens, fill in the fields:

    • Specify a name for the deployment.
    • Select "Web service" as the Deployment type.

  4. Click Save.

After you save the deployment, click on the deployment name to view the deployment details page.

 

Step 3: Test the deployed model

You can test the deployed model from the deployment details page:

  1. Download this sample test file: mnist-scikit-learn-test-payload.json external link.

    That test image is for the digit "5" and looks like this:
    Image of handwritten digit 5

  2. In the Test area of the deployment details page in Watson Studio, paste the contents of mnist-scikit-learn-test-payload.json:

    {
      "fields" : [ "f0", "f1", "f2", ...
      "values" : [ [ 0.0, 5.0, 12.0, ...
    }
    

  3. Click Predict.

    The results will look something like this:

    {
      "fields": [
        "prediction"
      ],
      "values": [
        [
          5
        ]
      ]
    }
    

    The values field contains the digit class ("0" through "9") that the model has classified the test data into. The expected digit class is "5".