Machine Learning Python samples and examples
Use samples and examples to help you learn about features and techniques.
Note: To run these samples and examples, you must be using a v2 Watson Machine Learning Service instance, provisioned after September 1, 2020. For details, see Watson Machine Learning Service instance.
These samples are built using the V4 version of the Watson Machine Learning REST API and Watson Machine Learning Python client library.
Running a sample notebook
To work with these samples, familiarize yourself with the basics of working with notebooks:
- For details on working with notebooks, see Coding and running notebooks.
- For details on authenticating in a notebook, see Authentication.
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 Core ML model to predict Boston house prices | CoreML | Load a sample data set from scikit-learn Explore data Prepare data for training and evaluation Create a scikit-learn pipeline Train and evaluate a model Store a model in the Watson Machine Learning repository Deploy a model as Core ML |
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 | Working with the instance Online deployment of SPSS model Scoring 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 |
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 Keras and HPO to recognize hand-written digits | Keras | Working with the Watson Machine Learning service. Training Deep Learning models (TensorFlow) Saving trained models in Watson Machine Learning repository Online deployment and scoring of the trained model |
Use PyTorch to recognize hand-written digits | PyTorch | Working with Watson Machine Learning service Training Deep Learning models (TensorFlow) Saving trained models in Watson Machine Learning repository Online deployment and scoring of trained model |
Use TensorFlow to recognize hand-written digits | TensorFlow | Working with Watson Machine Learning service Training Deep Learning models (TensorFlow) Saving trained models in Watson Machine Learning repository Online deployment and scoring of 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 Online deployment and score the trained model |
 | 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 Batch deployment and score the trained model |
 | Hybrid (AutoAI) | Work with Watson Machine Learning experiments to train AutoAI models Calculate fairness metrics of trained pipelines Refine the best model and perform mitigation to get less biased model Store trained model with custom software specification Online deployment and score the trained model |