Evidently AI for generating Data drift Target Drift & Regression Drift reports quickly
2 min readDec 4, 2024
import evidently
from evidently.report import Report
from evidently.metric_preset import DataDriftPreset, TargetDriftPreset, RegressionPreset
def generate_evidently_report(reference_data, current_data, output_path, report_type="data_drift"):
"""
Generate an Evidently report for the given reference and current datasets.
Parameters:
reference_data (pd.DataFrame): The reference dataset.
current_data (pd.DataFrame): The current dataset.
output_path (str): The file path where the report will be saved (e.g., 'report.html').
report_type (str): The type of report to generate. Options:
'data_drift', 'target_drift', 'regression'.
Returns:
None: Saves the report as an HTML file to the specified output path.
"""
# Define the metrics preset based on the report type
if report_type == "data_drift":
report = Report(metrics=[DataDriftPreset()])
elif report_type == "target_drift":
report = Report(metrics=[TargetDriftPreset()])
elif report_type == "regression":
report = Report(metrics=[RegressionPreset()])
else:
raise ValueError("Invalid report type. Choose from 'data_drift', 'target_drift', or 'regression'.")
# Run the report
report.run(reference_data=reference_data, current_data=current_data)
# Save the report
report.save_html(output_path)
print(f"Report saved to {output_path}")
reference_data,pd.DataFrame,The reference dataset (e.g., historical data or training data).,A DataFrame with features and targets.
current_data,pd.DataFrame,The current dataset (e.g., new data to compare against the reference).,A DataFrame with similar structure.
output_path,str,File path where the generated HTML report will be saved.,”output/report.html”
report_type,str,The type of report to generate. Options: ‘data_drift’, ‘target_drift’, ‘regression’.,’data_drift
import httpx
# Replace with your Slack webhook URL
slack_webhook_url = "https://hooks.slack.com/services/XXXX/YYYY/ZZZZ"
# The payload you want to send
payload = {"message": "This is a test message... ignore this"}
# Making the POST request with SSL verification disabled
with httpx.Client(verify=False) as client:
response = client.post(slack_webhook_url, json=payload)
# Check the response
if response.status_code == 200:
print("Message sent successfully!")
else:
print(f"Failed to send message. Status code: {response.status_code}, Response: {response.text}")