%pip install -q validmindDocument multiple results for the same test
Documentation templates facilitate the presentation of multiple unique test results for a single test.
Consider various scenarios where you may intend to showcase results of the same test with diverse inputs:
- Comparing test results with varied parameter values: Illustrate model performance by contrasting test results achieved with different parameter values to identify optimal settings.
- Displaying test results with distinct datasets: Showcase test versatility by presenting results on diverse datasets, such as providing confusion matrices for both training and test data.
- Model comparison: Conduct a comprehensive model evaluation by comparing tests like
ROC curveandAccuracyto discern and select the superior-performing model.
This interactive notebook guides you through the process of documenting a model with the ValidMind Library. It uses the Bank Customer Churn Prediction sample dataset from Kaggle to train a simple classification model. As part of the notebook, you will learn how to render more than one unique test result for the same test while exploring how the documentation process works:
- Initializing the ValidMind Library
- Loading a sample dataset provided by the library to train a simple classification model
- Running a ValidMind test suite to quickly generate documentation about the data and model
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 and validation 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.
documentation, model documentation: A structured and detailed document pertaining to a record, encompassing key components such as its underlying assumptions, methodologies, data sources, inputs, performance metrics, evaluations, limitations, and intended uses. Within the realm of risk management, this documentation serves to ensure transparency, adherence to regulatory requirements, and a clear understanding of potential risks associated with the record's application.
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.
documentation template: A default ValidMind document type that serves as a standardized framework for developing and documenting records, including sections designated for record details, data descriptions, test results, and performance metrics. By outlining required documentation and recommended analyses, document templates ensure consistency and completeness across documentation and help guide developers through a systematic development process while promoting comparability and traceability of development outcomes.
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.
Select
Modelby clicking on {Record} Inventory, where{Record}is the currently active type of record. (Learn more: Register records in the inventory)Click + Register Model.
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 documentation template
Once you've registered your model, let's select a documentation template. A template predefines sections for your documentation and provides a general outline to follow, making the documentation process much easier.
In the left sidebar that appears for your model, click Documents and select Development.
If you cannot locate your Development document, make sure Development type documents are enabled for model records and create a new document. (Learn more: Manage documents)
Under Template, select
Binary classification.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
Developmentfrom 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="documentation",
)Update the customer churn demo template
Before you initialize the ValidMind Library by running the notebook, edit the Binary classification template to make a copy of a test of interest and update it with different result_id fields for each entry:
- Go to Settings > Templates and click on the Binary classification template. Let's say we want to show
Skewnessresults fortrainingandtestdatasets.
To do this we replace
- content_type: test
content_id: validmind.data_validation.Skewnesswith
- content_type: test
content_id: validmind.data_validation.Skewness:training_data
- content_type: test
content_id: validmind.data_validation.Skewness:test_dataThis way, we can show two results of the same test in the model document. Here, the training_data and test_data could be any string. However, they should be unique for the same test.
- Click on Prepare new version, provide some version notes and click on Save new version to save a new version of this template.
- Next, we need to swap our model documentation to use this new version of the template. Follow the steps on Manage document templates to swap the template of our customer churn model.
In the following sections we provide more context on how these content_id fields mentioned earlier get mapped to the actual tests.
Initialize the Python environment
Next, let's import the necessary libraries and set up your Python environment for data analysis:
import pandas as pd
import xgboost as xgb
from sklearn.metrics import accuracy_score
from sklearn.model_selection import train_test_split
%matplotlib inlinePreview the documentation 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 sample dataset
The sample dataset used here is provided by the ValidMind library, along with a second, different dataset (taiwan_credit) you can try as well.
To be able to use either sample dataset, you need to import the dataset and load it into a pandas DataFrame, a two-dimensional tabular data structure that makes use of rows and columns:
# Import the sample dataset from the library
from validmind.datasets.classification import customer_churn as demo_dataset
df = demo_dataset.load_data()Initialize a ValidMind dataset object
Before you can run a test suite, which are a collection of 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 analyzetarget_column— the name of the target column in the datasetclass_labels— the list of class labels used for classification model training
vm_dataset = vm.init_dataset(
input_id="raw_dataset",
dataset=df,
target_column=demo_dataset.target_column,
class_labels=demo_dataset.class_labels,
)Document the model
As part of documenting the model with the ValidMind Library, you need to preprocess the raw dataset, initialize some training and test datasets, initialize a model object you can use for testing, and then run the full suite of tests.
Prepare datasets
DataFrame (df) preprocessing is simplified by employing demo_dataset.preprocess to partition it into distinct datasets (train_df, validation_df, and test_df)
train_df, validation_df, test_df = demo_dataset.preprocess(df)Initialize the training and test datasets
With the datasets ready, you can now initialize the training and test datasets (train_df and test_df) created earlier into their own dataset objects using vm.init_dataset():
vm_train_ds = vm.init_dataset(
input_id="train_dataset", dataset=train_df, target_column=demo_dataset.target_column
)
vm_test_ds = vm.init_dataset(
input_id="test_dataset", dataset=test_df, target_column=demo_dataset.target_column
)Run documentation tests
Now specify inputs and params for individual tests using config parameter. The results for the both the datasets will be visible in the documentation. The inputs in the config get priority over global inputs in the run_documentation_tests.
config = {
"validmind.data_validation.Skewness:training_data": {
"params": {"max_threshold": 1},
"inputs": {"dataset": vm_train_ds},
},
"validmind.data_validation.Skewness:test_data": {
"params": {"max_threshold": 1.5},
"inputs": {"dataset": vm_test_ds},
},
}
tests_suite = vm.run_documentation_tests(
inputs={
"dataset": vm_dataset,
},
config=config,
section=["data_preparation"],
)Run the individual tests using the run_test
Now run the Skewness tests for training and test datasets. The results for the both the datasets will be visible in the documentation.
test = vm.tests.run_test(
test_id="validmind.data_validation.Skewness:training_data",
params={"max_threshold": 1},
inputs={"dataset": vm_train_ds},
)
test.log()
test = vm.tests.run_test(
test_id="validmind.data_validation.Skewness:test_data",
params={"max_threshold": 1.5},
inputs={
"dataset": vm_test_ds,
},
)
test.log()Next steps
You can look at the results of this test suite 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 model documentation.
Work with your documentation
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 Development under Documents.
Expand the 2. Data Preparation section and take a look around.
You can now see the skewness tests results of training and test datasets in the
Data Preparationsection.
From here, you can also make qualitative edits to model documentation, view guidelines, collaborate with validators, and submit your documentation for approval when it's ready. (Learn more: Working with documentation)
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