Lesson 8 of 9
Mini Project: Automated EDA Report & Feature Quality Dashboard
Build a production-grade, automated Exploratory Data Analysis auditing engine. The tool ingests any arbitrary tabular dataset, performs automated type inference, computes distribution moments, identifies severe multicollinearity, flags extreme class imbalances, tests for target correlations, and produces an exportable Markdown diagnostic health report.
The Automated Feature Diagnostic Engine
import pandas as pd
import numpy as np
import scipy.stats as stats
class AutomatedEDAAuditor:
def __init__(self, df: pd.DataFrame, target_col: str = None):
self.df = df.copy()
self.target_col = target_col
self.report = []
def log(self, section: str, msg: str):
self.report.append(f"[{section}] {msg}")
def audit_structure(self):
n_rows, n_cols = self.df.shape
self.log("STRUCTURE", f"Dataset Dimensions: {n_rows:,} rows × {n_cols} columns")
# Missing value checks
null_counts = self.df.isna().sum()
high_null_cols = null_counts[null_counts > 0.3 * n_rows].index.tolist()
if high_null_cols:
self.log("WARNING", f"Columns with >30% missing values: {high_null_cols}")
else:
self.log("HEALTH", "No columns exceed the 30% null threshold.")
def audit_numerical_distributions(self):
num_cols = self.df.select_dtypes(include=np.number).columns
for col in num_cols:
if col == self.target_col:
continue
s = self.df[col].dropna()
if len(s) < 10:
continue
skew = s.skew()
kurt = s.kurtosis()
if abs(skew) > 1.5:
self.log("DISTRIBUTION", f"Feature '{col}' is heavily skewed (skew={skew:.2f}). Consider Log1p or Box-Cox.")
if kurt > 5.0:
self.log("OUTLIERS", f"Feature '{col}' exhibits heavy leptokurtic tails (kurtosis={kurt:.2f}).")
def audit_target_relationship(self):
if not self.target_col or self.target_col not in self.df:
return
target = self.df[self.target_col]
# Binary target check
if target.nunique() == 2:
class_ratio = target.value_counts(normalize=True)
min_class_pct = class_ratio.min() * 100
self.log("TARGET", f"Binary classification target detected. Minority class balance: {min_class_pct:.2f}%")
if min_class_pct < 5.0:
self.log("WARNING", "Severe class imbalance detected (<5%). Use PR-AUC and cost-sensitive class weights.")
def run_full_audit(self) -> str:
self.audit_structure()
self.audit_numerical_distributions()
self.audit_target_relationship()
return "\n".join(self.report)
# Execute on sample dataset
np.random.seed(42)
test_data = pd.DataFrame({
'user_id': range(1000),
'revenue': np.random.exponential(100, 1000),
'unrecorded_notes': [None if i % 2 == 0 else "note" for i in range(1000)], # 50% nulls
'churn': np.random.choice([0, 1], size=1000, p=[0.97, 0.03]) # 3% minority
})
auditor = AutomatedEDAAuditor(test_data, target_col='churn')
print("=== AUTOMATED EDA REPORT SUMMARY ===")
print(auditor.run_full_audit())Pro Tip: Integrate Profiling into CI/CD Data Validation
Run your automated EDA auditor as a scheduled CI/CD job or Airflow DAG preceding model retraining. If the percentage of high-null columns or distribution skewness drifts beyond predefined tolerance boundaries, halt the training pipeline and alert data engineering.
MlEdaReportProject Visual Representation
Hands-On Challenge: Export to Static HTML Report
Extend the `AutomatedEDAAuditor` class to export its findings into a styled single-page HTML report containing embedded Base64 matplotlib histogram charts and summary diagnostic badges.
Quick Quiz & Key Concept Checks
Common Pitfall: Treating Automated Profilers as a Substitute for Domain Expertise
Automated profiling libraries (YData Profiling, Sweetviz) compute statistical metrics, but they cannot understand business context. A feature with high correlation might be an illegal discriminatory attribute or an operational target leak. Domain understanding is indispensable.