%pip install -q validmindQuickstart for ongoing monitoring of models with ValidMind
Welcome! In this quickstart guide, you'll learn how to seamlessly monitor your production models using the ValidMind Platform.
We'll walk you through the process of initializing the ValidMind Library, loading a sample dataset and model, and running a monitoring test suite to quickly generate documentation about your new data and model.
This notebook utilizes the Bank Customer Churn Prediction dataset from Kaggle to train a simple classification model for demonstration purposes.
About ValidMind
ValidMind is a suite of tools for managing risk, including risk associated with AI and statistical models.
You use the ValidMind Library to automate documentation, validation, and monitoring tests, and then use the ValidMind Platform to collaborate on documentation. Together, these products simplify risk management, facilitate compliance with regulations and institutional standards, and enhance collaboration between yourself and validators.
Before you begin
This notebook assumes you have basic familiarity with Python, including an understanding of how functions work. If you are new to Python, you can still run the notebook but we recommend further familiarizing yourself with the language.
If you encounter errors due to missing modules in your Python environment, install the modules with pip install, and then re-run the notebook. For more help, refer to Installing Python Modules.
New to ValidMind?
If you haven't already seen our documentation on the ValidMind Library, we recommend you begin by exploring the available resources in this section. There, you can learn more about documenting records such as models and running tests, as well as find code samples and our Python Library API reference.
Register with ValidMind
Key concepts
record: A tool tracked in the ValidMind inventory, such as a model. Records include traditional statistical models, legacy systems, artificial intelligence/machine learning models, large language models (LLMs), agentic AI systems, and other documentable items that benefit from oversight, testing, and lifecycle management.
model: SR 26-2 (which supersedes SR 11-7) defines a model as a "complex quantitative method, system, or approach that applies statistical, economic, or financial theories to process input data into quantitative estimates." Simple arithmetic, deterministic rule-based processes, or software without statistical, economic, or financial theories underpinning their design or use are generally outside SR 26-2’s definition of a model. Within ValidMind, a model is a type of record tracked in the inventory.
ongoing monitoring report: A comprehensive and structured periodic report assessing the record's performance and compliance over time, ensuring it remains valid under changing conditions. Monitoring includes key elements such as data sources, inputs, performance metrics, and periodic evaluations, ensuring transparency and visibility of the record's performance in the production environment.
document template: Lays out the structure of documents, segmented into various sections and sub-sections, and functions as a test suite specifying the tests that should be run, and how the results should be displayed. Document templates help automate your development, validation, monitoring, and other risk management processes. Document templates are available for default ValidMind document types as well as custom document types.
monitoring template, monitoring report template: A default ValidMind document template that serves as a standardized framework for ongoing monitoring, including sections designated for test results, performance metrics, and drift analyses. By outlining required monitoring checks and expected routine tests, monitoring templates ensure consistency and completeness across monitoring reports and help guide owners through a systematic monitoring process while promoting early detection of performance degradation.
test: A function contained in the ValidMind Library, designed to run a specific quantitative test on the dataset or record. Test results are logged to the ValidMind Platform, where they are attached to documents. Tests are the building blocks of ValidMind, used to evaluate and document records and datasets, and can be run individually or as part of a suite defined by your templates.
test suite: A collection of tests designed to run together to automate and generate documentation end-to-end for specific use cases. (Learn more: test_suites)
metric: A subset of tests that do not have thresholds. In the context of this notebook, metrics and tests can be thought of as interchangeable concepts.
custom test: Functions that you define to evaluate your record or dataset. These functions can be registered with the ValidMind Library to be used in the ValidMind Platform.
inputs: Objects to be evaluated and documented in the ValidMind Library. They can be any of the following:
- model: A single record that has been initialized in ValidMind with
init_model(). Despite the naming convention, model objects can be any type of record you want to test, document, validate, or monitor with ValidMind. - dataset: A single dataset that has been initialized in ValidMind with
init_dataset(). - models: A list of ValidMind records - usually this is used when you want to compare multiple records in your custom tests.
- datasets: A list of ValidMind datasets - usually this is used when you want to compare multiple datasets in your custom tests. (Learn more: Run tests with multiple datasets)
parameters: Additional arguments that can be passed when running a ValidMind test, used to pass additional information to a test, customize its behavior, or provide additional context.
outputs: Custom tests can return elements like tables or plots. Tables may be a list of dictionaries (each representing a row) or a pandas DataFrame. Plots may be matplotlib or plotly figures.
Setting up
Install the ValidMind Library
To install the library:
Initialize the ValidMind Library
Register sample model
Let's first register a sample record (model) for use with this notebook:
In a browser, log in to ValidMind.
In the left sidebar, select Inventory.
Under the RECORD TYPE drop-down, select
Modeland click + Register Model. (Learn more: Register records in the inventory)Enter the model details and click Next > to continue to assignment of inventory record stakeholders.
Select your own name under the RECORD OWNER drop-down.
Click Register Model to add the model to your inventory.
Apply monitoring report template
Once you've registered your model, let's select a monitoring report template. A template predefines sections for your monitoring report and provides a general outline to follow, making the monitoring process much easier.
In the left sidebar that appears for your model, click Documents and select Monitoring.
If you cannot locate your Monitoring document, make sure Monitoring type documents are enabled for model records and create a new document. (Learn more: Manage documents)
Under TEMPLATE, select
Ongoing Monitoring for Classification Models.Click Use Template to apply the template.
Get your code snippet
Initialize the ValidMind Library with the code snippet unique to each record per document, ensuring your test results are uploaded to the correct record and automatically populated in the right document in the ValidMind Platform when you run the Library.
On the left sidebar that appears for your model, select Getting Started and select
Monitoringfrom the DOCUMENT drop-down menu.Click Copy snippet to clipboard.
Next, load your model identifier credentials from an
.envfile or replace the placeholder with your own code snippet:
# Load your model identifier credentials from an `.env` file
%load_ext dotenv
%dotenv .env
# Or replace with your code snippet
import validmind as vm
vm.init(
# api_host="...",
# api_key="...",
# api_secret="...",
# model="...",
document="monitoring",
monitoring = True,
)Initialize the Python environment
Next, let's import the necessary libraries and set up your Python environment for data analysis:
import xgboost as xgb
import validmind as vm
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
from validmind.tests import run_test
%matplotlib inlinePreview the monitoring report template
Let's verify that you have connected the ValidMind Library to the ValidMind Platform and that the appropriate template is selected for your model.
You will upload documentation and test results unique to your model based on this template later on. For now, take a look at the default structure that the template provides with the vm.preview_template() function from the ValidMind library and note the empty sections:
vm.preview_template()Load the reference and monitoring datasets
The sample dataset used here is provided by the ValidMind library. For demonstration purposes we'll use the training, test and validation dataset splits as training, reference and monitoring datasets.
from validmind.datasets.classification import customer_churn
raw_df = customer_churn.load_data()
train_df, reference_df, monitor_df = customer_churn.preprocess(raw_df)Load the production model
We will also load a pre-trained model for demonstration purposes. This is a simple XGBoost model trained on the Bank Customer Churn Prediction dataset.
import xgboost as xgb
# Load the saved model
model = xgb.XGBClassifier()
model.load_model("xgboost_model.model")Initialize the ValidMind datasets
Before you can run tests, you must first initialize a ValidMind dataset object using the init_dataset function from the ValidMind (vm) module.
This function takes a number of arguments:
dataset— The raw dataset that you want to provide as input to tests.input_id- A unique identifier that allows tracking what inputs are used when running each individual test.target_column— A required argument if tests require access to true values. This is the name of the target column in the dataset.class_labels— An optional value to map predicted classes to class labels.
With all datasets ready, you can now initialize training, reference(test) and monitor datasets (train_df, reference_df and monitor_df) created earlier into their own dataset objects using vm.init_dataset():
vm_train_ds = vm.init_dataset(
dataset=train_df,
input_id="train_df",
target_column=customer_churn.target_column,
)
vm_reference_ds = vm.init_dataset(
dataset=reference_df,
input_id="reference_df",
target_column=customer_churn.target_column,
)
vm_monitor_ds = vm.init_dataset(
dataset=monitor_df,
input_id="monitor_dataset",
target_column=customer_churn.target_column,
)Initialize the ValidMind model
You'll also need to initialize a ValidMind model object (vm_model) that can be passed to other functions for analysis and tests on the data for our model.
- Despite the naming convention, ValidMind model objects can be any type of record you want to test, document, validate, or monitor with the ValidMind Library.
- From classical statistical and machine learning models, to generative and agentic AI systems and more, the ValidMind model object provides a consistent wrapper around your record so it can be passed as a unified input to any ValidMind test or test suite, with results sent directly to the ValidMind Platform.
Initialize your model object with vm.init_model():
vm_model = vm.init_model(
model,
input_id="model",
)Assign predictions to the datasets
We can now use the assign_predictions() method from the Dataset object to link existing predictions to any model. If no prediction values are passed, the method will compute predictions automatically:
vm_train_ds.assign_predictions(
model=vm_model,
)
vm_reference_ds.assign_predictions(
model=vm_model,
)
vm_monitor_ds.assign_predictions(
model=vm_model,
)Run the ongoing monitoring tests
Before we start the testing procedure, let's take a look at the expected tests that are pre-configured:
test_list = vm.get_test_suite().get_default_config()
for l in test_list:
print(l)Let's run the first test in the list. Note that you can use vm.tests.describe_test() to get information about the inputs required for the test:
vm.tests.describe_test("validmind.model_validation.ModelMetadata")As you can see, the ModelMetadata only requires a model input. Let's run the test and log the results into the monitoring document with the .log() method:
test_result = vm.tests.run_test(
"validmind.model_validation.ModelMetadata",
model=vm_model,
).log()Let's run the tests needed to determine data quality of the monitoring dataset:
data_qual = vm.get_test_suite(
section="prediction_data_description"
).get_default_config()
# Run all of the necessary data quality checks where the monitoring dataset is the basis
for l in data_qual:
vm.tests.run_test(
l,
inputs={"dataset": vm_monitor_ds},
show=False,
).log()
print("Completed test: {0}".format(l))To view the results of the model metadata and data quality tests, select Monitoring under Documents in the left sidebar of the model in the ValidMind Platform and click on the following sections:
- Model Monitoring Overview > 1.2. Model Details
- Data Quality & Drift Assessment > 2.1. Prediction Data Description
Next, let's run comparison tests, which will allow comparing differences between the training dataset and monitoring datasets. To run a test in comparison mode, you only need to pass an input_grid parameter to the run_test() method instead of inputs.
For more information about comparison tests, see this notebook.
correlation_tests = [
"validmind.data_validation.PearsonCorrelationMatrix:train_vs_test",
"validmind.data_validation.HighPearsonCorrelation:train_vs_test",
]
for test in correlation_tests:
vm.tests.run_test(
test,
input_grid={
"dataset": [vm_train_ds, vm_monitor_ds],
"model": [vm_model],
},
show=False,
).log()
print("Completed test {0}".format(test))You can view these results in the ValidMind Platform in Ongoing Monitoring within Documents under the following section:
- Data Quality & Drift Assessment > 2.2. Prediction Data Correlations and Interactions
Conduct target and feature drift testing
Next, the goal is to investigate the distributional characteristics of predictions and features to determine if the underlying data has changed. These tests are crucial for assessing the expected accuracy of the model.
- Target drift: We compare the dataset used for testing (reference data) with the monitoring data. This helps to identify any shifts in the target variable distribution.
- Feature drift: We compare the training dataset with the monitoring data. Since features were used to train the model, any drift in these features could indicate potential issues, as the underlying patterns that the model was trained on may have changed.
In the 2. Data Quality & Drift Assessment > 2.3 Target Drift section we can confirm only there is only one pre-configured test:
for l in vm.get_test_suite(section="comparison_data_target").get_default_config():
print(l)As part of running the rest of the tests, we will directly log the results to a section when calling the .log() method.
First, let's run the Population Stability Index (PSI) for predictions. In this case, we want to compare the test data with the monitoring data. (Note: For predictions, the training data is irrelevant.)
vm.tests.run_test(
"validmind.model_validation.sklearn.PopulationStabilityIndex",
inputs={
"datasets": [vm_reference_ds, vm_monitor_ds],
"model": vm_model,
},
show=False,
).log()Next, we can examine the correlation between features and predictions. Significant changes in these correlations may trigger a deeper assessment.
vm.tests.run_test(
"validmind.ongoing_monitoring.TargetPredictionDistributionPlot",
inputs={
"datasets": [vm_reference_ds, vm_monitor_ds],
"model": vm_model,
},
show=False,
).log(section_id="comparison_data_target")Now we want see difference in correlation pairs between model prediction and features.
vm.tests.run_test(
"validmind.ongoing_monitoring.PredictionCorrelation",
inputs={
"datasets": [vm_reference_ds, vm_monitor_ds],
"model": vm_model,
},
show=False,
).log(section_id="comparison_data_target")Finally for target drift, let's plot each prediction value and feature grid side by side.
vm.tests.run_test(
"validmind.ongoing_monitoring.PredictionAcrossEachFeature",
inputs={
"datasets": [vm_reference_ds, vm_monitor_ds],
"model": vm_model,
},
show=False,
).log(section_id="comparison_data_target")Feature drift tests
Next, let's add run a test to investigate how or if the features have drifted. In this instance we want to compare the training data with prediction data. These results will be logged in the 2. Data Quality & Drift Assessment > 2.4. Feature Drift section.
vm.tests.run_test(
"validmind.ongoing_monitoring.FeatureDrift",
inputs={
"datasets": [vm_reference_ds, vm_monitor_ds],
"model": vm_model,
},
show=False,
).log(section_id="comparison_data_feature")Model performance monitoring tests
Let's wrap up by monitoring the model's performance. Keep in mind that in some cases, it may not be possible to determine accuracy if the ground truth is unavailable. If this is the case, you can skip this test and instead focus on target and feature drift to inform the model owners.
The pre-configured tests for model performance are:
for l in vm.get_test_suite(section="model_performance_monitoring").get_default_config():
print(l)The code below will run the tests and log the results into the monitoring document for each of the tests. Note the use of input_grid again, which is required for comparison tests:
# Use the reference dataset vs monitoring dataset - the true comparison of accuracy
for test in vm.get_test_suite(
section="model_performance_monitoring"
).get_default_config():
if test == "validmind.model_validation.statsmodels.GINITable":
vm.tests.run_test(
"validmind.model_validation.statsmodels.GINITable",
input_grid={
"dataset": [vm_reference_ds, vm_monitor_ds],
"model": [vm_model],
},
show=False,
).log()
else:
vm.tests.run_test(
test,
input_grid={
"dataset": [vm_reference_ds, vm_monitor_ds],
"model": [vm_model],
},
show=False,
).log()
print("Completed test: {0}".format(test))Next steps
You can look at the output produced by the ValidMind Library right in the notebook where you ran the code, as you would expect. But there is a better way — use the ValidMind Platform to work with your monitoring report.
Work with your monitoring report
From the Inventory in the ValidMind Platform, go to the model you registered earlier. (Learn more: Working with the inventory)
In the left sidebar that appears for your model, click Monitoring under Documents.
What you see is the full draft of your monitoring report in a more easily consumable version. From here, you can make qualitative edits to monitoring reports, view guidelines, review monitoring results, and submit your monitoring report for approval when it's ready. (Learn more: Ongoing monitoring)
Discover more learning resources
We also offer many interactive notebooks to help you use the ValidMind Library to streamline your work:
Or, visit our documentation to learn more about ValidMind.
Upgrade ValidMind
Retrieve the information for the currently installed version of ValidMind:
%pip show validmindIf the version returned is lower than the version indicated in our production open-source code, restart your notebook and run:
%pip install --upgrade validmindYou may need to restart your kernel after running the upgrade package for changes to be applied.
Copyright © 2023-2026 ValidMind Inc. All rights reserved.
Refer to LICENSE for details.
SPDX-License-Identifier: AGPL-3.0 AND ValidMind Commercial