0 / 0
watsonx.ai Runtime Python client samples and examples
Last updated: Dec 03, 2024
watsonx.ai Runtime Python client samples and examples

Review and use sample Jupyter Notebooks that use watsonx.ai Runtime Python library to demonstrate machine learning features and techniques. Each notebook lists learning goals so you can find the one that best meets your goals.

Training and deploying models from notebooks

If you choose to build a machine learning model in a notebook, you must be comfortable with coding in a Jupyter Notebook. A Jupyter Notebook is a web-based environment for interactive computing. 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 watsonx.ai Runtime, and deploy the model.

Learn from sample notebooks

Many ways exist to build and train models and then deploy them. Therefore, the best way to learn is to look at annotated samples that step you through the process by using different frameworks. Review representative samples that demonstrate key features.

The samples are built by using the V4 version of the watsonx.ai Python client library.

Video disclaimer: Some minor steps and graphical elements in the videos might differ from your deployment.

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 table.

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

Watch this video to learn how to test a model that was created with AutoAI by using the watsonx.ai Runtime APIs in Jupyter Notebook.

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

Helpful variables

Use the pre-defined PROJECT_ID environment variable to call the watsonx.ai Python client APIs. PROJECT_ID is the guide of the project where your environment is running.

Deployment samples

View or run these Jupyter Notebooks to see how techniques are implemented by using various 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 watsonx.ai Runtime repository
Deploy the model by using watsonx.ai Runtime Service
Perform predictions that use the deployed model
Use PMML to predict iris species PMML Deploy and score a PMML model
Use Python function to recognize hand-written digits Python Use a function to store a sample model, then deploy the sample model.
Use scikit-learn to recognize hand-written digits Scikit-learn Train sklearn model
Persist trained model in watsonx.ai Runtime repository
Deploy model for online scoring by using client library
Score sample records by 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 watsonx.ai Runtime repository
Explore and visualize prediction result by using the plotly package
Deploy a model for batch scoring by using watsonx.ai Runtime 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 watsonx.ai Runtime repository from tar.gz files
Deploy a model for online scoring by using watsonx.ai Runtime API
Score sample data by using the watsonx.ai Runtime API
Explore and visualize prediction results by 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 by using deployed model
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 the model's hyperparameters
Persist a model in watsonx.ai Runtime repository
Deploy a model for online scoring
Score sample data
Predict business for cars Spark Download an externally trained Keras model with dataset.
Persist an external model in the watsonx.ai Runtime repository.
Deploy a model for online scoring by using client library.
Score sample records by using client library.
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 Decision Optimization to plan your diet Core Create a diet planning model by using Decision Optimization
Use SPSS and batch deployment with Db2 to predict customer churn SPSS Load a CSV file into an Apache Spark DataFrame
Explore data
Prepare data for training and evaluation
Persist a pipeline and model in watsonx.ai Runtime repository from tar.gz files
Deploy a model for online scoring by using watsonx.ai Runtime API
Score sample data by using the watsonx.ai Runtime API
Explore and visualize prediction results by using the plotly package
Use scikit-learn and AI lifecycle capabilities to predict Boston house prices Scikit-learn 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 watsonx.ai Runtime repository
Deploy a model with AutoAI lifecycle capabilities
German credit risk prediction with Scikit-learn for model monitoring Scikit-learn Train, create, and deploy a credit risk prediction model with monitoring
Monitor German credit risk model Scikit-learn Train, create, and deploy a credit risk prediction model with IBM Watson OpenScale capabilities
Convert ONNX neural network from fixed axes to dynamic axes and use it with ibm-watsonx-ai ONNX Set up the environment
Create and export basic ONNX model
Convert model from fixed axes to dynamic axes
Persist converted ONNX model
Deploy and score ONNX model
Clean up
Summary and next steps
Use ONNX model converted from PyTorch with ibm-watsonx-ai ONNX Create PyTorch model with dataset.
Convert PyTorch model to ONNX format
Persist converted model in Watson Machine Learning repository.
Deploy model for online scoring using client library.
Score sample records using client library.
Use ONNX model converted from TensorFlow to recognize hand-written digits with ibm-watsonx-ai ONNX Download an externally trained TensorFlow model with dataset.
Convert TensorFlow model to ONNX format
Persist converted model in Watson Machine Learning repository.
Deploy model for online scoring using client library.
Score sample records using client library.

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 watsonx.ai Runtime 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
Deploy and score the trained model
Use AutoAI to predict credit risk Hybrid (AutoAI) Work with watsonx.ai Runtime 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
Deploy and score the trained model

More samples

To learn how to test a model by using watsonx.ai Runtime API client, see Test the model using the API Client.

Next steps

Parent topic: Managing predictive deployments

Generative AI search and answer
These answers are generated by a large language model in watsonx.ai based on content from the product documentation. Learn more