Skip to content

help to upgrade to new api #1010

@celestinoxp

Description

@celestinoxp

I have a code with old api, but if i use old "evidently" it downgrade other dependencies, so i need use new api.
i take a look on documentation but i don´t know how to change... my code:

        from evidently.dashboard import Dashboard
        from evidently.pipeline.column_mapping import ColumnMapping
        from evidently.tabs import CatTargetDriftTab, DataDriftTab

        column_mapping = ColumnMapping()
        column_mapping.target = target
        column_mapping.prediction = None
        column_mapping.datetime = None
        column_mapping.numerical_features = numeric_features
        column_mapping.categorical_features = categorical_features
        column_mapping.datetime_features = date_features

        if target not in reference_data.columns or target not in current_data.columns:
            raise ValueError(
                f"Both dataset must contain a label column {target} "
                "in order to create a drift report."
            )

        dashboard = Dashboard(tabs=[DataDriftTab(), CatTargetDriftTab()])
        dashboard.calculate(reference_data, current_data, column_mapping=column_mapping)
        filename = (
            filename or f"{self.exp_name_log}_{int(time.time())}_Drift_Report.html"
        )
        dashboard.save(filename)
        return filename

upgraded to:

        from evidently import ColumnMapping
        from evidently.metric_preset import DataDriftPreset, TargetDriftPreset
        from evidently.report import Report

        column_mapping = ColumnMapping()
        column_mapping.target = target
        column_mapping.prediction = None
        column_mapping.datetime = None
        column_mapping.numerical_features = numeric_features
        column_mapping.categorical_features = categorical_features
        column_mapping.datetime_features = date_features

        report = Report(metrics=[DataDriftPreset(), TargetDriftPreset()])

        # Generate the report filename
        filename = f"{self.exp_name_log}_{int(time.time())}_Drift_Report.html"

        # Save the report as an HTML file
        report.save(filename)

        # Return the filename
        return filename

It its correctly upgraded? Any suggestions?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions