nRegExpMetric",

columns=["Review_Text", "Title"],reg_exp=r"[A-Z][A-Za-z0-9 ]*",

),

],

column_mapping = ColumnMapping(

target="Rating",

numerical_features=["Age", "Positive_Feedback_Count"],

categorical_features=[

"Division_Name",

"Department_Name",

"Class_Name",

],

text_features=["Review_Text", "Title"],

),

download_nltk_data = True,

# post-processing (e.g. interpret results, take actions) can happen here

return report.json(), HTMLString(report.show(mode="inline").data)

@step

def data_validation(

reference_dataset: pd.DataFrame,

comparison_dataset: pd.DataFrame,

) -> Tuple[

Annotated[str, "test_json"],

Annotated[HTMLString, "test_html"]

]:

"""Custom data validation step with Evidently.

Args:

reference_dataset: a Pandas DataFrame

comparison_dataset: a Pandas DataFrame of new data you wish to

compare against the reference data

Returns:

The Evidently test suite results rendered in JSON and HTML formats.

"""

# pre-processing (e.g. dataset preparation) can take place here

data_validator = EvidentlyDataValidator.get_active_data_validator()

test_suite = data_validator.data_validation(

dataset=reference_dataset,

comparison_dataset=comparison_dataset,

check_list=[

EvidentlyTestConfig.test("DataQualityTestPreset"),

EvidentlyTestConfig.test_generator(

"TestColumnRegExp",

columns=["Review_Text", "Title"],

reg_exp=r"[A-Z][A-Za-z0-9 ]*",

),

],

column_mapping = ColumnMapping(

target="Rating",

numerical_features=["Age", "Positive_Feedback_Count"],

categorical_features=[

"Division_Name",

"Department_Name",

"Class_Name",

],

text_features=["Review_Text", "Title"],

),

download_nltk_data = True,

# post-processing (e.g. interpret results, take actions) can happen here

return test_suite.json(), HTMLString(test_suite.show(mode="inline").data)

Have a look at the complete list of methods and parameters available in the EvidentlyDataValidator API in the SDK docs.

Call Evidently directly

You can use the Evidently library directly in your custom pipeline steps, e.g.: