0% found this document useful (0 votes)
4 views30 pages

Predictive Analytics Practice Set

The document is a practice set for predictive analytics covering various topics such as time series analysis, neural network diagnostics, clustering, and classification techniques. It includes detailed questions and solutions that address key concepts like decomposition methods, smoothing techniques, and model evaluation metrics. The content is structured to enhance understanding of predictive analytics through practical applications and theoretical insights.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views30 pages

Predictive Analytics Practice Set

The document is a practice set for predictive analytics covering various topics such as time series analysis, neural network diagnostics, clustering, and classification techniques. It includes detailed questions and solutions that address key concepts like decomposition methods, smoothing techniques, and model evaluation metrics. The content is structured to enhance understanding of predictive analytics through practical applications and theoretical insights.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Predictive Analytics

Practice Set — Topic-wise Question Bank with Detailed Solutions


BAZG512 / MBAZG512 / PDBAZG512 · S2 25-26

Topics Covered
# Topic Focus
1 Time Series Analysis Components, decomposition, smoothing methods
2 Neural Network Diagnostics Vanishing gradient, overfitting, fixes
3 Clustering (K-Means & DBSCAN) Elbow method, density tuning
4 Naive Bayes Classification Priors, likelihoods, Laplace smoothing
5 ROC, AUC, Threshold Selection Operating-point trade-offs
6 Principal Component Analysis Scree, variance explained, k selection
7 Regression with Interactions Main effects, p-values, hierarchy
8 Support Vector Machines (SVM) Hyperplane, margin, C, kernels
9 Decision Trees & Random Forest Gini, information gain, bagging

Predictive Analytics — Practice Set (S2 25-26) Page 1


Topic 1 · Time Series Analysis
Concept map. A time series can carry four kinds of pattern: Trend (long-term direction), Seasonality
(regular pattern with fixed period — weekly, yearly), Cyclical (longer rises/falls of variable length, often
driven by macro conditions), and Irregular (noise / one-offs). Decomposition is additive when the
seasonal amplitude stays roughly constant (Y = T + S + I) and multiplicative when it grows or shrinks
with the level (Y = T x S x I). Smoothing has a ladder: Moving Average & SES when only a level
matters, Holt’s double when there is also trend, and Holt-Winters triple when trend + seasonality are
both present.

Q1 | Easy
For each of the following time series, name which time-series component (Trend, Seasonality, Cyclical,
or Irregular) is most likely to dominate, and justify in one line. (a) A solar farm’s daily kWh output over 3
years — the plot shows a steady summer-to-summer pattern that swings between high and low. (b) A
railway’s monthly freight tonnage over 8 years — volume rose persistently as new corridors were
added. (c) A construction-materials price index over 25 years — shows repeated booms and busts each
lasting 4 to 7 years, not tied to any calendar period. (d) Tomato wholesale prices on a single market
day, recorded every 10 minutes — ups and downs with no recognisable structure.
Solution
(a) Seasonality. A pattern that repeats at a fixed period (annual, tied to the sun) is the definition of
seasonality. The summer-vs-winter swing on solar output is a textbook example.
(b) Trend. Persistent, long-run directional movement — with no calendar repetition mentioned,
growth is the only structured component.
(c) Cyclical. Rises and falls of variable length, driven by macro forces (economic cycles), without a
fixed calendar period. The 4-to-7-year inconsistency is what distinguishes cyclical from seasonal.
(d) Irregular. No discernible pattern at this micro time scale — what is left after structured
components are removed is noise.
Intuition. A quick mnemonic. Trend has a direction. Seasonality has a fixed period. Cycle has a story
(macro). Irregular has neither direction, period, nor story — it is just leftover.

Q2 | Easy
Two monthly time series are observed over five years. Series A: ice-cream sales hover near Rs.10L
with a summer lift of about +Rs.3L every June–July, and the lift size is essentially the same year after
year. Series B: retail electronics sales had a Nov-Dec festive lift of about +Rs.5L in 2020 but +Rs.15L in
2024, growing as the overall sales level grew. Choose additive or multiplicative decomposition for each,
and explain how you decided.
Solution
Series A → Additive (Y = T + S + I). The seasonal swing is a fixed rupee amount (~+Rs.3L)
regardless of the baseline level. The peaks-and-troughs in the plot would look parallel across years.
Series B → Multiplicative (Y = T x S x I). The seasonal swing scales with the level — from +Rs.5L to
+Rs.15L as the trend tripled. Best modelled as a percentage of the current level.
Intuition. Eyeball test: do the seasonal peaks fan out (get wider) as time goes on? If yes — multiplicative. If
they stay parallel — additive. A log transform converts a multiplicative series into an additive one.

Q3 | Moderate
Pick the appropriate smoothing technique for each scenario, and explain. (A) Daily price of a stable
PSU stock — no trend, no seasonality, mostly noise around a steady level. (B) Monthly e-commerce
GMV with a clear upward trend but no holiday spikes (the business is B2B). (C) Quarterly hotel
occupancy in Goa across eight years: occupancy rises year on year and the Oct–Dec quarter is always
the peak. Choose from: 3-point Moving Average, Single Exponential Smoothing (SES), Holt’s double

Predictive Analytics — Practice Set (S2 25-26) Page 2


exponential, or Holt-Winters triple exponential.
Solution
(A) SES (or a small Moving Average). Only a level needs tracking. Formula: Lt = alpha · Yt + (1 −
alpha) · Lt−1. Forecast next period = current level.
(B) Holt’s double exponential. Level + trend, no season. Two recursions:
Lt = alpha · Yt + (1 − alpha) (Lt−1 + bt−1)
bt = beta · (Lt − Lt−1) + (1 − beta) · bt−1
(C) Holt-Winters triple exponential. Level + trend + seasonality (period m = 4 quarters). Adds a
seasonal recursion St = gamma (Yt − Lt) + (1 − gamma) · St−m for the additive form.
Intuition. Match the number of equations to the number of components you see. One (level) → SES. Two
(level + trend) → Holt. Three (level + trend + season) → Holt-Winters. The smoothing ladder is just a
sequence of components.

Q4 | Moderate
Weekly mall footfall (in thousands) for five weeks: 50, 52, 49, 55, 53. Apply Single Exponential
Smoothing with alpha = 0.4 and L1 = 50 (set the first level equal to the first observation). Compute L2,
L3, L4, L5, and the forecast for week 6.
Solution
Recursion: Lt = 0.4 · Yt + 0.6 · Lt−1. Forecast for the next period equals the latest level: Ft+1 = Lt.

L1 = 50 (given).
L2 = 0.4(52) + 0.6(50) = 20.8 + 30.0 = 50.80.
L3 = 0.4(49) + 0.6(50.80) = 19.6 + 30.48 = 50.08.
L4 = 0.4(55) + 0.6(50.08) = 22.0 + 30.048 = 52.048.
L5 = 0.4(53) + 0.6(52.048) = 21.2 + 31.2288 = 52.4288.
F6 = L5 ≈ 52.43 thousand footfalls.
Intuition. alpha is the ‘recency knob’. alpha = 0.4 means 40 percent of the new level comes from this week’s
actual value and 60 percent from the running smoothed level. Larger alpha = more reactive but noisier;
smaller alpha = smoother but laggy.

Q5 | Challenge
A meal-kit subscription company has three years of weekly subscriber counts. Inspection of the plot
shows: (i) gradual growth from about 5,000 to 18,000 subscribers (roughly linear); (ii) every January
(post-holiday) there is a sign-up surge of about +1,500 net new subscribers, and the size of that surge
has stayed roughly the same every year despite the rising baseline; (iii) a sharp dip in Year 2, weeks
30–45, when their mobile app had a critical bug that blocked new sign-ups; (iv) week-to-week noise. (a)
Classify each observed behaviour into Trend / Seasonality / Cyclical / Irregular (or one-off intervention).
(b) Recommend additive vs multiplicative decomposition and justify. (c) Recommend the appropriate
smoothing technique. (d) State one risk of running Holt-Winters on this series without preprocessing.
Solution
(a) Components. Linear-looking growth from 5K to 18K = Trend. Annual January sign-up surge =
Seasonality (fixed yearly period). Sharp Year-2-weeks-30–45 dip due to the app bug = one-off
intervention — it is not seasonal (doesn’t repeat at a fixed cadence) and it is not cyclical (no macro
economic driver); it is a single anomalous episode. Week-to-week random noise = Irregular.

(b) Additive. The seasonal surge has stayed at about +1,500 every year while the baseline tripled
(5K → 18K). The seasonal amplitude is constant in absolute terms, not proportional to level — that is
the hallmark of an additive series. (If the surge had grown to +4,500 as the level tripled, multiplicative
would be right.)

Predictive Analytics — Practice Set (S2 25-26) Page 3


(c) Holt-Winters triple exponential (additive form). Level, trend, and yearly seasonality are all
present.

(d) Risk if you fit Holt-Winters blindly. The Year-2 bug-period dip will be absorbed into the
seasonal indices for weeks 30–45 — meaning future forecasts for weeks 30–45 in Year 4, Year 5 etc.
will be artificially pulled down even though the bug has been fixed. The fix: treat that window as an
intervention — either exclude those weeks from fitting, or add an indicator variable / use outlier-robust
estimation to prevent the anomaly from contaminating the seasonal pattern.
Intuition. Real series rarely fit one clean recipe. The right move is: classify components first, then choose the
family of methods, then handle the one-offs (interventions) before fitting. Skipping the ‘handle one-offs’ step
is the most common production failure.

Predictive Analytics — Practice Set (S2 25-26) Page 4


Topic 2 · Neural Network Diagnostics
Concept map. Two diseases account for almost every ‘my network isn’t learning’ ticket. The first is the
vanishing/exploding gradient: when many layers multiply gradients < 1, the signal that reaches the
early layers vanishes; with gradients > 1 it explodes. Cure: ReLU activations, batch normalisation,
careful initialisation (He / Xavier), residual connections. The second is the bias / variance balance:
high training accuracy and low test accuracy is overfitting (high variance); both being low is
underfitting (high bias). Standard regularisers: dropout, L2 weight decay, early stopping, data
augmentation, smaller architecture.

Q1 | Easy
A team compares four architectures on the same medical-image dataset, trained for 30 epochs each
with default settings:
· Model A: 4 layers, sigmoid → 86% train, 81% test.
· Model B: 4 layers, ReLU → 89% train, 84% test.
· Model C: 20 layers, sigmoid → 7% train, 6% test.
· Model D: 20 layers, ReLU + batch normalisation → 93% train, 88% test.
Explain in plain English why Model C catastrophically fails while Models A, B, and D all work. What does
this comparison tell you about design choices for deep networks?
Solution
The story is about gradient flow through depth. Backpropagation multiplies activation derivatives
layer by layer. Whether the gradient survives to the first layer depends on (i) the activation function
and (ii) how many layers it has to pass through.

Model A (4 layers, sigmoid). Sigmoid’s derivative tops out at 0.25. Over 4 layers the gradient is
bounded by 0.254 ≈ 0.004 — small but not zero, so learning is slow but possible.
Model B (4 layers, ReLU). ReLU’s derivative is 1 for active inputs — gradient flows freely. Better
than A.
Model C (20 layers, sigmoid). 0.2520 ≈ 9.1 × 10−13. Gradients reaching early layers are essentially
zero — this is the vanishing-gradient problem. Early layers never learn; the model performs at
random.
Model D (20 layers, ReLU + batch norm). ReLU keeps the derivative healthy; batch norm keeps
pre-activations centred so ReLUs stay in the active range. Depth then helps instead of hurting.

Lesson. ‘Deeper is better’ is only true if gradients can survive the depth. The right design pattern for
deep networks is ReLU-family activations + batch (or layer) normalisation + careful
initialisation. Sigmoid is fine for shallow networks or the final output layer of a binary classifier, but
stacking many sigmoid layers kills the gradient.
Intuition. Sigmoid is fine for the final layer of a binary classifier (you want a probability there). It is rarely the
right choice for hidden layers in deep networks — the multiplication of small derivatives kills the gradient.

Q2 | Easy
A model reports 98 percent training accuracy and 70 percent test accuracy. Name the condition.
Suggest three specific, distinct fixes.
Solution
Condition: Overfitting (high variance). The model has fitted noise in the training set rather than the
underlying signal.

Three fixes.
(1) Regularisation — add L2 weight decay (lambda ≈ 1e−4) or dropout (p between 0.3 and 0.5) so
the network cannot lean too hard on any one weight.

Predictive Analytics — Practice Set (S2 25-26) Page 5


(2) Early stopping — track validation loss and stop training when it stops improving (patience of
5–10 epochs).
(3) More data or data augmentation — if the dataset is small, this is the highest-leverage fix.
Geometric transforms for images, synonym replacement for text, SMOTE for tabular minority classes.
Intuition. If you can only do one thing fast, try early stopping with a validation split — it is essentially free and
immediately reduces the train-test gap.

Q3 | Moderate
Choose the appropriate output-layer activation and loss function for each task. (a) Spam vs not-spam
classification. (b) Multi-class classification across 50 product categories where each image has exactly
one label. (c) Multi-label genre tagging where a movie may simultaneously be action, drama, and sci-fi.
(d) Predicting house price in lakhs of rupees.
Solution
(a) Sigmoid + binary cross-entropy. Sigmoid outputs a value in (0,1) interpretable as P(spam).
Cross-entropy is the natural loss for a Bernoulli outcome.
(b) Softmax + categorical cross-entropy. Softmax forces the 50 outputs to sum to 1 and behave as
a probability distribution — ideal when exactly one class is correct.
(c) Per-output sigmoid + binary cross-entropy per label. The labels are independent yes/no
questions, so you do NOT want softmax (which forces them to compete). Train each output as its own
binary classifier.
(d) Linear activation + MSE (or MAE) loss. Price is a continuous real number; no squashing is
needed at the output. MAE is more robust to outliers; MSE penalises large errors more.
Intuition. Choose the activation by what the output represents. One probability → sigmoid. A distribution
over K → softmax. K independent yes/nos → K sigmoids. A real number → linear.

Q4 | Moderate
For each loss curve, name the problem and recommend a fix. (A) Training loss decreasing steadily;
validation loss going up after epoch 10. (B) Training loss flat from epoch 1 and never improves. (C) Both
training and validation loss plateau near the loss of a random classifier.
Solution
(A) Overfitting starting at epoch 10. Apply early stopping at epoch 10; add dropout (0.3–0.5) or L2
weight decay; collect more data or augment.
(B) Learning failure. Likely vanishing gradient (deep sigmoid stack), bad weight initialisation, or
learning rate set way too small / way too large. Try ReLU, He init, and sweep learning rates in a log
range (e.g., 1e−5 to 1e−1).
(C) Underfitting (high bias). The model is not capable of expressing the function. Either the
architecture is too small/shallow, or features carry no signal. Increase capacity (more layers / units),
engineer richer features, sanity-check labels and data pipeline.
Intuition. Curves first, hyperparameters second. Always plot training and validation loss together — the
shape of the gap diagnoses the disease.

Q5 | Challenge
A B2B SaaS company trains a 6-layer dense neural network with 256 units per layer (ReLU activations,
no dropout, no batch norm) on 8,000 historical sales-opportunity records (25 features) to predict
whether a deal will close. Results: training accuracy 97 percent, test accuracy 64 percent, F1 on the
positive (won-deal) class only 0.31. A gradient boosted tree (XGBoost) on the same data scores test
accuracy 79 percent and F1 of 0.52. (i) Identify the two issues happening at once. (ii) Recommend four
specific interventions tailored to this dataset size and class imbalance.
Solution

Predictive Analytics — Practice Set (S2 25-26) Page 6


(i) Two issues.
1. Severe overfitting. The 97 / 64 split is a 33-point train-test gap. A 6 × 256 dense network has
roughly 400,000 parameters — with only 8,000 rows and 25 features, that is approximately 50
parameters per row, vastly over-parameterised. The model memorises noise.
2. Wrong tool for tabular data. On structured tabular datasets, gradient-boosted trees consistently
outperform deep neural networks; XGBoost beating the deep net by 15 points test accuracy is not a
fluke. Trees naturally handle non-linear feature interactions and mixed types without needing huge
amounts of data.

Class imbalance is also signalled by the much lower F1 (0.31) vs accuracy (0.64) — won deals are a
minority class and the model is rewarded for predicting the majority.

(ii) Four interventions.


(1) Shrink the network or switch frameworks. Either drop to 2–3 layers of 32–64 units, or accept
that XGBoost is the right tool for this dataset and ship it instead. Simpler model that wins is the model
that wins.
(2) Regularise heavily. Add dropout 0.3–0.5 between layers and L2 weight decay 1e−4 to 1e−3. With
only 8,000 rows, the regularisation needs to be aggressive.
(3) Address class imbalance directly. Use class weights (inverse-frequency) in the loss, or
oversample the minority class with SMOTE. Switch the monitored metric from accuracy to F1 or
AUPRC so the model is rewarded for getting the minority class right.
(4) Early stopping based on validation F1 (not accuracy), patience 5–10 epochs, restoring best
weights. Also standardise the 25 features and add batch normalisation between layers if you keep the
neural network.
Intuition. ‘Deeper is better’ is a myth for tabular data. On structured datasets, gradient-boosted trees and
well-regularised shallow nets usually beat deep MLPs. Always benchmark against a simple baseline first.

Predictive Analytics — Practice Set (S2 25-26) Page 7


Topic 3 · Clustering (K-Means & DBSCAN)
Concept map. K-Means minimises WCSS (within-cluster sum of squares) by assigning each point to
its nearest centroid; you must specify k. The trick is to read the elbow of the WCSS curve, since WCSS
always falls as k grows (it hits zero at k = N). DBSCAN defines a cluster as a maximal set of
density-connected points — no centroids, no need to set k, can discover non-convex shapes, and labels
low-density points as noise (−1). Its tunables are eps (neighbourhood radius) and min_samples
(core-point threshold). Both methods break down without proper feature scaling.

Q1 | Easy
A junior analyst plots WCSS against k for k = 1 to 15. The curve drops steeply and then flattens. They
ask: (i) ‘If I keep increasing k, can WCSS ever start to go up again?’ (ii) ‘If lower WCSS means tighter
clusters, why don’t we just pick a really big k?’ Answer both questions clearly in 3–4 sentences each.
Solution
(i) No — WCSS is monotonically non-increasing in k. Adding a centroid can never hurt: in the
worst case the new centroid sits on top of an existing one and WCSS is unchanged. Usually it lands
somewhere that reduces some point-to-centroid distances, strictly lowering WCSS. So the curve only
ever goes down (or flat) — it cannot bend upward.

(ii) Because tighter does not mean better — it means more fragmented. Push k all the way to N
(the number of points) and every point becomes its own centroid, giving WCSS = 0 with N ‘clusters’ of
size one. That is mathematically tight but useless: every customer is their own segment, nobody to
market to collectively. The honest goal is to balance tightness against parsimony. Look for the elbow
of the curve — the k after which extra clusters buy almost no additional tightness — or use silhouette
score, which rewards tightness and separation between clusters.
Intuition. Every monotonic curve has a smallest point at the end. Whenever you must ‘balance fit and
complexity,’ suspect the smallest (or largest) value of the metric is misleading you.

Q2 | Easy
For k = 1 to 8, a K-Means run on customer data gives WCSS values 2400, 1500, 900, 580, 530, 510,
500, 495. Recommend k using the elbow method, with each step shown.
Solution
Compute the marginal drops (how much WCSS decreases when you add the next cluster).

k = 1 → 2: ∆ = 900 (big)
k = 2 → 3: ∆ = 600 (big)
k = 3 → 4: ∆ = 320 (meaningful)
k = 4 → 5: ∆ = 50 (sharp slowdown)
k = 5 → 6: ∆ = 20
k = 6 → 7: ∆ = 10
k = 7 → 8: ∆ = 5

The marginal benefit collapses from 320 to 50 as you pass k = 4. The curve clearly flattens after k = 4
— that is the elbow. Choose k = 4. Confirm with silhouette score if needed.
Intuition. The elbow is where the ‘hand-claw’ bends. If two candidate k values look equally plausible, fall
back on silhouette score, gap-statistic, or downstream business interpretability.

Q3 | Moderate
Why does K-Means struggle on a ‘two interlocking moons’ shape, and which alternative algorithm
handles it well? Explain in terms of how each algorithm defines a cluster.

Predictive Analytics — Practice Set (S2 25-26) Page 8


Solution
K-Means’s definition of a cluster is ‘all points closer to centroid ck than to any other centroid’. The
resulting cluster boundaries are straight lines (a Voronoi tessellation), which can only carve space into
convex, blob-shaped regions. A moon curves around the other moon — no single centroid can
describe a moon’s middle, and any straight boundary will cut both moons in half.

DBSCAN’s definition is ‘a maximal set of points that are density-connected: you can walk from any
point to any other through neighbourhoods of radius eps that each contain at least min_samples
points’. Shape does not matter — if you can follow a dense trail of points around the moon, you stay
in the cluster. So DBSCAN (and other density-based methods) recover the two moons cleanly.
Intuition. Rule of thumb. K-Means cuts space with straight lines. DBSCAN follows density along whatever
shape the data takes. Pick the algorithm whose ‘definition of a cluster’ matches the geometry you expect.

Q4 | Moderate
A team applies DBSCAN to a geospatial dataset of 12,000 cell-phone tower locations across India,
using only latitude and longitude as features. They set eps = 2 and min_samples = 10 and report:
‘DBSCAN found only 3 huge blob clusters and almost no noise.’ (i) What does this output tell you about
the parameter choice? (ii) What is wrong with measuring eps in raw degrees of latitude / longitude? (iii)
Outline the right way forward.
Solution
(i) eps is far too large. When DBSCAN merges everything into a few giant blobs with negligible
noise, it means almost every point is within eps of almost every other point. That is the over-merge
failure mode (the opposite of the ‘too small → everything is noise’ failure). 2 degrees of latitude
corresponds to roughly 220 km — an enormous radius when towers in the same city sit within a few
hundred metres of each other.

(ii) Raw degrees are misleading for distance. 1 degree of latitude is about 111 km everywhere, but
1 degree of longitude is 111 km only at the equator and shrinks to zero at the poles (it is about 96 km
at Mumbai’s latitude). Euclidean distance on raw lat/long is geometrically inconsistent. Either convert
to a metric projection (e.g., UTM coordinates in metres) or use haversine distance directly, where eps
can be expressed in kilometres.

(iii) Right way forward.


Step 1. Project coordinates to a metric system, or use DBSCAN with haversine distance — then eps
is in kilometres, which is interpretable.
Step 2. Decide what cluster size makes business sense. A ‘cluster of towers in a metro area’ might
span 10–30 km — that is a reasonable eps to try.
Step 3. Set min_samples = 10–20 (a real city typically has many towers; small clusters of fewer than
10 towers can be treated as noise / rural).
Step 4. Use the k-distance plot in the metric space to refine eps — find the knee.
Step 5. Validate by overlaying the resulting clusters on a map. They should look like cities, not like
state-sized blobs.
Intuition. DBSCAN’s success depends on the distance metric matching the data’s geometry. Lat/long in
degrees, mixed-unit features without scaling, and ordinal categorical codes treated as numbers are all
common ways the metric goes wrong. Get the metric right first; only then tune eps and min_samples.

Q5 | Challenge
A fraud-analytics team has 200,000 transactions, each with 25 numeric features (amount, time-of-day,
location-distance, device flags, etc.). Fraud is rare (~1 percent), and intuitively fraud forms small tight
pockets while normal transactions occupy big diffuse regions. (a) Argue for K-Means or DBSCAN as the
better fit. (b) Give a step-by-step recipe to apply your chosen method (preprocessing, parameters,

Predictive Analytics — Practice Set (S2 25-26) Page 9


validation).
Solution
(a) DBSCAN is the better fit.
· K-Means centroids are pulled by mass. With normal transactions outnumbering fraud 99:1, every
K-Means centroid will sit inside the normal mass, and fraud will be absorbed into the nearest big
cluster. No useful separation.
· K-Means assumes convex blobs. Fraud and normal regions overlap in many features — no clean
blob structure.
· DBSCAN was designed to find dense pockets in low-density background and to flag everything else
as noise. Small tight fraud pockets become high-precision clusters; the bulk of normal transactions
either merge into mega-clusters or fall on the boundary — both are informative.
· DBSCAN does not require k, which the team has no way to set in advance.

(b) Recipe.
1. Clean. Drop IDs, impute / drop missing values, one-hot encode categoricals.
2. Scale. StandardScaler on all 25 features. Non-negotiable for distance-based methods.
3. min_samples starting point = 2 × 25 = 50. (Larger values make the algorithm more conservative;
smaller values find smaller pockets but admit more noise.)
4. Pick eps via a k-distance plot with k = min_samples − 1 = 49. Sort distances, find the knee, set
eps at the y-value there.
5. Run DBSCAN(eps, min_samples). Inspect noise share. If > 90 percent noise, eps was too small
or min_samples too large; loosen both and re-plot.
6. Validate on labels (if available). For each cluster, compute the share of known fraud. The
smallest dense clusters should have very high fraud purity — that is the success signal.
7. Productionise. Score new transactions by their nearest-core distance / density; flag any that
DBSCAN would label noise for human review.
Intuition. Algorithm choice mirrors data geometry. Many imbalanced minorities, small dense pockets,
unknown k → DBSCAN. Roughly balanced, blob-shaped segments with known k → K-Means.

Predictive Analytics — Practice Set (S2 25-26) Page 10


Topic 4 · Naive Bayes Classification
Concept map. Naive Bayes applies Bayes’s rule with a strong independence assumption:
P(C | X1,...,Xn) ∝ P(C) · P(X1 | C) · P(X2 | C) · ... · P(Xn | C).
Estimate each piece by simple counting from the training data: the prior P(C) is the class frequency;
each likelihood P(Xi = v | C) is (rows with that value among C) / (rows of C). Predict the class with the
largest product. If any required cell is zero, the entire product is zero — cure this with Laplace (add-1)
smoothing: (count + 1) / (class_total + V), where V is the number of possible values for that feature.

Q1 | Easy
Why is the algorithm called ‘Naive’? State the independence assumption it makes and explain in two
sentences why the algorithm is often called ‘wrong but useful’.
Solution
The naive assumption. Given the class, the features are conditionally independent:
P(X1, X2, ..., Xn | C) = P(X1 | C) · P(X2 | C) · ... · P(Xn | C). In real data, features are often correlated
(income and education, for example), so the assumption is wrong.

Why it still works. Classification only needs the ranking of class posteriors to be correct, not their
exact values. As long as the relative ordering of P(C | X) across classes is preserved, the argmax
remains correct — even if the absolute probabilities are off. Naive Bayes is also fast, robust to small
datasets, and surprisingly competitive in text-classification problems where features (words) are
high-dimensional but weakly correlated.

Q2 | Easy
A small dataset has 20 emails: 8 are Spam, 12 are Ham. Among the Spam emails, 6 contain the word
‘free’; among the Ham emails, 2 contain ‘free’. (a) Compute the priors P(Spam) and P(Ham). (b)
Compute the likelihoods P(free | Spam) and P(free | Ham). (c) Using only the word ‘free’, classify an
email that contains it.
Solution
(a) Priors. P(Spam) = 8 / 20 = 0.40. P(Ham) = 12 / 20 = 0.60.

(b) Likelihoods. P(free | Spam) = 6 / 8 = 0.750. P(free | Ham) = 2 / 12 ≈ 0.167.

(c) Posterior numerators (we can ignore the common denominator P(free) when comparing
classes):
P(Spam | free) ∝ 0.40 × 0.750 = 0.300.
P(Ham | free) ∝ 0.60 × 0.167 = 0.100.
0.300 > 0.100 ⇒ classify as Spam.
Intuition. The prior favoured Ham (more Ham emails overall), but the much stronger likelihood of ‘free’ given
Spam (0.75 vs 0.17) flipped the decision. Naive Bayes is a tug-of-war between prior and likelihood.

Q3 | Moderate
A dataset of 10 movies (training set below) records Star, Budget, and Season, with class Genre ∈ {Hit,
Flop}. Using Naive Bayes without smoothing, classify a new movie with Star = A-list, Budget = Medium,
Season = Festive. Show every step.
Movie Star Budget Season Genre
1 A-list High Festive Hit
2 A-list Medium Normal Hit
3 Newcomer Low Normal Flop

Predictive Analytics — Practice Set (S2 25-26) Page 11


4 A-list High Normal Hit
5 Newcomer Medium Festive Flop
6 A-list Low Normal Flop
7 Newcomer High Festive Hit
8 A-list Medium Festive Hit
9 Newcomer Low Festive Flop
10 Newcomer Medium Normal Flop

Solution
Step 1. Count classes. Hits = {1, 2, 4, 7, 8} = 5. Flops = {3, 5, 6, 9, 10} = 5. Priors: P(Hit) = P(Flop) =
0.5.

Step 2. Likelihoods for Hits (denominator = 5).


· P(Star = A-list | Hit) = 4/5 = 0.80 (movies 1, 2, 4, 8).
· P(Budget = Medium | Hit) = 2/5 = 0.40 (movies 2, 8).
· P(Season = Festive | Hit) = 3/5 = 0.60 (movies 1, 7, 8).

Step 3. Likelihoods for Flops (denominator = 5).


· P(Star = A-list | Flop) = 1/5 = 0.20 (movie 6).
· P(Budget = Medium | Flop) = 2/5 = 0.40 (movies 5, 10).
· P(Season = Festive | Flop) = 2/5 = 0.40 (movies 5, 9).

Step 4. Posterior numerators.


P(Hit | X) ∝ 0.5 × 0.80 × 0.40 × 0.60 = 0.0960.
P(Flop | X) ∝ 0.5 × 0.20 × 0.40 × 0.40 = 0.0160.

0.0960 > 0.0160 ⇒ predict Hit.


Intuition. Look at which factor dominates: P(A-list | Hit) = 0.80 vs P(A-list | Flop) = 0.20 — a 4x ratio in favour
of Hit. That single feature is doing most of the lifting; festive season helps too.

Q4 | Moderate
On the same dataset, classify a movie with Star = Newcomer, Budget = High, Season = Normal. Show
that without smoothing, one of the likelihoods is zero and forces the posterior to zero. Then apply
Laplace (add-1) smoothing with V = number of possible values for each feature, and reclassify.
Solution
Zero detection. For Flops, look up Budget = High: movies that are Flop AND Budget = High — there
are none. So unsmoothed P(High | Flop) = 0/5 = 0, which zeros the entire P(Flop | X) regardless of
other evidence. That is unfair — the dataset just did not happen to contain this combination.

Laplace smoothing. Replace each likelihood by (count + 1) / (class_total + V), where V is the
number of distinct values for that feature in the dataset.
· Star has 2 values (A-list, Newcomer) → V = 2.
· Budget has 3 values (High, Medium, Low) → V = 3.
· Season has 2 values (Festive, Normal) → V = 2.

Smoothed likelihoods, Hits (5 movies).


P(Newcomer | Hit) = (1 + 1)/(5 + 2) = 2/7 ≈ 0.286 (movie 7).
P(High | Hit) = (2 + 1)/(5 + 3) = 3/8 = 0.375 (movies 1, 4).
P(Normal | Hit) = (2 + 1)/(5 + 2) = 3/7 ≈ 0.429 (movies 2, 4).

Predictive Analytics — Practice Set (S2 25-26) Page 12


Smoothed likelihoods, Flops (5 movies).
P(Newcomer | Flop) = (4 + 1)/(5 + 2) = 5/7 ≈ 0.714.
P(High | Flop) = (0 + 1)/(5 + 3) = 1/8 = 0.125.
P(Normal | Flop) = (3 + 1)/(5 + 2) = 4/7 ≈ 0.571.

Posterior numerators.
P(Hit | X) ∝ 0.5 × 0.286 × 0.375 × 0.429 ≈ 0.0230.
P(Flop | X) ∝ 0.5 × 0.714 × 0.125 × 0.571 ≈ 0.0255.

0.0255 > 0.0230 ⇒ predict Flop (close call).


Intuition. Laplace smoothing pretends you saw one example of every feature-value in every class. It costs
almost nothing on large datasets and saves you from one missing combination ruining a prediction.

Q5 | Challenge
Using the movie dataset above with Laplace smoothing, classify a movie with Star = Newcomer, Budget
= Low, Season = Festive. Then answer: if you could change exactly one feature value of this input,
which change would flip the prediction? Show the calculation.
Solution
Base case. Star = Newcomer, Budget = Low, Season = Festive.
Hits likelihoods (Laplace, V = 2, 3, 2):
· P(Newcomer | Hit) = 2/7 ≈ 0.286.
· P(Low | Hit) = (0 + 1)/(5 + 3) = 1/8 = 0.125 (no Hit has Low budget).
· P(Festive | Hit) = (3 + 1)/(5 + 2) = 4/7 ≈ 0.571.
P(Hit | X) ∝ 0.5 × 0.286 × 0.125 × 0.571 ≈ 0.0102.

Flops likelihoods:
· P(Newcomer | Flop) = 5/7 ≈ 0.714.
· P(Low | Flop) = (3 + 1)/(5 + 3) = 4/8 = 0.5 (movies 3, 6, 9).
· P(Festive | Flop) = (2 + 1)/(5 + 2) = 3/7 ≈ 0.429.
P(Flop | X) ∝ 0.5 × 0.714 × 0.5 × 0.429 ≈ 0.0766.

Flop wins, decisively (about 7.5x).

Which single change flips the prediction? Try each one in turn.
Change A — Star: Newcomer → A-list.
P(Hit) ∝ 0.5 × (4+1)/7 × 1/8 × 4/7 = 0.5 × 0.714 × 0.125 × 0.571 ≈ 0.0255.
P(Flop) ∝ 0.5 × (1+1)/7 × 4/8 × 3/7 = 0.5 × 0.286 × 0.5 × 0.429 ≈ 0.0306.
Flop still wins, but the gap collapses.

Change B — Budget: Low → High.


P(Hit) ∝ 0.5 × 2/7 × (2+1)/8 × 4/7 = 0.5 × 0.286 × 0.375 × 0.571 ≈ 0.0306.
P(Flop) ∝ 0.5 × 5/7 × (0+1)/8 × 3/7 = 0.5 × 0.714 × 0.125 × 0.429 ≈ 0.0191.
Hit now wins. So changing Budget from Low to High flips the prediction.

Change C — Season: Festive → Normal.


P(Hit) ∝ 0.5 × 2/7 × 1/8 × 3/7 ≈ 0.00765.
P(Flop) ∝ 0.5 × 5/7 × 4/8 × 4/7 ≈ 0.1020. Flop wins by even more.

Conclusion. The single most influential feature here is Budget. Switching Low → High moves

Predictive Analytics — Practice Set (S2 25-26) Page 13


Hit-vs-Flop because the training data has many high-budget hits but no high-budget flops (the
smoothing absorbs the zero).
Intuition. Sensitivity analysis matters on small datasets — if a single feature flip can change the prediction,
the model is not very robust. Collect more data, especially for under-represented combinations.

Predictive Analytics — Practice Set (S2 25-26) Page 14


Topic 5 · ROC, AUC & Threshold Selection
Concept map. A binary classifier outputs a probability; you turn it into a label by picking a threshold.
Different thresholds give different counts of True Positives (TP), False Positives (FP), True Negatives
(TN), and False Negatives (FN). The ROC curve plots TPR = TP / (TP + FN) (recall) on the y-axis
versus FPR = FP / (FP + TN) on the x-axis as the threshold sweeps from 1 down to 0. AUC is the area
under that curve; AUC = 1 is perfect, 0.5 is random. A lower threshold catches more positives but raises
false alarms; a higher threshold is the opposite. The right threshold depends on the cost of FP vs FN,
not on accuracy.

Q1 | Easy
A churn model is applied to 100 customers. The actual number of churners is 30. The model flags 40 as
‘will churn’; of those, 25 actually do churn. Compute TP, FP, TN, FN, TPR, FPR, and Precision.
Solution
Actual positives (churners) = 30, actual negatives = 70. Predicted positives = 40, predicted negatives
= 60.

· TP = predicted churn AND actual churn = 25.


· FP = predicted churn AND NOT actual churn = 40 − 25 = 15.
· FN = predicted NOT churn AND actual churn = 30 − 25 = 5.
· TN = predicted NOT churn AND NOT actual churn = 70 − 15 = 55.
Check: 25 + 15 + 5 + 55 = 100. ✓

· TPR (Recall) = TP / (TP + FN) = 25 / 30 ≈ 0.833.


· FPR = FP / (FP + TN) = 15 / 70 ≈ 0.214.
· Precision = TP / (TP + FP) = 25 / 40 = 0.625.
Intuition. Three questions, three metrics. Recall asks ‘of all real churners, how many did I catch?’ Precision
asks ‘of those I flagged, how many were right?’ FPR asks ‘of all non-churners, how many did I wrongly
flag?’.

Q2 | Easy
Interpret each AUC and recommend the model to deploy. Model A: AUC = 0.50. Model B: AUC = 0.78.
Model C: AUC = 0.93. Model D: AUC = 0.20.
Solution
· A (0.50). Random guessing — no discriminative power.
· B (0.78). Reasonable separation, useful baseline.
· C (0.93). Strong discriminator. Verify with cross-validation and a cost-aware metric before
production.
· D (0.20). Worse than random, but systematically — its predictions are backwards. Flipping the labels
would give AUC = 0.80. Investigate why predictions are inverted (label swap? sign of a coefficient?).

Deploy Model C, after sanity checking.


Intuition. AUC below 0.5 is not random — it is signal pointing the wrong way. Random is exactly 0.5.

Q3 | Moderate
An insurance claims-fraud model is evaluated at its default threshold of 0.50 on 500 claims, yielding TP
= 120, FP = 80, FN = 30, TN = 270. (a) Compute Recall, Precision, F1, FPR, and Accuracy. (b) If the
team raises the threshold to make the model stricter, in which direction do TP, FP, FN, TN typically
move, and why? (c) The audit team says: ‘every undetected fraudulent claim costs us 8 times what it
costs to investigate an honest claim.’ Compute the cost at the current threshold; then say whether

Predictive Analytics — Practice Set (S2 25-26) Page 15


lowering the threshold to a setting that gives TP = 140, FP = 140, FN = 10, TN = 210 would be worth it.
Solution
(a) Metrics at threshold 0.50 (population = 500; actual fraud = 150; actual honest = 350):
· Recall = TP / (TP + FN) = 120 / 150 = 0.800.
· Precision = TP / (TP + FP) = 120 / 200 = 0.600.
· F1 = 2 · P · R / (P + R) = 2 · 0.6 · 0.8 / (0.6 + 0.8) = 0.96 / 1.4 ≈ 0.686.
· FPR = FP / (FP + TN) = 80 / 350 ≈ 0.229.
· Accuracy = (TP + TN) / 500 = 390 / 500 = 0.780.

(b) Effect of raising the threshold. A higher threshold means the model needs to be more confident
before flagging a claim as fraud. So fewer claims get flagged in total — some of the points the model
was barely confident about move from the predicted-positive side to the predicted-negative side.
Among those, some were true frauds (so TP drops, FN rises) and some were honest claims (so FP
drops, TN rises). Net effect: TP ↓, FP ↓, FN ↑, TN ↑. Recall falls; precision usually rises.

(c) Cost analysis. Set the cost of investigating an honest claim (FP) to 1 unit; cost of missing a fraud
(FN) = 8 units.
Total cost = 8 · FN + 1 · FP.
· Current threshold (0.50): 8 · 30 + 80 = 240 + 80 = 320.
· Proposed lower threshold: 8 · 10 + 140 = 80 + 140 = 220.
220 < 320, so the lower threshold saves 100 cost units (about 31 percent lower total cost). Yes,
switch to it.

Notice what happened to the headline metrics: accuracy went from 0.78 to (140 + 210)/500 = 0.70 —
accuracy got worse even though cost got better. That is why accuracy is the wrong objective when FN
and FP carry different costs.
Intuition. Accuracy is the wrong objective whenever FP and FN cost different amounts. Translate the
business cost into an explicit FN/FP weighting before you pick a threshold.

Q4 | Moderate
For each use case, decide whether Precision or Recall matters more, and whether the threshold should
be set high or low. Justify. (A) An email spam filter where a legitimate email lost is far worse than a
missed spam. (B) A cancer screening system where a missed cancer is catastrophic and a false
positive only triggers another (safe) test.
Solution
(A) Spam filter → favour Precision → threshold high. A false positive (a real email classified as
spam) is the costly error. Pushing the threshold up means the model must be very confident before
flagging, which reduces false alarms at the cost of letting through some spam.

(B) Cancer screening → favour Recall → threshold low. A false negative (a real cancer missed) is
the catastrophic error. Lowering the threshold flags more cases, including some false alarms —
acceptable because the follow-up test catches them with no real harm.

General rule. Precision protects against false alarms; recall protects against missed positives. Set
the threshold by which kind of error you cannot afford.
Intuition. F1 (the harmonic mean of precision and recall) is a tempting ‘single number’ metric, but it implicitly
assumes FP and FN are equally costly. If they are not — use weighted F-beta or an explicit cost matrix.

Q5 | Challenge
For a fraud detection problem the team can only afford to review the top 10 percent of flagged
transactions (i.e., they need FPR ≤ 0.10). Four models are available: M1 has AUC 0.82 and a smooth

Predictive Analytics — Practice Set (S2 25-26) Page 16


curve hugging the top-left. M2 has AUC 0.79; at FPR = 0.10 its TPR = 0.70. M3 has AUC 0.85; at FPR =
0.10 its TPR = 0.45. M4 has AUC 0.65, mostly along the diagonal. Which model would you deploy, and
why is AUC alone insufficient to make the call?
Solution
The constraint matters. The team can only operate at FPR ≤ 0.10. AUC is an average over all
possible thresholds, so a high AUC can come from strong performance in regions you cannot use.

Reading the curves at FPR = 0.10 (the operating point):


· M2: TPR = 0.70 — catches 70 percent of fraud.
· M1: TPR ≈ 0.60 (consistent with a smooth top-left curve and AUC 0.82).
· M3: TPR = 0.45 — high AUC, but its strength is in the FPR > 0.10 region the team cannot reach.
· M4: TPR ≈ 0.10 — barely better than random.

Deploy M2. It dominates in the constrained operating region.

Why AUC alone is insufficient. Two models can share an AUC but differ wildly in where on the
curve their advantage lies. Always plot the curves and pick on the threshold region you can actually
deploy in. A complementary metric is Partial AUC — AUC restricted to a specified FPR range —
which formalises this idea.
Intuition. Always state the operating constraint before picking a model. ‘Top-k review queue’, ‘cap on false
alarms per day’, ‘minimum recall’ are all operating constraints that change the answer.

Predictive Analytics — Practice Set (S2 25-26) Page 17


Topic 6 · Principal Component Analysis
Concept map. PCA finds new axes (Principal Components) that are linear combinations of original
features, ordered by the variance they explain. PC1 is the direction of maximum variance; PC2 is
perpendicular to PC1 with the next largest variance, and so on. The scree plot of
variance-explained-per-PC reveals an ‘elbow’; components before the elbow carry signal, components
after are mostly noise. Always standardise features first — PCA chases variance, and without scaling
the feature with the largest unit dominates. The number of components to keep is a trade-off between
variance retained and complexity reduction; the right answer is downstream-task-dependent.

Q1 | Easy
A customer dataset has three features: age (years, 18 to 80), income (rupees, 30,000 to 2,000,000),
and number of children (0 to 5). PCA is applied without standardisation. What goes wrong, and what is
the fix?
Solution
What goes wrong. PCA maximises variance in the projected axes. Income’s raw variance is many
orders of magnitude larger than age’s or children’s — not because income carries more information,
but because rupees and years and counts are different units. PC1 will essentially align with income,
regardless of whether income is the most informative feature for the downstream task. The PCs
become measurements of unit choice, not of structure.

Fix. Standardise each feature to mean 0 and standard deviation 1 (z-score) before PCA. Then every
feature contributes a variance of 1 to the total, and the PCs reflect the correlation structure of the
data, not the units.
Intuition. PCA cares about spread. Until you put all features on the same scale, ‘spread’ measures unit
choice. Standardise first, every time.

Q2 | Easy
The variance explained per principal component is 0.40, 0.20, 0.12, 0.08, 0.06, 0.05, 0.04, 0.03, 0.02.
(a) How many PCs are needed for ≥ 80 percent variance? For ≥ 95 percent? (b) Is the ‘95 percent rule’
always the right choice?
Solution
(a) Cumulative variance.
PC1: 0.40 · PC2: 0.60 · PC3: 0.72 · PC4: 0.80 · PC5: 0.86 · PC6: 0.91 · PC7: 0.95 · PC8: 0.98 ·
PC9: 1.00.

80 percent ⇒ 4 PCs. 95 percent ⇒ 7 PCs.

(b) The 95-percent rule is not universal.


· For 2-D visualisation, 2 PCs even at 60 percent variance is often more useful than 7 PCs.
· For downstream regularised models, extra PCs are essentially free; you can be liberal.
· PC5–PC7 here each add 3–6 percent — consider the scree elbow and the downstream task before
committing.
· Always validate by cross-validating the downstream model with different k values.

Q3 | Moderate
You have a 50-feature genomics dataset and the PCA variance-explained per component is 25, 18, 12,
8, 5, 4, 3, 3 percent, then a long slow tail. Three rules of thumb exist for choosing how many
components to keep: (i) the ‘visualisation rule’ (keep 2 or 3 for scatter plotting), (ii) the ‘Kaiser’s rule’
(keep PCs whose variance is above the average original-feature variance, i.e. variance ratio > 1/p), (iii)
the ‘95 percent rule’. Apply each rule, then state how many PCs you would actually keep for a

Predictive Analytics — Practice Set (S2 25-26) Page 18


downstream classifier and how you would defend that number.
Solution
Apply each rule.
(i) Visualisation rule ⇒ keep 2 or 3 PCs — cumulative variance 43–55 percent. Plenty for a scatter
plot, far too little for a model.

(ii) Kaiser’s rule (on standardised data, total variance = p = 50, so threshold per PC = 1/50 = 2 percent
of total variance). Counting PCs at or above 2 percent: PC1 (25), PC2 (18), PC3 (12), PC4 (8), PC5
(5), PC6 (4), PC7 (3), PC8 (3) all qualify; the long tail almost certainly falls below 2 percent. Keep
about 8 PCs, covering 78 percent variance.

(iii) 95 percent rule. Through PC8 we have 78 percent. The tail adds 1–2 percent per PC, so reaching
95 percent likely takes about 25–30 PCs. That gives little dimensionality reduction and drags in many
noisy directions.

What I would actually do. Keep around 8–10 PCs (roughly Kaiser’s answer, near the scree elbow at
PC8–PC9). Then defend the number empirically: run the downstream classifier with k ∈ {3, 5, 8, 10,
12, 15, 20} components and pick the k with the best cross-validated metric. PCA is preprocessing —
‘right number of components’ is whichever best serves the next stage of the pipeline.

Q4 | Moderate
A wellness app collects two features per user: X1 = average daily caffeine intake (mg) and X2 =
average nightly hours of sleep. PCA yields PC1 loading = (+0.71, −0.71) and PC2 loading = (+0.71,
+0.71). Interpret each component in plain English. Describe a user who scores high on PC1 and a user
who scores high on PC2.
Solution
Loadings tell you which features pull the PC up.
· PC1 = +0.71 · X1 + (−0.71) · X2 — rises when caffeine is high and sleep is low. It is a contrast /
trade-off axis: ‘wired and sleep-deprived’.
· PC2 = +0.71 · X1 + (+0.71) · X2 — rises when caffeine is high and sleep is high. It is a composite
axis — broadly ‘high consumption of both’ / a high-intake lifestyle.

High PC1 user: drinks a lot of coffee and barely sleeps — the classic over-caffeinated insomniac.
High PC2 user: consumes plenty of caffeine but still sleeps well — a high-activity profile where intake
and rest both run high. Low PC2: low on both — a minimal-consumption lifestyle.

Rule of thumb. Same-sign loadings ⇒ composite scale. Opposite-sign loadings ⇒ trade-off /


contrast scale.

Q5 | Challenge
A clinical research team runs PCA on 60 measured biomarkers from 4,000 patients. The variance
explained per principal component is: PC1: 18%, PC2: 11%, PC3: 8%, PC4: 6%, PC5: 5%, PC6: 4%,
PC7: 3%, PC8: 3%, PC9: 2%, then a long thin tail. (a) Compute the cumulative variance up to PC9 and
apply both Kaiser’s rule and the 95 percent rule to recommend a number of components. (b)
Recommend the number of PCs you would use for a downstream disease classifier and how you would
defend the choice. (c) State two specific caveats about applying PCA to biomarker data.
Solution
(a) Cumulative variance and rules.
Cumulative through PC9: 18 + 11 + 8 + 6 + 5 + 4 + 3 + 3 + 2 = 60 percent.
· Kaiser’s rule. On standardised data with p = 60 features, total variance is 60 (each feature
contributes 1). Each PC’s variance ratio > 1/p = 1/60 ≈ 1.67 percent qualifies. PC1 through PC9 all

Predictive Analytics — Practice Set (S2 25-26) Page 19


have variance ratio ≥ 2 percent (the smallest is PC9 at 2 percent); the tail falls below. Kaiser ⇒ keep
about 9 PCs.
· 95 percent rule. We have 60 percent by PC9 and the tail adds about 1 percent or less per
component. Reaching 95 percent would require roughly 40–45 PCs — nearly the original
dimensionality. Marginal gains are tiny and likely noisy.

(b) What I would actually use. Around 8–12 PCs — consistent with Kaiser’s answer and the natural
elbow near PC8–PC9. Defend the choice empirically: fit the downstream classifier (logistic regression,
RF, etc.) with k ∈ {3, 5, 8, 10, 12, 15, 20} components, and pick the k with the highest cross-validated
AUC / F1. PCA is preprocessing — the right number of components is whichever best serves the
disease classification task, not whichever hits a fixed variance target.

(c) Caveats specific to biomarker data.


1. Non-Gaussian distributions. Many biomarker readings (concentrations, enzyme levels, cell
counts) are heavily right-skewed and may contain physiological outliers. PCA implicitly assumes
roughly elliptical, second-moment-driven structure. Log-transform skewed biomarkers and consider
robust PCA variants before running the standard procedure.
2. Clinical interpretability. A clinician needs to act on individual biomarkers (‘your HbA1c is
elevated’), not on PC3 = 0.14 × HbA1c + 0.22 × LDL + .... If interpretation is the goal, consider sparse
PCA, factor analysis with rotation, or biomarker-level feature selection instead of vanilla PCA.
Intuition. PCA helps prediction but hurts explanation. If stakeholders ask ‘why was this patient flagged?’ on
PCA-transformed features, the honest answer is a long sum of small contributions — not actionable. Weigh
the interpretability cost against the compression benefit for your use case.

Predictive Analytics — Practice Set (S2 25-26) Page 20


Topic 7 · Regression with Interactions
Concept map. In a regression Y = beta0 + beta1 · X1 + beta2 · X2, the slope on X1 is constant
regardless of X2. To let the effect of X1 depend on X2, add an interaction term: Y = beta0 + beta1 · X1 +
beta2 · X2 + beta3 · X1 · X2. Then the slope on X1 becomes (beta1 + beta3 · X2). The p-value on a
coefficient is the probability of observing an estimate at least as extreme as ours if the true coefficient
were zero — small p (typically < 0.05) suggests the term matters. The hierarchy principle: if an
interaction term is in the model, the corresponding main effects must stay, even if their p-values are
individually high.

Q1 | Easy
Model: Y = 200 + 15 · X1 + 50 · X2, where Y is monthly cafe revenue (in thousands of rupees), X1 is
average daily walk-in customers, and X2 is whether the cafe has a corporate tie-up (0 = no, 1 = yes). (a)
Predict Y for a cafe with X1 = 80 and a corporate tie-up. (b) Interpret each coefficient in plain English.
Solution
(a) Y = 200 + 15(80) + 50(1) = 200 + 1,200 + 50 = Rs. 1,450 thousand per month (i.e. Rs. 14.5
lakhs).

(b) Interpretation.
· Intercept = 200. Predicted revenue when X1 = 0 (no walk-ins) and X2 = 0 (no tie-up). Often a
baseline anchor — X1 = 0 is far outside any normal operating range, so do not read it as a literal
forecast.
· beta1 = 15. Each additional daily walk-in customer adds Rs. 15 thousand per month to revenue,
holding tie-up status fixed. Because there is no interaction term, this +15 applies whether the cafe has
a tie-up or not.
· beta2 = 50. Having a corporate tie-up adds Rs. 50 thousand per month compared to no tie-up,
holding walk-in volume fixed.
Intuition. Main-effects-only models assume the effects are additive and constant. Whenever the impact of
one variable should depend on the level of another, you need an interaction term.

Q2 | Easy
A regression of house price (Rs. lakhs) on size (sqft) and number of bedrooms gives beta_size = 0.05
with p = 0.001, and beta_bedrooms = 1.2 with p = 0.42. Interpret each p-value and explain what the
bedrooms result suggests.
Solution
p_size = 0.001. If size truly had no effect on price, the probability of observing an estimate as large as
0.05 by chance would be 0.1 percent. Reject the null hypothesis: size has a clear effect. Each
additional sqft adds about Rs. 5,000 to the price, on average.

p_bedrooms = 0.42. Far above any conventional threshold. We cannot distinguish the 1.2
lakhs-per-bedroom estimate from zero given the data’s noise.

Likely interpretation. Once size is accounted for, bedroom count adds little independent information:
a 1500 sqft 2BHK and a 1500 sqft 3BHK often have similar value. Bedrooms and size are correlated,
so most of bedrooms’ effect is being absorbed by size. Do not rush to drop bedrooms — check VIF
(multicollinearity), consider interactions, and see Q4 on the hierarchy principle if interactions are
present.

Q3 | Moderate
Model: Y = 1,200 + 8 · X1 + 200 · X2 + 3 · X1 · X2, where Y is monthly app-usage minutes, X1 is the
customer’s age in years, and X2 is the subscription plan (0 = basic, 1 = premium). (a) Write the effective

Predictive Analytics — Practice Set (S2 25-26) Page 21


regression line for basic and premium customers separately. (b) Interpret beta3 = 3: does premium
amplify or dampen the effect of age on usage? (c) Predict Y for a 40-year-old basic customer and a
40-year-old premium customer.
Solution
(a) Substitute X2:
· X2 = 0 (basic): Y = 1,200 + 8 · X1 + 200(0) + 3 · X1(0) = 1,200 + 8 · X1.
· X2 = 1 (premium): Y = 1,200 + 8 · X1 + 200(1) + 3 · X1(1) = 1,400 + 11 · X1.

The age slope rises from 8 to 11 minutes per year when a customer is on premium, and the intercept
rises from 1,200 to 1,400.

(b) beta3 = 3 is the interaction term. Each additional year of age adds 3 extra minutes of usage only
when the customer is on premium. Premium amplifies the age effect: older customers use the
premium plan more intensely than older customers use the basic plan. The two are complements, not
substitutes.

(c)
· X1 = 40, basic: Y = 1,200 + 8(40) = 1,200 + 320 = 1,520 minutes / month.
· X1 = 40, premium: Y = 1,400 + 11(40) = 1,400 + 440 = 1,840 minutes / month.
Difference at age 40 = 320 minutes. The premium uplift is not a fixed +200 minute add-on — it grows
with the customer’s age.
Intuition. When an interaction is present, the ‘effect of X1’ is not a single number any more. It is a function of
X2: slope_on_X1 = beta1 + beta3 · X2.

Q4 | Moderate
An e-commerce analyst fits the model Y = beta0 + beta1 · Discount + beta2 · Email + beta3 · Discount ·
Email to predict revenue per customer, where Discount is the percentage discount offered and Email is
0/1 for whether a promotional email was sent. The fitted p-values are beta1 = 0.18, beta2 = 0.24, beta3
= 0.004. A teammate proposes dropping Discount and Email from the model because neither main
effect is statistically significant. Give three distinct reasons why this is wrong, and describe what test you
would actually run to decide.
Solution
Three reasons the proposal is wrong.

1. The hierarchy (marginality) principle. If an interaction term Discount · Email is in the model, the
corresponding main effects must remain — even if their individual p-values are high. Removing them
changes the meaning of the interaction (it no longer represents the deviation from main-effect
predictions; it becomes an undefined hybrid) and distorts the fit at the corners of the design space.

2. The p-value on a main effect inside an interaction model is not what it looks like. The p-value
on beta1 tests ‘is the discount effect zero when Email = 0?’ That is a corner slice (customers who got
NO email), which may be a small or noisy subset of the data. A high p-value there does not mean
‘discount has no effect overall’ — only that it cannot be distinguished from zero at the Email = 0
reference level.

3. The interaction is highly significant (p = 0.004) on its own. That alone tells us discounts and
emails work differently in combination than in isolation. Stripping the main effects out of the model
would prevent it from describing what happens when one variable is at zero, but the data clearly cares
about the joint relationship.

The right test. Compare nested models with a partial F-test (or compare AIC / BIC):

Predictive Analytics — Practice Set (S2 25-26) Page 22


Full: Y = beta0 + beta1 D + beta2 E + beta3 D·E
Reduced: Y = beta0 + beta1 D + beta2 E (interaction dropped)
If the reduced model is not significantly worse, drop the interaction — then the main-effect p-values
become straightforward to interpret and you can consider dropping non-significant ones. As long as
the interaction stays, the main effects stay with it.

Q5 | Challenge
A regression of customer purchase value (Y, in rupees) on Age (in years), Promo (0 = no, 1 = yes), and
their interaction gives:

Y = 800 + 12 · Age − 150 · Promo + 5 · Age · Promo

with p-values: beta0 < 0.001, beta1 (Age) = 0.02, beta2 (Promo) = 0.06, beta3 (Age · Promo) = 0.001.
(a) Interpret each coefficient. (b) Write the predicted line for Promo = 0 and Promo = 1, and find the Age
at which they cross. (c) The marketing head says: ‘Promo had a negative coefficient — promotions hurt
sales. Drop them.’ Respond and recommend the right action.
Solution
(a) Interpretation.
· beta0 = 800: predicted purchase at Age = 0 and Promo = 0. Anchor only — Age = 0 is outside any
real customer range.
· beta1 = 12: each year of age adds Rs. 12 when Promo = 0. Significant.
· beta2 = −150: at Age = 0, Promo reduces purchase by Rs. 150 compared to no-Promo. Borderline
significance (p = 0.06) and must be read with the interaction.
· beta3 = 5: the effect of Promo on purchase rises by Rs. 5 per year of customer age. Highly
significant.

(b) Lines.
· Promo = 0: Y = 800 + 12 · Age.
· Promo = 1: Y = (800 − 150) + (12 + 5) · Age = 650 + 17 · Age.

Where they cross. Set equal: 800 + 12 Age = 650 + 17 Age ⇒ 150 = 5 Age ⇒ Age = 30.
At Age = 20: Promo = 0 gives 800 + 240 = 1040; Promo = 1 gives 650 + 340 = 990. Promo hurts
young customers.
At Age = 30: both = 1160. Indifference point.
At Age = 40: Promo = 0 gives 1280; Promo = 1 gives 650 + 680 = 1330. Promo helps older
customers.

(c) Respond. The marketing head is reading a single coefficient out of an interaction model. beta2 =
−150 is not the average effect of Promo — it is the effect of Promo at Age = 0, a value no customer
has. The correct read is: Promo’s effect depends on age, becoming positive above age 30 and
negative below.

Right action: segment the promotion. Run promotions only on customers above approximately age
30 — expected lift is positive there. Suppress promotions for younger customers — they are net
negative. Also keep both main effects in the model (hierarchy principle) as long as the interaction
stays. Validate by A/B testing promotion vs no-promotion within each age bracket.
Intuition. Coefficients in an interaction model only make sense at the reference level of the other variable. To
answer business questions, always plot the implied lines for each subgroup or compute the slope as a
function of the moderator.

Predictive Analytics — Practice Set (S2 25-26) Page 23


Topic 8 · Support Vector Machines
Concept map. An SVM finds the hyperplane that separates two classes with the largest possible
margin — the empty gap between the boundary and the nearest training points. The points that sit on
the edge of the margin are the support vectors; the hyperplane is defined entirely by them. The
penalty parameter C controls the trade-off between a wide margin and few classification mistakes:
small C → wider margin, more tolerant of misclassifications; large C → narrower margin, fewer
training errors. When the data is not linearly separable in its original space, a kernel (linear,
polynomial, RBF) projects it into a higher-dimensional space where a linear separator exists.

Q1 | Easy
What is a support vector? What is the margin? Why do we want it to be as wide as possible?
Solution
Support vector. A training point that lies on the edge of the margin (or, in a soft-margin SVM, inside
or on the wrong side of it). Only these points determine where the decision boundary sits — all other
points could be moved around freely without changing the model.

Margin. The perpendicular distance from the decision hyperplane to the nearest training point of
either class. It is the empty corridor the SVM tries to maximise.

Why wide is good. A wider margin means small perturbations to the data are less likely to push a
point across the boundary, so the classifier generalises better to unseen points. Intuition: a path that
is 10 metres wide is safer to walk down than one that is 10 centimetres wide.
Intuition. Throw away every training point that is NOT a support vector and retrain — you will get the exact
same SVM. That is why SVMs are called ‘sparse’ models: the boundary depends only on a handful of critical
points.

Q2 | Easy
When is data ‘linearly separable’? Give a 2-D example of data that is linearly separable and another that
is not. For the non-separable case, what does an SVM do?
Solution
Linearly separable. There exists a straight line (in 2-D), a plane (in 3-D), or a hyperplane (in higher
dimensions) that puts every Class-A point on one side and every Class-B point on the other side, with
no errors.

Example A — linearly separable. Customers plotted by (income, age): high-income elderly always
buy a premium plan, low-income young customers never do. A diagonal line cleanly splits them.

Example B — not linearly separable. The classic ‘two concentric rings’ pattern: the inner ring is
Class A, the outer ring is Class B. No straight line can separate them.

What the SVM does. Apply a kernel (RBF is the usual first choice) to project the data into a
higher-dimensional space where a linear separator does exist. The model still computes a linear
boundary — but in the transformed space — which maps back to a curved boundary in the original
2-D plane.
Intuition. The kernel trick is ‘curving the space, not the line.’ We never actually compute the new high-dim
coordinates — the kernel function gives us the dot product we need, directly.

Q3 | Easy
An SVM learned the decision boundary 2 · X1 + 3 · X2 − 12 = 0. The decision rule is: predict Class +1 if
(2 X1 + 3 X2 − 12) > 0, else Class −1. Classify the following points: A = (3, 2), B = (1, 4), C = (5, 1).

Predictive Analytics — Practice Set (S2 25-26) Page 24


Solution
Plug each point into the linear score f(x) = 2 X1 + 3 X2 − 12 and check the sign.

A = (3, 2): f = 2(3) + 3(2) − 12 = 6 + 6 − 12 = 0. The point lies exactly on the decision boundary —
ambiguous. By convention, treat as Class +1 (or refuse to predict).
B = (1, 4): f = 2(1) + 3(4) − 12 = 2 + 12 − 12 = +2 > 0 ⇒ Class +1.
C = (5, 1): f = 2(5) + 3(1) − 12 = 10 + 3 − 12 = +1 > 0 ⇒ Class +1.

Bonus — distance from the boundary. distance = |f(x)| / ||w||, where ||w|| = sqrt(22 + 32) = sqrt(13)
≈ 3.606. So B is ≈ 2/3.606 ≈ 0.555 units from the boundary; C is ≈ 0.277 units. B is the more confident
prediction.
Intuition. The sign of f(x) tells you the class. The magnitude of f(x), divided by ||w||, tells you how far from the
boundary the point is — a rough confidence score.

Q4 | Moderate
An SVM is trained twice on the same dataset: once with C = 0.01 and once with C = 100. Describe how
the two boundaries differ. Which one is more likely to overfit, and why?
Solution
C is the penalty for each misclassified point.

C = 0.01 (small). The model barely penalises mistakes. It prioritises a wide margin and allows many
points to sit on the wrong side of the margin or be misclassified. The boundary is smoother and
ignores individual outliers. Risk: under-fitting if the true pattern is sharp.

C = 100 (large). The model is very strict about mistakes — it will narrow the margin as needed to
classify every training point correctly. The boundary contorts to chase outliers and noisy points. Risk:
overfitting — great training accuracy, weak test accuracy.

Overfit risk lives at large C. The safe procedure is to choose C by cross-validation, sweeping a log
grid like {0.01, 0.1, 1, 10, 100} and picking the C with the best validation score.
Intuition. Read C as a strictness knob. Small C = lenient teacher willing to let some students sit on the wrong
side of the line for a calmer overall class. Large C = strict teacher who insists every student be on the correct
side, even if the dividing line looks crazy.

Q5 | Moderate
For each scenario, recommend a kernel (linear, polynomial degree 2-3, or RBF) and justify in one
sentence. (A) Text classification with 50,000 word-count features and 100,000 documents. (B) A 2-D
dataset shaped like two interlocking spirals. (C) A small structured dataset (5,000 rows, 20 features)
where you suspect mild non-linearity but no idea what shape.
Solution
(A) Linear kernel. Very high-dimensional sparse data (text, TF-IDF, bag-of-words) is almost always
already linearly separable in the original space — you have more features than you can shake a stick
at, and a hyperplane in that space is plenty. Linear is also the fastest to train and predict with.

(B) RBF kernel. Spirals are highly non-linear; the RBF kernel can model arbitrary smooth shapes by
adjusting gamma (the width of each local Gaussian). A polynomial kernel would struggle with the tight
curvature.

(C) RBF kernel as a default starting point. RBF is the all-purpose recommendation when you do
not know the data shape. Tune C and gamma by cross-validation. If a linear kernel matches RBF
performance, prefer linear (simpler, faster, more interpretable).

Predictive Analytics — Practice Set (S2 25-26) Page 25


Intuition. Default playbook: (1) start with linear, (2) try RBF, (3) polynomial is rarely worth the extra
hyperparameters in practice. Always standardise features first — SVMs are distance-based and blow up
with un-scaled features, just like K-Means.

Predictive Analytics — Practice Set (S2 25-26) Page 26


Topic 9 · Decision Trees & Random Forest
Concept map. A Decision Tree repeatedly asks ‘which feature, split where, makes the resulting groups
the purest?’ Purity is measured by Gini impurity or entropy. A split is chosen by maximising
Information Gain = impurity(parent) − weighted average impurity(children). A deep single tree is highly
interpretable but overfits viciously. A Random Forest trains many trees, each on a bootstrap sample
of the rows AND with each split restricted to a random subset of features, then averages their votes.
The two sources of randomness decorrelate the trees, so their average is far more stable than any
single tree.

Q1 | Easy
Compute the Gini impurity of a node that contains 40 examples of Class A and 60 examples of Class B.
Also compute the Gini for a perfectly pure node (100 of Class A, 0 of Class B). What does a Gini value
of 0 mean?
Solution
Gini formula. For K classes with proportions p1, p2, ..., pK in the node: Gini = 1 − sum of pi2.

Mixed node (40 A, 60 B).


p_A = 40 / 100 = 0.4. p_B = 60 / 100 = 0.6.
Gini = 1 − (0.42 + 0.62) = 1 − (0.16 + 0.36) = 1 − 0.52 = 0.48.

Pure node (100 A, 0 B).


p_A = 1, p_B = 0. Gini = 1 − (12 + 02) = 1 − 1 = 0.

Meaning of Gini = 0. The node contains only one class. The tree does not need to split it any further
— it is a leaf.
Intuition. For a 2-class problem, Gini ranges from 0 (perfectly pure) to 0.5 (50/50 mix — maximum
uncertainty). The split that brings the child Ginis closest to 0 is the winner.

Q2 | Easy
A parent node has 100 examples (50 Class A, 50 Class B), so its Gini is 0.5. A candidate split divides it
into Left (40 A, 10 B; 50 examples) and Right (10 A, 40 B; 50 examples). Compute the Information
Gain of the split.
Solution
Step 1. Parent Gini. Given as 0.5 (50/50 mix).

Step 2. Child Ginis.


Left node: p_A = 40/50 = 0.8, p_B = 0.2. Gini_L = 1 − (0.82 + 0.22) = 1 − (0.64 + 0.04) = 1 − 0.68 =
0.32.
Right node: p_A = 10/50 = 0.2, p_B = 0.8. By symmetry, Gini_R = 0.32.

Step 3. Weighted child impurity. Each child has 50 of the 100 rows, so weight = 0.5 each.
Weighted = 0.5 · 0.32 + 0.5 · 0.32 = 0.32.

Step 4. Information Gain. IG = 0.50 − 0.32 = 0.18.

Interpretation: this split reduced impurity by 0.18 (from 0.50 to 0.32). The tree algorithm would
compare this gain against the gain of every other candidate split and pick the highest.
Intuition. Information Gain is always ‘how much purer did the data get after splitting?’ A split that produces
two equally mixed children has IG = 0 — useless. A split that produces two pure children has IG equal to the
parent’s impurity — perfect.

Predictive Analytics — Practice Set (S2 25-26) Page 27


Q3 | Easy
Why does a single, deep decision tree usually overfit? Explain in plain English how a Random Forest
fixes the problem.
Solution
Why a deep tree overfits. Each split is greedy — the tree chooses the split that best fits the training
data right now, without thinking about generalisation. Allowed to grow deep, the tree keeps adding
branches until each leaf contains essentially one training point. At that level of detail, it has
memorised every quirk and noise pattern. Training accuracy is near 100 percent; test accuracy
collapses.

What Random Forest does. Build many trees (typically 100 to 500), each one trained on a slightly
different version of the problem, then take the majority vote.
· Bootstrap sampling (bagging). Each tree sees a random sample of rows drawn with replacement
— so no two trees see exactly the same data.
· Feature subsetting at each split. When considering how to split a node, the tree is only allowed to
look at a random subset of features (commonly sqrt(p) for classification, p/3 for regression). This
prevents one strong feature from dominating every tree.

The result. Individual trees still overfit their own bootstrap sample — but they overfit in different
directions because they saw different rows and were forced to use different features. Averaging their
predictions cancels out the individual overfits, leaving the genuine signal.
Intuition. ‘A council of biased experts can be wiser than any one of them, provided the biases point in
different directions.’ The decorrelation across trees is the whole reason Random Forest works — if every
tree saw the same data and could use the same features, you would just have 100 copies of the same
overfit tree.

Q4 | Moderate
A parent node has 200 examples (120 Class ‘Pass’, 80 Class ‘Fail’). Two candidate splits are being
evaluated:
Split on Attendance: Left = 100 examples (90 Pass, 10 Fail); Right = 100 examples (30 Pass, 70 Fail).
Split on Homework: Left = 80 examples (60 Pass, 20 Fail); Right = 120 examples (60 Pass, 60 Fail).
Compute the Information Gain (using Gini) for each split and recommend which split the tree should
pick.
Solution
Step 1. Parent Gini.
p_Pass = 120/200 = 0.6, p_Fail = 80/200 = 0.4.
Gini_parent = 1 − (0.62 + 0.42) = 1 − (0.36 + 0.16) = 1 − 0.52 = 0.48.

Step 2. Split on Attendance.


Left (100 rows: 90 Pass, 10 Fail): p_P = 0.9, p_F = 0.1. Gini_L = 1 − (0.81 + 0.01) = 0.18.
Right (100 rows: 30 Pass, 70 Fail): p_P = 0.3, p_F = 0.7. Gini_R = 1 − (0.09 + 0.49) = 0.42.
Weighted child impurity = (100/200) · 0.18 + (100/200) · 0.42 = 0.5 · 0.18 + 0.5 · 0.42 = 0.09 + 0.21 =
0.30.
IG(Attendance) = 0.48 − 0.30 = 0.18.

Step 3. Split on Homework.


Left (80 rows: 60 Pass, 20 Fail): p_P = 60/80 = 0.75, p_F = 0.25. Gini_L = 1 − (0.5625 + 0.0625) =
0.375.
Right (120 rows: 60 Pass, 60 Fail): p_P = 0.5, p_F = 0.5. Gini_R = 1 − (0.25 + 0.25) = 0.50.
Weighted child impurity = (80/200) · 0.375 + (120/200) · 0.50 = 0.4 · 0.375 + 0.6 · 0.50 = 0.15 + 0.30 =
0.45.

Predictive Analytics — Practice Set (S2 25-26) Page 28


IG(Homework) = 0.48 − 0.45 = 0.03.

Step 4. Compare.
IG(Attendance) = 0.18 vs IG(Homework) = 0.03.
Pick Attendance. It reduces impurity 6 times more than the Homework split. Intuitively: high
attendance is strongly associated with passing (90 of 100 high-attendance students pass), while
Homework barely separates anyone.
Intuition. A split is only useful if its children are noticeably purer than the parent. The Homework split here
produced a Right child that is still 50/50 — the tree learned nothing from sending students to that branch.
Always weight child impurities by the share of rows in each child — a tiny ultra-pure child does not justify a
giant noisy sibling.

Q5 | Moderate
A team trains a single decision tree (unbounded depth) on 10,000 rows. Training accuracy is 99
percent, test accuracy is 71 percent. They then train a Random Forest of 200 trees on the same data —
test accuracy jumps to 84 percent. (i) Explain why the single tree did so poorly on test. (ii) Explain in two
sentences how the Random Forest closed the gap. (iii) Name two important hyperparameters for a
Random Forest and what each controls.
Solution
(i) Why the single tree failed. Allowed to grow to unbounded depth, the tree split until every leaf
contained just one or two training points. It memorised the training set — including its noise — rather
than learning a generalisable pattern. The 28-point train-test gap is the signature of overfitting (high
variance).

(ii) Why Random Forest helped. Each of the 200 trees was trained on a different bootstrap sample
of rows and was forced to consider only a random subset of features at each split — so the trees
made different mistakes. Averaging their votes cancels out the individual overfits and leaves the
consistent signal, dropping the variance and lifting test accuracy.

(iii) Two key hyperparameters.


· n_estimators — number of trees. More trees = more stable predictions, but with diminishing returns
and longer training time. Typical values 100 to 500.
· max_features — how many features each split may consider. Common defaults: sqrt(p) for
classification, p/3 for regression. Smaller values increase decorrelation between trees (reduce
variance more) but each individual tree becomes weaker. Other useful knobs: max_depth (cap
individual tree depth to limit overfitting per tree), min_samples_leaf (refuse to create leaves below
this size).
Intuition. Random Forest’s biggest selling point is that it is hard to break: defaults usually work, training is
parallel, and feature importances come for free. It is the first model most data scientists try on tabular data
— and often the last one too.

Closing Notes for Students


1. Practise without looking. Cover the solution and try each question on a blank sheet. The exam
expects you to derive intuition; memorising worked answers will not generalise.
2. Look at the curve, not the number. AUC, accuracy, R-squared, WCSS — every single-number
metric hides something. Always inspect the underlying plot or table.
3. Match the algorithm to the data geometry. The reason K-Means fails on moons, sigmoid fails in
deep nets, and an additive decomposition fails on a multiplicative series — in each case the assumption
of the method clashes with the structure of the data. Find the mismatch and explain it.

Predictive Analytics — Practice Set (S2 25-26) Page 29


4. Cost > accuracy. Every classification problem implicitly has a FN/FP cost ratio. State it, then choose
the threshold.
5. Hierarchy principle, every time. If an interaction stays, main effects stay.

Predictive Analytics — Practice Set (S2 25-26) Page 30

You might also like