Data Visualization & Pattern Detection
Press Next → or use ← → arrow keys
Visualization IS Analysis
That's why data visualization is not decoration — it's analysis. Summary numbers compress away exactly the trends, groupings, and outliers you most need to see. A good plot puts them back on screen where your eyes can catch them in seconds.
Four datasets can share the same mean, variance, and correlation yet look nothing alike — a fact known as Anscombe's Quartet. Rely on the numbers alone and you'll miss curves, outliers, and clusters entirely. The next slide shows exactly how.
Anscombe's Quartet — Always Plot First
All four share the same mean (~9), variance (~11), and correlation (~0.82) — yet a line, a curve, an outlier-wrecked line, and a near-vertical stack couldn't be more different. The summary numbers are blind to this; a five-second scatter plot reveals it instantly. Rule one of visualization: plot before you compute.
Match The Chart To The Question
The eye judges lengths far better than angles, so pie charts make it nearly impossible to compare similar slices accurately. Almost any pie chart is clearer as a bar chart. Start from the question, and the right chart usually picks itself.
Seeing One Variable's Shape
import seaborn as sns # histogram + smooth KDE curve sns.histplot(df['purchase_amount'], bins=40, kde=True) # split the distribution by a category sns.histplot(df, x='purchase_amount', hue='gender', kde=True, alpha=0.6)
A right-skew (a long tail of big spenders) says the mean will mislead — report the
median. A bimodal shape (two humps) is a giveaway that two sub-populations are mixed
together, which the hue= split can confirm. Histograms, KDEs, and violins all answer the
same question: what does this one column actually look like?
Comparisons, Relationships & Outliers
# category comparison + outliers in one plot sns.boxplot(data=df, x='product_category', y='purchase_amount') # two numerics, colour-encoded by a third variable sns.scatterplot(data=df, x='age', y='purchase_amount', hue='income_bracket') # everything at once — correlation heatmap (upper triangle masked) corr = df.select_dtypes('number').corr().round(2) sns.heatmap(corr, annot=True, cmap='coolwarm', center=0, vmin=-1, vmax=1)
A correlation heatmap shows, in one glance, which features drive your target (say income → purchase at +0.78), which work against it (delivery days → rating at −0.44), and which mirror each other. Any pair above |r| > 0.85 is a multicollinearity flag — candidates to drop.
Five Patterns To Hunt For
Trends (steady direction), seasonality (repeating cycles), clusters (natural groups), correlations (variables moving together), and outliers (points that don't belong). Naming the pattern you're hunting tells you which chart to reach for.
Trends & Seasonality Over Time
# daily totals, then a 7-day rolling average to reveal the trend df['order_date'] = pd.to_datetime(df['order_date']) daily = df.groupby('order_date')['purchase_amount'].sum().reset_index() daily['rolling_7d'] = daily['purchase_amount'].rolling(7).mean()
Raw daily data is jagged. A rolling average (here 7-day) irons out the day-to-day jitter so the underlying trend stands out. Meanwhile a monthly bar chart exposes seasonality — the November–December peaks that repeat every year. Line charts for trends, bars for cyclical patterns.
pd.to_datetime() is the essential first move — until a column is a real datetime, you can't
resample, roll, or group by month. Time-series patterns only appear once the time axis is genuinely a
time axis.
Catching Anomalies With A Control Band
Compute a rolling mean and rolling standard deviation, then draw a band at mean ± 2σ. Any day whose revenue jumps outside that band is an anomaly — a marketing spike, a system glitch, or a data error worth investigating. The band adapts as the trend moves, so it stays meaningful over time.
Two Ways To Flag The Unusual
Before you touch a flagged point, ask: is it a data-quality error (a typo, a sensor fault) or a genuine event (a real sales spike, a fraud attempt)? Never delete anomalies silently — investigate first and document every removal. The interesting outlier is often the whole point of the analysis.
matplotlib · seaborn · plotly
Reach for seaborn while exploring, plotly when the audience needs to interact, and matplotlib when you need pixel-perfect control for a report or paper. They interoperate — seaborn returns matplotlib axes you can fine-tune.
What Makes A Chart Honest & Clear
| ❌ Avoid | ✅ Do |
|---|---|
| Truncated axis (bar not starting at 0) | Start bar-chart axes at zero |
| Colour as decoration | Colour to encode information |
| Chartjunk: gridlines, 3-D, gradients | Strip everything non-essential |
| Pie charts for comparison | Bar charts — the eye reads length |
| Leaving the reader to guess | Annotate the insight directly on the chart |
A good chart delivers its main message in about five seconds. If a viewer has to squint, decode a legend, or hunt for the point, simplify: fewer elements, a clearer title, a direct annotation. And never distort — a truncated axis can turn a 2% change into a visual cliff.
Seven Rules For Visualization
You Can Now See What The Data Hides
Visualization is analysis: each chart tests whether reality matches your expectation. Plot before you compute, match the chart to the question, and learn to spot the five patterns — trend, seasonality, clusters, correlation, and outliers. Then keep it honest: zero-based axes, meaningful colour, and a message readable in five seconds.
The patterns and problems you spot here feed straight into data cleaning (fixing the outliers and gaps you found) and feature engineering — turning the trends, seasonality, and relationships you've now seen into features a model can learn from.
📊 End of tutorial · Press ← to review, or click Restart