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
Copy link to section
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
Copy link to section
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
Copy link to section
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
Copy link to section
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.
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
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
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
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
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
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.
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
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
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
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.
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
Copy link to section
View or run these Jupyter Notebooks to see how AutoAI model techniques are implemented.
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
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