Path: blob/main/L4assets/DSandMLOpsAssets/HandsOn/Notebooks/DS Model evaluation.ipynb
1928 views
Model evaluation
In this notebook we test the models on data that was not used in the model creation.
CPDaaS: Make sure to first insert a "project token"
Click on the three vertical dots icon in the uper right of the screen, then click on Insert project token
Once inserted, execute the cell.
A project token is only available if you followed the prerequesite instructions to create on in your project.
WML python library
The ibm-watson-machine-learning library is already part of the runtime environment, so it does not need to be installed with the command:
!pip install ibm-watson-machine-learning
At the time of this writing, the library supports Cloud Pak for Data as a Service as well as Cloudpak for Data versions 3.5, 4.0, 4.5, and 4.6.
For more information on the Python libraries see:
Get a WML connection
Replace the value of
cpd_urlwith the proper cloud region or the proper cluster URLSet the value of
API_keyto your API key
Create a Watson Machine Learning (WML) client connection
Listing projects models
Also get the model details
AutoAI model details
There are a lot of details attached to a model. Here is a small sample:
Number of rcords involved in the model training
Label column
Feature importance
Input fields schema
Training data reference
Model name
and more
List the feature importance
List the important features in order of importance. This is something that can be seen through the Watson Studio UI in the AutoAI experiment.
The two most important features are HOTSPOT2 and PRIM_DRIVER_GENDER
List the input column names
Note that the RISK column is not part of the input.
The output columns definition is an empty array.
SPSS model details
The SPSS model includes different information from AutoAI but stilll includes information such as:
Schemas: input, output
Software specifications
Name
and more
List input and output column names
The output columns include the input columns with the addition of:
Partition$XR-RISK$XRE-RISK
Load data to score
This data was not seen during model creation. It contains over 20 thousand records.
This section uses the first 20 records of the dataset.
Some statistics on the records
This should really be done on the training data but since we have 20000 records, that should be good enough.
Load the AutoAI model and score some records
The AutoAI model can run in the notebook runtime. There is no need to first deploy it. This makes it quite simple to use in a notebook.
Compare results
Values, differences and percentage of differences
Root mean squared error (RMSE)
Applied only on the small set of records scored. This can varie greatly from the value returned in the AutoAI experiment on the training data.
The RISK value in the validation records range from 4 to 59. A RMSE of 5 would represent roughly a 9% error.
Deploy the SPSS model and score some records
In this case, the load command would create a local file with the model in it and returns the path to the model.
The SPSS model depends on a runtime that is not part of the notebook. It must use the Watson Machine Learning(WML) for execution.
We need a deployment space!
Promote the model to the deployment space
From the project to the deployment space. This deployment space must be associated with a Watson Machine Learning (WML) service
Deploy the newly promoted model
Note: online_url is deprecated and will be removed in a future release. Use serving_urls instead.
Score the records
Notice the fields names are extracted from the model details and the scoring records are directly from the dataframe. There must not be invalid values so they are replaces with zeros (fillna(0))
Compare results
Values, differences and percentage of differences
Root mean squared error (RMSE)
Applied only on the small set of records scored. This can varie greatly based on the results used, only 20 values here.
Cleanup
Remove the deployment
Remove the promoted asset
Author
Jacques Roy is a member of the IBM Enablement for Data and AI
Copyright © 2023. This notebook and its source code are released under the terms of the MIT License.