| name | autoviz-6-outlier-detection-and-highlighting |
| description | Sub-skill of autoviz: 6. Outlier Detection and Highlighting. |
| version | 1.0.0 |
| category | data-analysis |
| type | reference |
| scripts_exempt | true |
6. Outlier Detection and Highlighting
6. Outlier Detection and Highlighting
Automatic Outlier Identification:
from autoviz import AutoViz_Class
import pandas as pd
import numpy as np
np.random.seed(42)
n = 1000
revenue = np.concatenate([
np.random.normal(1000, 200, n - 20),
np.random.uniform(3000, 5000, 10),
np.random.uniform(-500, 0, 10)
])
units = np.concatenate([
np.random.normal(50, 10, n - 15),
np.random.uniform(150, 200, 15)
])
df = pd.DataFrame({
"revenue": revenue,
"units": units,
"cost": np.abs(revenue * 0.6 + np.random.randn(n) * 100),
"category": np.random.choice(["A", "B", "C"], n),
"region": np.random.choice(["North", "South", "East", "West"], n)
})
AV = AutoViz_Class()
df_analyzed = AV.AutoViz(
filename="",
dfte=df,
verbose=2,
chart_format="svg"
)
Custom Outlier Analysis Wrapper:
from autoviz import AutoViz_Class
import pandas as pd
import numpy as np
def analyze_with_outlier_report(df: pd.DataFrame, target: str = "") -> dict:
"""
Run AutoViz and provide detailed outlier report.
Args:
df: Input DataFrame
target: Target variable name (optional)
Returns:
Dictionary with analysis results and outlier info
"""
outlier_info = {}
numeric_cols = df.select_dtypes(include=[np.number]).columns
for col in numeric_cols:
Q1 = df[col].quantile(0.25)
Q3 = df[col].quantile(0.75)
IQR = Q3 - Q1
lower_bound = Q1 - 1.5 * IQR
upper_bound = Q3 + 1.5 * IQR
outliers = df[(df[col] < lower_bound) | (df[col] > upper_bound)]
outlier_info[col] = {
"count": len(outliers),
"percentage": len(outliers) / len(df) * 100,
"lower_bound": lower_bound,
"upper_bound": upper_bound,
"min_outlier": outliers[col].min() if len(outliers) > 0 else None,
"max_outlier": outliers[col].max() if len(outliers) > 0 else None
}
AV = AutoViz_Class()
df_analyzed = AV.AutoViz(
filename=,
dfte=df,
depVar=target,
verbose=,
chart_format=
)
{
: df_analyzed,
: outlier_info,
: (info[] info outlier_info.values())
}