String Mismatch Comparison#

This page provides an overview for using and understanding the “String Mismatch Comparison” check.


What is the purpose of the check?#

The check compares the same categorical column within train and test and checks whether there are variants of similar strings that exists only in test and not in train. Finding those mismatches is helpful to prevent errors when inferring on the test data. For example, in train data we have category ‘New York’, and in our test data we have ‘new york’. We would like to be acknowledged that the test data contain a new variant of the train data, so we can address the problem.

How String Mismatch Defined?#

To recognize string mismatch, we transform each string to it’s base form. The base form is the string with only its alphanumeric characters in lowercase. (For example “Cat-9?!” base form is “cat9”). If two strings have the same base form, they are considered to be the same.

import pandas as pd

Run the Check#

from deepchecks.tabular.checks import StringMismatchComparison

data = {'col1': ['Deep', 'deep', 'deep!!!', 'earth', 'foo', 'bar', 'foo?']}
compared_data = {'col1': ['Deep', 'deep', '$deeP$', 'earth', 'foo', 'bar', 'foo?', '?deep']}

check = StringMismatchComparison()
result =, pd.DataFrame(data=compared_data))

String Mismatch Comparison

Detect different variants of string categories between the same categorical column in two datasets.

Additional Outputs
* showing only the top 10 columns, you can change it using n_top_columns param
Column name col1
Base form deep
Common variants ['Deep', 'deep']
Variants only in test ['?deep', '$deeP$']
% Unique variants out of all dataset samples (count) 25% (2)
Variants only in train ['deep!!!']
% Unique variants out of all baseline samples (count) 14.29% (1)

Define a Condition#

check = StringMismatchComparison().add_condition_no_new_variants()
result =, pd.DataFrame(data=compared_data))
String Mismatch Comparison

Total running time of the script: ( 0 minutes 0.059 seconds)

Gallery generated by Sphinx-Gallery