# Quick start: Build and deploy a machine learning model in a Jupyter notebook #

You can create, train, and deploy machine learning models with Watson Machine Learning in a Jupyter notebook\. Read about the Jupyter notebooks, then watch a video and take a tutorial that’s suitable for intermediate users and requires coding\.

**Required services** : Watson Studio : Watson Machine Learning

Your basic workflow includes these tasks:

<!-- <ol> -->

1.  Open your sandbox project\. Projects are where you can collaborate with others to work with data\.
2.  Add a notebook to the project\. You can create a blank notebook or import a notebook from a file or GitHub repository\.
3.  Add code and run the notebook\.
4.  Review the model pipelines and save the desired pipeline as a model\.
5.  Deploy and test your model\.

<!-- </ol> -->

## Read about Jupyter notebooks ##

A Jupyter notebook is a web\-based environment for interactive computing\. If you choose to build a machine learning model in a notebook, you should be comfortable with coding in a Jupyter notebook\. You can run small pieces of code that process your data, and then immediately view the results of your computation\. Using this tool, you can assemble, test, and run all of the building blocks you need to work with data, save the data to Watson Machine Learning, and deploy the model\.

[Read more about training models in notebooks](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/ml-samples-overview.html)

[Learn about other ways to build models](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/data-science.html)

## Watch a video about creating a model in a Jupyter notebook ##

![Watch Video](https://dataplatform.cloud.ibm.com/docs/content/wsj/getting-started/images/lc-video.png) Watch this video to see how to train, deploy, and test a machine learning model in a Jupyter notebook\.

This video provides a visual method to learn the concepts and tasks in this documentation\.

## Try a tutorial to create a model in a Jupyter notebook ##

In this tutorial, you will complete these tasks:

<!-- <ul> -->

 *  [Task 1: Open a project\.](https://dataplatform.cloud.ibm.com/docs/content/wsj/getting-started/get-started-build-notebook.html?context=cdpaas&locale=en#step01)
 *  [Task 2: Add a notebook to your project\.](https://dataplatform.cloud.ibm.com/docs/content/wsj/getting-started/get-started-build-notebook.html?context=cdpaas&locale=en#step02)
 *  [Task 3: Set up the environment\.](https://dataplatform.cloud.ibm.com/docs/content/wsj/getting-started/get-started-build-notebook.html?context=cdpaas&locale=en#step03)
 *  [Task 4: Run the notebook:](https://dataplatform.cloud.ibm.com/docs/content/wsj/getting-started/get-started-build-notebook.html?context=cdpaas&locale=en#step04)
    
    <!-- <ul> -->
    
     *  Build and train a model.
     *  Save a pipeline as a model.
     *  Deploy the model.
     *  Test the deployed model.
    
    <!-- </ul> -->
    
 *  [Task 5: View and test the deployed model in the deployment space\.](https://dataplatform.cloud.ibm.com/docs/content/wsj/getting-started/get-started-build-notebook.html?context=cdpaas&locale=en#step05)

<!-- </ul> -->

<!-- <ul> -->

 *  [(Optional) Clean up\.](https://dataplatform.cloud.ibm.com/docs/content/wsj/getting-started/get-started-build-notebook.html?context=cdpaas&locale=en#step06)

<!-- </ul> -->

This tutorial will take approximately 30 minutes to complete\.

### Sample data ###

The sample data used in this tutorial is from data that is part of **scikit\-learn** and will be used to train a model to recognize images of hand\-written digits, from 0\-9\.

Expand all sections

<!-- <ul> -->

 *  Tips for completing this tutorial
    
    \#\#\# Use the video picture-in-picture Tip: Start the video, then as you scroll through the tutorial, the video moves to picture-in-picture mode. Close the video table of contents for the best experience with picture-in-picture. You can use picture-in-picture mode so you can follow the video as you complete the tasks in this tutorial. Click the timestamps for each task to follow along.The following animated image shows how to use the video picture-in-picture and table of contents features: ![How to use picture-in-picture and chapters](https://dataplatform.cloud.ibm.com/docs/content/wsj/getting-started/images/pip-and-chapters.gif)\{: width="560px" height="315px" data-tearsheet="this"\} \#\#\# Get help in the community If you need help with this tutorial, you can ask a question or find an answer in the [Cloud Pak for Data Community discussion forum](https://community.ibm.com/community/user/cloudpakfordata/communities/community-home/digestviewer?communitykey=c0c16ff2-10ef-4b50-ae4c-57d769937235)\{: new\_window\}. \#\#\# Set up your browser windows For the optimal experience completing this tutorial, open Cloud Pak for Data in one browser window, and keep this tutorial page open in another browser window to switch easily between the two applications. Consider arranging the two browser windows side-by-side to make it easier to follow along. ![Side-by-side tutorial and UI](https://dataplatform.cloud.ibm.com/docs/content/wsj/getting-started/images/tutorial-side-by-side.png)\{: width="560px" height="315px" data-tearsheet="this"\} Tip: If you encounter a guided tour while completing this tutorial in the user interface, click **Maybe later**.  
    [Back to the top](https://dataplatform.cloud.ibm.com/docs/content/wsj/getting-started/get-started-build-notebook.html?context=cdpaas&locale=en#video-preview)  
    
<!-- </ul> -->

<!-- <ul> -->

 *  Task 1: Open a project
    
    You need a project to store the data and the AutoAI experiment. You can use your sandbox project or create a project. 1. From the navigation menu ![Navigation menu](https://dataplatform.cloud.ibm.com/docs/content/wsj/getting-started/images/navigation-menu.svg)\{: iih\}, choose **Projects > View all projects** 1. Open your sandbox project. If you want to use a new project: 1. Click **New project**. 1. Select **Create an empty project**. 1. Enter a name and optional description for the project. 1. Choose an existing [object storage service instance](https://dataplatform.cloud.ibm.com/docs/content/wsj/admin/storage-options.html)\{: new\_window\} or create a new one. 1. Click **Create**. 1. When the project opens, click the **Manage** tab and select the **Services and integrations** page. ![preview tutorial video](https://dataplatform.cloud.ibm.com/docs/content/wsj/getting-started/images/lc-video.png) To preview this task, watch the video beginning at 00:07. 1. On the *IBM services* tab, click **Associate service**. 1. Select your Watson Machine Learning instance. If you don't have a Watson Machine Learning service instance provisioned yet, follow these steps: 1. Click **New service**. 1. Select **Watson Machine Learning**. 1. Click **Create**. 1. Select the new service instance from the list. 1. Click **Associate service**. 1. If necessary, click **Cancel** to return to the *Services & Integrations* page. For more information or to watch a video, see [Creating a project](https://dataplatform.cloud.ibm.com/docs/content/wsj/getting-started/projects.html)\{: new\_window\}.  
    For more information on associated services, see [Adding associated services](https://dataplatform.cloud.ibm.com/docs/content/wsj/getting-started/assoc-services.html)\{: new\_window\}. \#\#\# ![Checkpoint icon](https://dataplatform.cloud.ibm.com/docs/content/wsj/getting-started/images/checkmark--filled-blue.svg)\{: iih\} Check your progress The following image shows the new project.  
      
    ![The following image shows the new project.](https://dataplatform.cloud.ibm.com/docs/content/wsj/getting-started/images/notebook-new-project.png)\{: width="100%" \}  
    [Back to the top](https://dataplatform.cloud.ibm.com/docs/content/wsj/getting-started/get-started-build-notebook.html?context=cdpaas&locale=en#video-preview)  
    
<!-- </ul> -->

<!-- <ul> -->

 *  Task 2: Add a notebook to your project
    
    ![preview tutorial video](https://dataplatform.cloud.ibm.com/docs/content/wsj/getting-started/images/lc-video.png) To preview this task, watch the video beginning at 00:18. You will use a sample notebook in this tutorial. Follow these steps to add the sample notebook to your project: 1. Access the [Use sckit-learn to recognize hand-written digits notebook](https://dataplatform.cloud.ibm.com/exchange/public/entry/view/e20607d75c8473daaade1e77c21717d4)\{: new\_window\} in the *Samples*. 1. Click **Add to project**. 1. Select the project from the list, and click **Add**. 1. Verify the notebook name and description (optional). 1. Select a runtime environment for this notebook. 1. Click **Create**. Wait for the notebook editor to load. 1. From the menu, click **Kernel > Restart & Clear Output**, then confirm by clicking **Restart and Clear All Outputs** to clear the output from the last saved run. \#\#\# ![Checkpoint icon](https://dataplatform.cloud.ibm.com/docs/content/wsj/getting-started/images/checkmark--filled-blue.svg)\{: iih\} Check your progress The following image shows the new notebook.  
      
    ![The following image shows the new notebook.](https://dataplatform.cloud.ibm.com/docs/content/wsj/getting-started/images/notebook-new-notebook.png)\{: width="100%" \}  
    [Back to the top](https://dataplatform.cloud.ibm.com/docs/content/wsj/getting-started/get-started-build-notebook.html?context=cdpaas&locale=en#video-preview)  
    
<!-- </ul> -->

<!-- <ul> -->

 *  Task 3: Set up the environment
    
    ![preview tutorial video](https://dataplatform.cloud.ibm.com/docs/content/wsj/getting-started/images/lc-video.png) To preview this task, watch the video beginning at 00:44. The first section in the notebook sets up the environment by specifying your IBM Cloud credentials and Watson Machine Learning service instance location. Follow these steps to set up the environment in your notebook: 1. Scroll to the *Set up the environment* section. 1. Choose a method to obtain the API key and location. - Run the IBM Cloud CLI commands in the notebook from a command prompt. - Use the IBM Cloud console. 1. Launch the [API keys section in the IBM Cloud Console](https://cloud.ibm.com/iam/apikeys)\{: new\_window\}, and [create an API key](https://cloud.ibm.com/docs/account?topic=account-userapikey&interface=ui#create_user_key)\{: new\_window\}. 1. Access your [IBM Cloud resource list](https://cloud.ibm.com/resources)\{: new\_window\}, view your Watson Machine Learning service instance, and note the *Location*. 1. See the Watson Machine Learning [API Docs](https://cloud.ibm.com/apidocs/machine-learning)\{: new\_window\} for the correct endpoint URL. For example, Dallas is in us-south. 1. Paste your API key and location into cell 1. 1. Run cells 1 and 2. 1. Run cell 3 to install the `ibm-watson-machine-learning` package. 1. Run cell 4 to import the API client and create the API client instance using your credentials. 1. Run cell 5 to see a list of all existing deployment spaces. If you do not have a deployment space, then follow these steps: 1. Open another tab with your watsonx deployment. 1. From the navigation menu ![Navigation menu](https://dataplatform.cloud.ibm.com/docs/content/wsj/getting-started/images/navigation-menu.svg)\{: iih\}, click **Deployments**. 1. Click **New deployment space**. 1. Add a name and optional description for the deployment. 1. Click **Create**, then **View new space**. 1. Click the **Manage** tab. 1. Copy the **Space GUID** and close the tab, this value will be your `space_id`. 1. Copy and paste the appropriate deployment space ID into cell 6, then run cell 6 and cell 7 to set the default space. \#\#\# ![Checkpoint icon](https://dataplatform.cloud.ibm.com/docs/content/wsj/getting-started/images/checkmark--filled-blue.svg)\{: iih\} Check your progress The following image shows the notebook with all of the environment variables set up.  
      
    ![The following image shows the notebook with all of the environment variables set up.](https://dataplatform.cloud.ibm.com/docs/content/wsj/getting-started/images/notebook-cell07.png)\{: width="100%" \}  
    [Back to the top](https://dataplatform.cloud.ibm.com/docs/content/wsj/getting-started/get-started-build-notebook.html?context=cdpaas&locale=en#video-preview)  
    
<!-- </ul> -->

<!-- <ul> -->

 *  Task 4: Run the notebook
    
    ![preview tutorial video](https://dataplatform.cloud.ibm.com/docs/content/wsj/getting-started/images/lc-video.png) To preview this task, watch the video beginning at 02:14. Now that all of the environment variables are set up, you can run the rest of the cells in the notebook. Follow these steps to read through the comments, run the cells, and review the output: 1. Run the cells in the *Explore data* section. 1. Run the cells in the *Create a scikit-learn model* section to. 1. Prepare the data by splitting it into three data sets (train, test, and score). 1. Create the pipeline. 1. Train the model. 1. Evaluate the model using the test data. 1. Run the cells in the *Publish model* section to publish the model, get model details, and get all models. 1. Run the cells in the *Create model deployment* section. 1. Run the cells in the *Get deployment details* section. 1. Run the cells in the *Score* section*, which sends a scoring request to the deployed model and shows the prediction. 1. Click \*File > Save* to save the notebook and its output. \#\#\# ![Checkpoint icon](https://dataplatform.cloud.ibm.com/docs/content/wsj/getting-started/images/checkmark--filled-blue.svg)\{: iih\} Check your progress The following image shows the notebook with the prediction.  
      
    ![The following image shows the notebook with the prediction.](https://dataplatform.cloud.ibm.com/docs/content/wsj/getting-started/images/notebook-prediction.png)\{: width="100%" \}  
    [Back to the top](https://dataplatform.cloud.ibm.com/docs/content/wsj/getting-started/get-started-build-notebook.html?context=cdpaas&locale=en#video-preview)  
    
<!-- </ul> -->

<!-- <ul> -->

 *  Task 5: View and test the deployed model in the deployment space
    
    ![preview tutorial video](https://dataplatform.cloud.ibm.com/docs/content/wsj/getting-started/images/lc-video.png) To preview this task, watch the video beginning at 04:07. You can also view the model deployment directly from the deployment space. Follow these steps to test the deployed model in the space. 1. From the navigation menu ![Navigation menu](https://dataplatform.cloud.ibm.com/docs/content/wsj/getting-started/images/navigation-menu.svg)\{: iih\}, click **Deployments**. 1. Click the **Spaces** tab. 1. Select the appropriate deployment space from the list. 1. Click **Scikit model**. 1. Click **Deployment of scikit model**. 1. Review the *Endpoint* and *Code snippets*. 1. Click the **Test** tab. You can test the deployed model by pasting the following JSON code: `json {"input_data": [{"values": 0.0, 0.0, 5.0, 16.0, 16.0, 3.0, 0.0, 0.0, 0.0, 0.0, 9.0, 16.0, 7.0, 0.0, 0.0, 0.0, 0.0, 0.0, 12.0, 15.0, 2.0, 0.0, 0.0, 0.0, 0.0, 1.0, 15.0, 16.0, 15.0, 4.0, 0.0, 0.0, 0.0, 0.0, 9.0, 13.0, 16.0, 9.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 14.0, 12.0, 0.0, 0.0, 0.0, 0.0, 5.0, 12.0, 16.0, 8.0, 0.0, 0.0, 0.0, 0.0, 3.0, 15.0, 15.0, 1.0, 0.0, 0.0], 0.0, 0.0, 6.0, 16.0, 12.0, 1.0, 0.0, 0.0, 0.0, 0.0, 5.0, 16.0, 13.0, 10.0, 0.0, 0.0, 0.0, 0.0, 0.0, 5.0, 5.0, 15.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 8.0, 15.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 13.0, 13.0, 0.0, 0.0, 0.0, 0.0, 0.0, 6.0, 16.0, 9.0, 4.0, 1.0, 0.0, 0.0, 3.0, 16.0, 16.0, 16.0, 16.0, 10.0, 0.0, 0.0, 5.0, 16.0, 11.0, 9.0, 6.0, 2.0]]}]}` 1. Click **Predict**. The resulting prediction indicates that the hand-written digits are 5 and 4. \#\#\# ![Checkpoint icon](https://dataplatform.cloud.ibm.com/docs/content/wsj/getting-started/images/checkmark--filled-blue.svg)\{: iih\} Check your progress The following image shows the *Test* tab with the prediction.  
      
    ![The following image shows the \*Test\* tab with the prediction.](https://dataplatform.cloud.ibm.com/docs/content/wsj/getting-started/images/notebook-test-tab.png)\{: width="100%" \}  
    [Back to the top](https://dataplatform.cloud.ibm.com/docs/content/wsj/getting-started/get-started-build-notebook.html?context=cdpaas&locale=en#video-preview)  
    
<!-- </ul> -->

<!-- <ul> -->

 *  (Optional) Task 6: Clean up
    
    If you'd like to remove all of the assets created by the notebook, create a new notebook based on the [Machine Learning artifacts management notebook](https://github.com/IBM/watson-machine-learning-samples/blob/master/cloud/notebooks/python_sdk/instance-management/Machine%20Learning%20artifacts%20management.ipynb)\{: new\_window\}. A link to this notebook is also available in the **Clean up** section of the *Use scikit-learn to recognize hand-written digits notebook* used in this tutorial.  
    [Back to the top](https://dataplatform.cloud.ibm.com/docs/content/wsj/getting-started/get-started-build-notebook.html?context=cdpaas&locale=en#video-preview)  
    
<!-- </ul> -->

## Next steps ##

Now you can use this data set for further analysis\. For example, you or other users can do any of these tasks:

<!-- <ul> -->

 *  [Cleansing and shaping data](https://dataplatform.cloud.ibm.com/docs/content/wsj/getting-started/get-started-refine.html)
 *  [Analyze the data in a notebook](https://dataplatform.cloud.ibm.com/docs/content/wsj/getting-started/get-started-analyze.html)

<!-- </ul> -->

## Additional resources ##

<!-- <ul> -->

 *  Try these other methods to build models:
    
    <!-- <ul> -->
    
     *  [Build and deploy a machine learning model with AutoAI](https://dataplatform.cloud.ibm.com/docs/content/wsj/getting-started/get-started-build.html)
     *  [Build and deploy a machine learning model with SPSS Modeler](https://dataplatform.cloud.ibm.com/docs/content/wsj/getting-started/get-started-build-spss.html)
     *  [Build and deploy a Decision Optimization model](https://dataplatform.cloud.ibm.com/docs/content/wsj/getting-started/get-started-do.html)
    
    <!-- </ul> -->
    
 *  View more [videos](https://dataplatform.cloud.ibm.com/docs/content/wsj/getting-started/videos-wx.html)\.
 *  Find sample data sets, projects, models, prompts, and notebooks in the Samples to gain hands\-on experience:
    
    ![Notebook icon](https://dataplatform.cloud.ibm.com/docs/content/wsj/getting-started/images/notebook.svg)[Notebooks](https://dataplatform.cloud.ibm.com/gallery?context=wx&format=notebook) that you can add to your project to get started analyzing data and building models.
    
    ![Project icon](https://dataplatform.cloud.ibm.com/docs/content/wsj/getting-started/images/ibm-cloud--projects.svg)[Projects](https://dataplatform.cloud.ibm.com/gallery?context=wx&format=project-template) that you can import containing notebooks, data sets, prompts, and other assets.
    
    ![Data set icon](https://dataplatform.cloud.ibm.com/docs/content/wsj/getting-started/images/data--set.svg)[Data sets](https://dataplatform.cloud.ibm.com/gallery?context=wx&format=dataset) that you can add to your project to refine, analyze, and build models.
    
    ![Prompt icon](https://dataplatform.cloud.ibm.com/docs/content/wsj/getting-started/images/prompt.svg)[Prompts](https://dataplatform.cloud.ibm.com/gallery?context=wx&format=example-prompt) that you can use in the Prompt Lab to prompt a foundation model.
    
    ![Model icon](https://dataplatform.cloud.ibm.com/docs/content/wsj/getting-started/images/model.svg)[Foundation models](https://dataplatform.cloud.ibm.com/gallery?context=wx&format=foundation-model) that you can use in the Prompt Lab.
 *  Find more [Python client samples and examples](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/ml-samples-overview.html)\.

<!-- </ul> -->

**Parent topic:**[Quick start tutorials](https://dataplatform.cloud.ibm.com/docs/content/wsj/getting-started/quickstart-tutorials.html)

<!-- </article "role="article" "> -->