Watson Machine Learning Python client samples and examples

Review and use sample notebooks that use the Watson Machine Learning Python library to demonstrate machine learning features and techniques.

The samples are built using the V4 version of the Watson Machine Learning Python client library.

Using the Watson Machine Learning Python client in a notebook:

  1. Click Add to project, and then choose Notebook.
  2. Specify a name for the notebook.
  3. Accept the default language, Python, and accept the default runtime.
  4. Click Create.
  5. Enter your credentials and import the Watson Machine Learning APIs

Watch this video to learn how to train, deploy, and test a machine learning model in a Jupyter notebook. This video mirrors the Use scikit-learn to recognize hand-written digits found in the Deployment samples following table.

This video provides a visual method as an alternative to following the written steps in this documentation.

Watch this video to learn how to test a model that was created with AutoAI using the Watson Machine Learning APIs in Jupyter notebook.

This video provides a visual method as an alternative to following the written steps in this documentation.

Using variables in a notebook

There are several pre-defined environment variables that make it easier to call the Watson Machine Learning Python client APIs.

Deployment samples

View or run these Jupyter notebooks to see how techniques are implemented using a variety of frameworks. Some of the samples rely on trained models, which are also available for you to download from the public repository.

Sample name Framework Techniques demonstrated
Use scikit-learn and custom library to predict temperature Scikit-learn Train a model with custom defined transformer
Persist the custom defined transformer and the model in Watson Machine Learning repository
Deploy the model using Watson Machine Learning Service
Perform predictions using the deployed model
Use Keras to recognize hand-written digits Keras Download an externally trained Keras model with dataset
Persist an external model in Watson Machine Learning repository
Deploy model for online scoring using client library
Score sample records using client library
Use PMML to predict iris species PMML Deploy and score a PMML model
Persist and deploy a Decision Optimization model Decision Optimization Load a DO model file into an Watson Machine Learning repository
Prepare data for training and evaluation
Create an DO machine learning job
Persist a DO model Watson Machine Learning repository
Deploy a model for batch scoring using Watson Machine Learning API
Use Python function to recognize hand-written digits Python Use a function to store a sample model then deploy it
Use scikit-learn to recognize hand-written digits Scikit-learn Train sklearn model
Persist trained model in Watson Machine Learning repository
Deploy model for online scoring using client library
Score sample records using client library
Use Spark and batch deployment to predict customer churn Spark Load a CSV file into an Apache Spark DataFrame
Explore data
Prepare data for training and evaluation
Create an Apache Spark machine learning pipeline
Train and evaluate a model
Persist a pipeline and model in Watson Machine Learning repository
Explore and visualize prediction result using the plotly package
Deploy a model for batch scoring using Wastson Machine Learning API
Use Spark and Python to predict Credit Risk Spark Load a CSV file into an Apache® Spark DataFrame
Explore data
Prepare data for training and evaluation
Persist a pipeline and model in Watson Machine Learning repository from tar.gz files
Deploy a model for online scoring using Watson Machine Learning API
Score sample scoring data using the Watson Machine Learning API
Explore and visualize prediction result using the plotly package
Use Spark to predict product line Spark Load a CSV file into an Apache Spark DataFrame
Explore data
Prepare data for training and evaluation
Persist a pipeline and model in Watson Machine Learning repository from tar.gz files
Deploy a model for online scoring using Watson Machine Learning API
Score sample scoring data using the Watson Machine Learning API
Explore and visualize prediction result using the plotly package
Use SPSS to predict customer churn SPSS Work with the instance
Perform an online deployment of the SPSS model
Score data using deployed model
Use Tensorflow to recognize hand-written digits Tensorflow Download an externally trained Tensorflow model with dataset
Persist an external model in Watson Machine Learning repository
Deploy model for online scoring using client library
Score sample records using client library
Use XGBoost to classify tumors XGBoost Load a CSV file into numpy array
Explore data
Prepare data for training and evaluation
Create an XGBoost machine learning model
Train and evaluate a model
Use cross-validation to optimize model's hyperparameters
Persist a model in Watson Machine Learning repository
Deploy a model for online scoring
Score sample data
Predict business for cars Hybrid(Tensorflow) Set up an AI definition
Prepare the data
Create a Keras model using Tensorflow
Deploy and score the model
Define, store and deploy a Python function
Deploy Python function for software specification Core Create a Python function
Create a web service
Score the model
Machine Learning artifact management Core Export and import artifacts
Load, deploy and score externally created models
Use R Shiny app to create SIR model R Persist a R Shiny app in in Watson Machine Learning asset repository.
Deploy application for online scoring using client library.
Score sample records using client library.

Deep Learning samples

View or run these Jupyter notebooks to see how deep learning model techniques are implemented using a variety of frameworks. Some of the samples rely on trained models, which are also available for you to download from the public repository.

Sample name Framework Techniques demonstrated
Use PyTorch to recognize hand-written digits PyTorch Working with Watson Machine Learning service
Training Deep Learning models (TensorFlow)
Save trained models in Watson Machine Learning repository
Perform online deployment and score the trained model
Use TensorFlow to recognize hand-written digits TensorFlow Work with Watson Machine Learning service
Train Deep Learning models (TensorFlow)
Saving trained models in Watson Machine Learning repository
Perform online deployment and score the trained model

AutoAI samples

View or run these Jupyter notebooks to see how AutoAI model techniques are implemented.

Sample name Framework Techniques demonstrated
Use AutoAI and Lale to predict credit risk Hybrid (AutoAI) with Lale Work with Watson Machine Learning experiments to train AutoAI models
Compare trained models quality and select the best one for further refinement
Refine the best model and test new variations
Perform online deployment and score the trained model
Use AutoAI to predict credit risk Hybrid (AutoAI) Work with Watson Machine Learning experiments to train AutoAI models
Compare trained models quality and select the best one for further refinement
Refine the best model and test new variations
Perform online deployment and score the trained model
Use AutoAI and multiple data to predict sale quantity Hybrid (AutoAI) Work with Watson Machine Learning experiments to train AutoAI models using multiple data sources
Define Watson Machine Learning experiment for multiple data sets
Work with experiments to train AutoAI models
Compare trained models quality and select the best one for further deployment
Perform batch deployment and score the trained model

Parent topic: Training and deploying machine learning models in notebooks