← All Free Study Guides · Course: SRM

Module 1: Statistical Learning & Exploratory Data Analysis

Study manual for Exam SRM



1. Foundational Distinctions in Statistical Learning

Statistical learning refers to a vast set of tools for understanding data. In a formal statistical learning problem, we observe a quantitative or qualitative response YY and a vector of pp different predictors (features, inputs, covariates) X=(X1,X2,…,Xp)TX = (X_1, X_2, \dots, X_p)^T. We assume that there is some true underlying functional relationship between YY and XX:

Y=f(X)+εY = f(X) + \varepsilon

where:

1.1 Four core taxonomies

Statistical Learning Taxonomies
1. Supervision Level
• Supervised (X and Y)
• Unsupervised (X only)
2. Response Type
• Regression (Continuous)
• Classification (Categorical)
3. Modeling Goal
• Prediction (Accuracy)
• Inference (Interpretability)
4. Model Flexibility
• Parametric (Linear/GLM)
• Non-parametric (KNN/Trees)
CriterionDistinction ADistinction BActuarial Example
SupervisionSupervised Learning: Every training observation ii includes both features xix_i and a supervising outcome label yiy_i.Unsupervised Learning: Only features xix_i are recorded; no target yiy_i exists. The goal is discovering latent clusters, patterns, or principal dimensions (Module 6).Supervised: Predicting claim severity from vehicle age.
Unsupervised: Grouping policyholders into lifestyle clusters without claim labels.
Response TypeRegression: The response YY takes continuous, numerical values (e.g., loss amounts, claim costs, financial returns).Classification: The response YY takes values in a discrete set of classes C={1,2,…,K}\mathcal{C} = \{1, 2, \dots, K\} (e.g., claim occurrence 0/1, policy renewal vs. lapse).Regression: Estimating ultimate claim cost in dollars.
Classification: Predicting whether a driver will file at least one bodily injury claim.
Modeling GoalPrediction: The primary objective is producing an accurate prediction Y^=f^(X)\hat{Y} = \hat{f}(X) for new cases. The structure of f^\hat{f} can be a "black box" as long as prediction error is minimized.Inference: The primary objective is understanding how YY is affected by individual components of XX (which predictors are associated with YY, what is the direction and magnitude of each effect, is the relationship linear?).Prediction: Real-time pricing algorithms where exact competitive quote pricing is prioritized.
Inference: Regulatory filings requiring transparent justification of rate differentials across geographic territories.
Model StructureParametric Methods: Assume a functional form for ff (e.g., linear f(X)=β0+∑βjXjf(X) = \beta_0 + \sum \beta_j X_j). Reduces the estimation problem to estimating a finite set of parameters.Non-parametric Methods: Make no explicit assumptions about the functional form of ff. Seek an estimate that gets close to the data without being too rough.Parametric: Multiple Linear Regression, Logistic GLM.
Non-parametric: KK-Nearest Neighbors, Splines, Decision Trees.

1.2 Reducible vs. Irreducible Error

When we estimate ff with f^\hat{f}, our prediction for a new observation X=x0X = x_0 is Y^=f^(x0)\hat{Y} = \hat{f}(x_0). The expected squared error of this prediction decomposes into two fundamentally distinct components:

E[(Y−Y^)2]=E[(f(X)+ε−f^(X))2]=(f(X)−f^(X))2⏟Reducible Error+Var(ε)⏟Irreducible Error (σε2)E\left[(Y - \hat{Y})^2\right] = E\left[(f(X) + \varepsilon - \hat{f}(X))^2\right] = \underbrace{\left(f(X) - \hat{f}(X)\right)^2}_{\text{Reducible Error}} + \underbrace{\text{Var}(\varepsilon)}_{\text{Irreducible Error } (\sigma_\varepsilon^2)}

2. The Bias-Variance Trade-off

The bias-variance trade-off is the central theoretical concept governing all supervised statistical learning methods on Exam SRM. It dictates how model flexibility affects predictive performance.

2.1 Full Mathematical Derivation of the Decomposition

Let x0x_0 be a fixed, newly observed predictor value, let Y0=f(x0)+ε0Y_0 = f(x_0) + \varepsilon_0 be the corresponding unobserved true response (where E[ε0]=0E[\varepsilon_0] = 0 and Var(ε0)=σε2\text{Var}(\varepsilon_0) = \sigma_\varepsilon^2, independent of the training data T\mathcal{T}), and let f^(x0)\hat{f}(x_0) be the prediction generated by a model trained on dataset T\mathcal{T}.

Because f^\hat{f} depends on the randomly drawn training sample T\mathcal{T}, f^(x0)\hat{f}(x_0) is a random variable with expectation ET[f^(x0)]E_{\mathcal{T}}[\hat{f}(x_0)] and variance VarT(f^(x0))\text{Var}_{\mathcal{T}}(\hat{f}(x_0)).

We seek to evaluate the Expected Test Mean Squared Error (MSE) at point x0x_0:

E[(Y0−f^(x0))2]E\left[(Y_0 - \hat{f}(x_0))^2\right]

Step-by-Step Proof:

  1. Add and subtract f(x0)f(x_0) and E[f^(x0)]E[\hat{f}(x_0)] inside the error term:
Y0−f^(x0)=(f(x0)+ε0)−f^(x0)=ε0+(f(x0)−E[f^(x0)])−(f^(x0)−E[f^(x0)])Y_0 - \hat{f}(x_0) = \left(f(x_0) + \varepsilon_0\right) - \hat{f}(x_0) = \varepsilon_0 + \left(f(x_0) - E[\hat{f}(x_0)]\right) - \left(\hat{f}(x_0) - E[\hat{f}(x_0)]\right)
  1. Square this three-term sum:
(Y0−f^(x0))2=ε02+(f(x0)−E[f^(x0)])2+(f^(x0)−E[f^(x0)])2+2ε0(f(x0)−E[f^(x0)])−2ε0(f^(x0)−E[f^(x0)])−2(f(x0)−E[f^(x0)])(f^(x0)−E[f^(x0)])\begin{aligned} (Y_0 - \hat{f}(x_0))^2 &= \varepsilon_0^2 + \left(f(x_0) - E[\hat{f}(x_0)]\right)^2 + \left(\hat{f}(x_0) - E[\hat{f}(x_0)]\right)^2 \\ &\quad + 2\varepsilon_0\left(f(x_0) - E[\hat{f}(x_0)]\right) - 2\varepsilon_0\left(\hat{f}(x_0) - E[\hat{f}(x_0)]\right) \\ &\quad - 2\left(f(x_0) - E[\hat{f}(x_0)]\right)\left(\hat{f}(x_0) - E[\hat{f}(x_0)]\right) \end{aligned}
  1. Take the mathematical expectation E[⋅]E[\cdot] across both the training data T\mathcal{T} and the new error ε0\varepsilon_0:
    • E[ε02]=Var(ε0)=σε2E[\varepsilon_0^2] = \text{Var}(\varepsilon_0) = \sigma_\varepsilon^2 (since E[ε0]=0E[\varepsilon_0] = 0).
    • (f(x0)−E[f^(x0)])2\left(f(x_0) - E[\hat{f}(x_0)]\right)^2 is non-random with respect to T\mathcal{T}, so its expectation is simply [Bias(f^(x0))]2\left[\text{Bias}(\hat{f}(x_0))\right]^2.
    • E[(f^(x0)−E[f^(x0)])2]=Var(f^(x0))E\left[\left(\hat{f}(x_0) - E[\hat{f}(x_0)]\right)^2\right] = \text{Var}(\hat{f}(x_0)).
    • E[2ε0(f(x0)−E[f^(x0)])]=2E[ε0]⋅(f(x0)−E[f^(x0)])=0E\left[2\varepsilon_0\left(f(x_0) - E[\hat{f}(x_0)]\right)\right] = 2 E[\varepsilon_0] \cdot \left(f(x_0) - E[\hat{f}(x_0)]\right) = 0 (since E[ε0]=0E[\varepsilon_0] = 0).
    • E[2ε0(f^(x0)−E[f^(x0)])]=2E[ε0]⋅E[f^(x0)−E[f^(x0)]]=0E\left[2\varepsilon_0\left(\hat{f}(x_0) - E[\hat{f}(x_0)]\right)\right] = 2 E[\varepsilon_0] \cdot E\left[\hat{f}(x_0) - E[\hat{f}(x_0)]\right] = 0 (because ε0\varepsilon_0 is independent of the training data that generated f^\hat{f}).
    • E[2(f(x0)−E[f^(x0)])(f^(x0)−E[f^(x0)])]=2(f(x0)−E[f^(x0)])⋅E[f^(x0)−E[f^(x0)]]⏟=0=0E\left[2\left(f(x_0) - E[\hat{f}(x_0)]\right)\left(\hat{f}(x_0) - E[\hat{f}(x_0)]\right)\right] = 2\left(f(x_0) - E[\hat{f}(x_0)]\right) \cdot \underbrace{E\left[\hat{f}(x_0) - E[\hat{f}(x_0)]\right]}_{= 0} = 0.
  1. Summing the non-zero terms yields the celebrated Bias-Variance Decomposition:
E[(Y0−f^(x0))2]=[Bias(f^(x0))]2+Var(f^(x0))+σε2E\left[(Y_0 - \hat{f}(x_0))^2\right] = \left[\text{Bias}(\hat{f}(x_0))\right]^2 + \text{Var}(\hat{f}(x_0)) + \sigma_\varepsilon^2
The Bias-Variance Tradeoff vs Model Flexibility
024246810Irreducible Noise Var(ε) = 0.5Model Flexibility (Degrees of Freedom)Mean Squared Error (MSE)
  • Total Test MSE
  • Squared Bias
  • Variance
  • Training MSE

As flexibility increases, Squared Bias monotonically decreases, while Model Variance monotonically increases. The Test MSE curve is U-shaped, reaching its global minimum where the rate of decrease in squared bias equals the rate of increase in variance.

2.2 Deep Conceptual Breakdown of the Three Components

  1. Squared Bias [Bias(f^(x0))]2=(f(x0)−E[f^(x0)])2\left[\text{Bias}(\hat{f}(x_0))\right]^2 = \left(f(x_0) - E[\hat{f}(x_0)]\right)^2:
    • Definition: The error introduced by approximating a complicated real-world process with a much simpler model.
    • Behavior: Very rigid models (e.g., Simple Linear Regression) have high bias because they cannot capture non-linear relationships. Extremely flexible models (e.g., high-degree splines, deep trees) have low bias because they can conform to almost any functional shape.
    • Monotonicity: Squared bias monotonically decreases as model flexibility increases.
  1. Model Variance Var(f^(x0))=E[(f^(x0)−E[f^(x0)])2]\text{Var}(\hat{f}(x_0)) = E\left[\left(\hat{f}(x_0) - E[\hat{f}(x_0)]\right)^2\right]:
    • Definition: The amount by which f^(x0)\hat{f}(x_0) would change if we estimated it using a completely different training dataset drawn from the same population.
    • Behavior: Ideally, the estimate should not vary substantially between training sets. Rigid models have low variance because changing a few data points does not shift the slope of a fitted line drastically. In contrast, highly flexible models have high variance because they chase individual data points, causing dramatic fluctuations across different training samples.
    • Monotonicity: Model variance monotonically increases as model flexibility increases.
  1. Irreducible Error σε2\sigma_\varepsilon^2:
    • Definition: The inherent noise in the system that cannot be explained by any function of the observed predictors XX.
    • Behavior: Completely independent of model choice, algorithm flexibility, and sample size. It represents the horizontal asymptote / floor below which test MSE can never descend.

3. Resampling Methods: Validating Model Accuracy

Training MSE always flatters the fitted model because the optimization objective minimizes errors on those exact observations. As model flexibility grows, Training MSE monotonically decreases towards zero.

Consequently, Training MSE is completely useless for model selection. To evaluate predictive performance, we must estimate the Test MSE using data that was never used during model fitting.

                  Comparison of Resampling Approaches
                                   │
         ┌─────────────────────────┼─────────────────────────┐
         ▼                         ▼                         ▼
  Validation Set Split            $k$-Fold CV                      LOOCV
┌───────────────────────┐ ┌─────────────────────────┐ ┌─────────────────────────┐
│ • Single split (e.g., │ │ • Divide into $k$ equal │ │ • $k = n$ folds.        │
│   70% train / 30% test│ │   folds (e.g., $k=5, 10$)│ │ • Fit on $n-1$, test on 1│
│ • High variance in MSE│ │ • Intermediate bias and │ │ • Virtually zero bias.  │
│ • Overestimates error │ │   low variance.         │ │ • High variance in MSE  │
│   (smaller sample)    │ │ • Gold standard for SRM.│ │   estimate (correlated).│
└───────────────────────┘ └─────────────────────────┘ └─────────────────────────┘

3.1 The Validation Set Approach

3.2 kk-Fold Cross-Validation

MSEj=1∣Cj∣∑i∈Cj(yi−y^i)2\text{MSE}_j = \frac{1}{|C_j|} \sum_{i \in C_j} (y_i - \hat{y}_i)^2
CV(k)=1k∑j=1kMSEj\text{CV}_{(k)} = \frac{1}{k} \sum_{j=1}^k \text{MSE}_j

3.3 Leave-One-Out Cross-Validation (LOOCV)

CV(n)=1n∑i=1n(yi−y^(−i))2\text{CV}_{(n)} = \frac{1}{n} \sum_{i=1}^n (y_i - \hat{y}_{(-i)})^2

The Bias-Variance Trade-off Between LOOCV and kk-Fold (k=5k=5 or 1010):

Candidates on Exam SRM must understand the subtle bias-variance trade-off of the CV error estimators themselves:

  1. Bias of the Error Estimator:
    • LOOCV trains on n−1n-1 observations, which is virtually identical to the full sample nn. Hence, LOOCV provides an almost completely unbiased estimate of test error.
    • kk-fold CV (k=5k=5 or 1010) trains on k−1kn\frac{k-1}{k}n observations (e.g., 80%80\% or 90%90\%). It has slightly higher bias (it slightly overestimates test error).
  2. Variance of the Error Estimator:
    • Counterintuitively, LOOCV has higher variance than 1010-fold CV!
    • Why? In LOOCV, the nn fitted models are trained on nn datasets that are each almost identical (sharing n−2n-2 common observations). Therefore, the nn validation errors are highly positively correlated. The mean of many highly correlated quantities has a higher variance than the mean of quantities that are less correlated.
    • In 1010-fold CV, the training sets overlap much less, reducing positive correlation and lowering the variance of the overall CV estimate CV(k)\text{CV}_{(k)}.
    • Conclusion: k=5k=5 or k=10k=10 strikes the optimal balance between bias and variance for estimating test error.

3.4 The Least-Squares Computational Shortcut for LOOCV

Fitting a model nn separate times is computationally expensive. However, for Ordinary Least Squares (OLS) linear and polynomial regression, there is a remarkable algebraic identity:

CV(n)=1n∑i=1n(yi−y^i1−hii)2\text{CV}_{(n)} = \frac{1}{n} \sum_{i=1}^n \left(\frac{y_i - \hat{y}_i}{1 - h_{ii}}\right)^2

where:

hii=1n+(xi−xˉ)2∑j=1n(xj−xˉ)2h_{ii} = \frac{1}{n} + \frac{(x_i - \bar{x})^2}{\sum_{j=1}^n (x_j - \bar{x})^2}

3.5 The Golden Rule of Cross-Validation: Preventing Data Leakage


4. Exploratory Data Analysis (EDA) & Descriptive Statistics

Before fitting any predictive model, actuaries perform Exploratory Data Analysis (EDA) to understand the distribution, central tendencies, spread, skewness, and anomalies within the dataset.

4.1 Summary Statistics & Moment Analysis

Let x1,x2,…,xnx_1, x_2, \dots, x_n be a sample of nn observations.

  1. Sample Mean (xˉ\bar{x}) vs. Sample Median (x~\tilde{x}):
    • Mean: xˉ=1n∑i=1nxi\bar{x} = \frac{1}{n} \sum_{i=1}^n x_i. Sensitive to extreme outliers.
    • Median: 50th percentile. Robust against outliers and heavy tails.
    • Skewness Diagnostic:
      • xˉ≈x~\bar{x} \approx \tilde{x}: Symmetric distribution (e.g., Normal).
      • xˉ>x~\bar{x} > \tilde{x}: Right-skewed (positive skewness), typical in actuarial claim severity, mortality loss, and healthcare expenditures.
      • xˉ<x~\bar{x} < \tilde{x}: Left-skewed (negative skewness), seen in retirement age or customer retention duration.
  1. Interquartile Range (IQR):
IQR=Q3−Q1\text{IQR} = Q_3 - Q_1

where Q1Q_1 is the 25th percentile (first quartile) and Q3Q_3 is the 75th percentile (third quartile). The IQR covers the central 50% of the distribution and is robust against extreme values.

  1. Sample Variance (s2s^2) and Standard Deviation (ss):
s2=1n−1∑i=1n(xi−xˉ)2,s=s2s^2 = \frac{1}{n-1} \sum_{i=1}^n (x_i - \bar{x})^2, \quad s = \sqrt{s^2}
  1. Sample Skewness (b1b_1) and Sample Kurtosis (b2b_2):
    • Skewness (Asymmetry):
b1=1n∑i=1n(xi−xˉ)3(1n∑i=1n(xi−xˉ)2)3/2b_1 = \frac{\frac{1}{n}\sum_{i=1}^n (x_i - \bar{x})^3}{\left(\frac{1}{n}\sum_{i=1}^n (x_i - \bar{x})^2\right)^{3/2}}

b1>0b_1 > 0 indicates a long right tail; b1<0b_1 < 0 indicates a long left tail.

b2=1n∑i=1n(xi−xˉ)4(1n∑i=1n(xi−xˉ)2)2b_2 = \frac{\frac{1}{n}\sum_{i=1}^n (x_i - \bar{x})^4}{\left(\frac{1}{n}\sum_{i=1}^n (x_i - \bar{x})^2\right)^2}

For a standard normal distribution, b2=3b_2 = 3. Excess kurtosis is b2−3b_2 - 3. A leptokurtic distribution (excess kurtosis >0> 0) features fat tails and a sharp peak, common in financial risk modeling.

4.2 The Boxplot & The 1.5×IQR1.5 \times \text{IQR} Outlier Fence Rule

Tukey's schematic boxplot visually portrays the distribution using the Five-Number Summary:

Min,Q1,Median  (Q2),Q3,Max\text{Min}, \quad Q_1, \quad \text{Median} \; (Q_2), \quad Q_3, \quad \text{Max}
Lower Outlier             Inner Fence             Q1       Median     Q3            Upper Fence             Upper Outlier
      *            ├──────────────────────────[       |       |       ]──────────────────────────┤                *
                   │                          │       │       │       │                          │
              Q1 - 1.5*IQR                   Q1       │      Q2      Q3                    Q3 + 1.5*IQR
                                                      │◄─────────────►│
                                                             IQR

4.3 Normal Quantile-Quantile (Q-Q) Plots

A normal Q-Q plot compares the sample quantiles of standardized observations against the theoretical quantiles of a standard normal distribution N(0,1)\mathcal{N}(0, 1).

Q-Q Plot PatternDiagnostic InterpretationActuarial Consequence & Remedy
Straight 45-degree diagonal lineObservations follow a normal distribution.Standard OLS assumptions are satisfied.
Upward curving convex arc (both ends above line)Right-skewed (positively skewed) distribution. Small values are clustered; large values are excessively dispersed.OLS residuals violate normality. Apply a log transform ln⁡(Y)\ln(Y) or use a Gamma/Poisson GLM with log link.
Downward curving concave arc (both ends below line)Left-skewed (negatively skewed) distribution.Consider power transformations (e.g., Box-Cox with λ>1\lambda > 1).
S-shape: Left end below line, Right end above lineHeavy-tailed (fat-tailed / leptokurtic) distribution. Extreme values occur far more frequently than predicted by a normal distribution.High risk of underestimating extreme claim severity or tail risk (VaR/TVaR). Consider Student's tt, Pareto, or Generalized Pareto distributions.
Inverted S-shape: Left end above, Right end belowLight-tailed (platykurtic) distribution. Bounded or truncated support with fewer extreme values.Truncated models or uniform-like characteristics.

5. KK-Nearest Neighbors (KNN)

KK-Nearest Neighbors is a quintessential non-parametric, memory-based learning algorithm that can be applied to both regression and classification problems.

5.1 The Algorithm

Given a positive integer KK and a test observation x0x_0:

  1. Identify the KK points in the training dataset that are closest to x0x_0 using a distance metric, typically Euclidean distance:
d(xi,x0)=∑j=1p(xij−x0j)2d(x_i, x_0) = \sqrt{\sum_{j=1}^p (x_{ij} - x_{0j})^2}

Let N0\mathcal{N}_0 denote this set of KK nearest points.

  1. KNN Regression: Estimate the response as the arithmetic average of the neighbors:
f^(x0)=1K∑i∈N0yi\hat{f}(x_0) = \frac{1}{K} \sum_{i \in \mathcal{N}_0} y_i
  1. KNN Classification: Estimate the conditional probability for class jj as the proportion of neighbors belonging to class jj:
P(Y=j∣X=x0)=1K∑i∈N0I(yi=j)P(Y = j \mid X = x_0) = \frac{1}{K} \sum_{i \in \mathcal{N}_0} I(y_i = j)

The observation is classified to the class with the highest estimated probability (majority vote).

5.2 The Role of the Hyperparameter KK

SettingFlexibilityBiasVarianceEffective Degrees of FreedomTraining Error
K=1K = 1Maximum (overfitting)Extremely low (zero at training points)Extremely high (sensitive to local noise)nn0.0%0.0\% (perfect fit on training data)
Intermediate KK (e.g., K=10K=10)BalancedModerateModerate≈n/K\approx n/KOptimal test performance
K=nK = nMinimum (underfitting)Extremely high (predicts global sample mean/mode)Virtually zero11Very high (ignores all local predictor information)
Effective Degrees of Freedom of KNN≈nK\text{Effective Degrees of Freedom of KNN} \approx \frac{n}{K}

As KK increases, the effective degrees of freedom drop, making the decision boundary smoother and less flexible, thereby increasing bias and decreasing variance.

5.3 Mandatory Predictor Standardization

Because KNN relies directly on Euclidean distance, it is highly sensitive to the measurement scale of the predictors.

If Predictor 1 is Annual Income measured in dollars ($30,000\$30,000 to $200,000\$200,000, standard deviation ≈$30,000\approx \$30,000) and Predictor 2 is Driver Age measured in years (1818 to 8080, standard deviation ≈15\approx 15), a difference of $1,000\$1,000 in income completely dwarfs a 20-year difference in age in Euclidean distance calculations!

5.4 The Curse of Dimensionality

As the number of predictor dimensions pp increases:

  1. The volume of the feature space grows exponentially (O(2p)\mathcal{O}(2^p)).
  2. The available data points become increasingly sparse.
  3. To capture a fixed fraction (e.g., 10%) of the total sample volume, the nearest neighbors must be located exceedingly far away from x0x_0 in the predictor space.
  4. Consequently, the nearest neighbors are no longer genuinely "local," severely inflating bias and causing KNN to perform poorly in high dimensions compared to parametric linear models.

6. R code and output interpretation lab

Exam questions often present R output to extract coefficients, test statistics, and model diagnostic parameters.

6.1 Exploratory Data Analysis & Residual Diagnostics

r
# Load actuarial policyholder dataset
data <- read.csv("auto_claims.csv")

# 1. Five-number summary and distribution checks
summary(data$claim_amount)
# Output:
#    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
#     120    1450    3200    5480    6800   85000 

# Notice Mean (5480) > Median (3200) -> Severe Right-Skewness!

# 2. Interquartile Range and Outlier Detection
iqr_val <- IQR(data$claim_amount)       # 6800 - 1450 = 5350
upper_fence <- 6800 + 1.5 * iqr_val     # 6800 + 1.5 * 5350 = 14825
lower_fence <- 1450 - 1.5 * iqr_val     # 1450 - 8025 = -6575 (bounded at 0)
# Any claim above $14,825 is flagged as an outlier in boxplot!

# 3. Generating Diagnostic Plots
boxplot(claim_amount ~ vehicle_type, data = data,
        main = "Claim Severity by Vehicle Category",
        xlab = "Vehicle Type", ylab = "Incurred Loss ($)")

qqnorm(residuals(model_ols), main = "Normal Q-Q Plot of OLS Residuals")
qqline(residuals(model_ols), col = "red", lwd = 2)

6.2 Cross-Validation with boot::cv.glm

In R, cross-validation for generalized linear models is executed using the cv.glm() function from the boot library.

r
library(boot)

# Fit linear regression model using glm() (equivalent to lm() when family = gaussian)
glm_fit <- glm(claim_amount ~ driver_age + vehicle_age + credit_score, 
               data = auto_claims)

# Run 10-fold Cross-Validation
set.seed(2027)
cv_10fold <- cv.glm(data = auto_claims, glmfit = glm_fit, K = 10)

# Inspect cross-validation results
cv_10fold$delta
# Output:
# [1] 412580.4  411990.2

6.3 KK-Nearest Neighbors with class::knn

r
library(class)

# Prepare standardized training and testing feature matrices
train_X <- scale(train_data[, c("driver_age", "credit_score", "annual_mileage")])
test_X  <- scale(test_data[, c("driver_age", "credit_score", "annual_mileage")],
                 center = attr(train_X, "scaled:center"),
                 scale  = attr(train_X, "scaled:scale")) # Crucial: Prevent data leakage!

train_Y <- train_data$claim_indicator # Binary factor: 0 or 1

# Fit KNN with K = 5
knn_pred <- knn(train = train_X, test = test_X, cl = train_Y, k = 5, prob = TRUE)

# Confusion Matrix Evaluation
conf_matrix <- table(Predicted = knn_pred, Actual = test_data$claim_indicator)
print(conf_matrix)
# Output:
#          Actual
# Predicted    0    1
#         0 1820  140
#         1   80   60

From this confusion matrix:


7. Common traps


8. Master Practice Question Vault

Problem 1: Mathematical Bias-Variance Decomposition

An actuarial team evaluates two competing predictive models for commercial liability claim severity at a specific covariate vector x0x_0. The true expected severity at x0x_0 is f(x0)=450f(x_0) = 450. The irreducible noise standard deviation is σε=40\sigma_\varepsilon = 40.

Which model has the lower expected test Mean Squared Error at x0x_0, and what is the difference in expected test MSE between the two models?

  1. AModel A has lower MSE; difference is 1,125
  2. BModel A has lower MSE; difference is 275
  3. CModel B has lower MSE; difference is 875
  4. DModel A has lower MSE; difference is 1,150
  5. EBoth models have identical test MSE

Detailed 4-Step Solution:

  1. Actuarial Principle & Formula: Expected Test MSE decomposes as:
E[(Y0−f^(x0))2]=(f(x0)−E[f^(x0)])2+Var(f^(x0))+σε2E\left[(Y_0 - \hat{f}(x_0))^2\right] = \left(f(x_0) - E[\hat{f}(x_0)]\right)^2 + \text{Var}(\hat{f}(x_0)) + \sigma_\varepsilon^2
  1. Evaluate Model A:
    • BiasA=f(x0)−E[f^A(x0)]=450−420=30\text{Bias}_A = f(x_0) - E[\hat{f}_A(x_0)] = 450 - 420 = 30.
    • BiasA2=302=900\text{Bias}_A^2 = 30^2 = 900.
    • VarA=250\text{Var}_A = 250.
    • σε2=402=1,600\sigma_\varepsilon^2 = 40^2 = 1,600.
    • MSEA=900+250+1,600=2,750\text{MSE}_A = 900 + 250 + 1,600 = 2,750.
  2. Evaluate Model B:
    • BiasB=f(x0)−E[f^B(x0)]=450−445=5\text{Bias}_B = f(x_0) - E[\hat{f}_B(x_0)] = 450 - 445 = 5.
    • BiasB2=52=25\text{Bias}_B^2 = 5^2 = 25.
    • VarB=1,400\text{Var}_B = 1,400.
    • σε2=1,600\sigma_\varepsilon^2 = 1,600.
    • MSEB=25+1,400+1,600=3,025\text{MSE}_B = 25 + 1,400 + 1,600 = 3,025.
  3. Compare and Conclude: MSEB−MSEA=3,025−2,750=275\text{MSE}_B - \text{MSE}_A = 3,025 - 2,750 = 275. The irreducible error is the same for both, so the gap is all in the reducible part: 900+250=1,150900 + 250 = 1,150 reducible error for A. 25+1,400=1,42525 + 1,400 = 1,425 reducible error for B. 1,425−1,150=2751,425 - 1,150 = 275. Model A has the lower expected test MSE, by 275: its larger bias is outweighed by its much smaller variance. Answer (B).

Why the other choices are wrong:


Problem 2: LOOCV Computational Leverage Shortcut

An OLS linear regression model is fitted to n=5n = 5 claim observations. The observed responses yiy_i, fitted values y^i\hat{y}_i, and diagonal hat matrix elements hiih_{ii} are given below:

Observation iiActual yiy_iFitted y^i\hat{y}_iLeverage hiih_{ii}
112100.20
218200.50
325220.25
430320.60
540380.20

Calculate the Leave-One-Out Cross-Validation estimate of the test Mean Squared Error (CV(5)\text{CV}_{(5)}).

  1. A17.38
  2. B8.00
  3. C13.90
  4. D5.00
  5. E69.50

Detailed 4-Step Solution:

  1. Governing Formula:
CV(n)=1n∑i=1n(yi−y^i1−hii)2=1n∑i=1ne(i)2\text{CV}_{(n)} = \frac{1}{n} \sum_{i=1}^n \left(\frac{y_i - \hat{y}_i}{1 - h_{ii}}\right)^2 = \frac{1}{n} \sum_{i=1}^n e_{(i)}^2
  1. Compute Deleted Residuals e(i)=yi−y^i1−hiie_{(i)} = \frac{y_i - \hat{y}_i}{1 - h_{ii}}:
    • Obs 1: e1=12−10=2.0e_1 = 12 - 10 = 2.0. e(1)=2.01−0.20=2.00.80=2.50  ⟹  e(1)2=6.25e_{(1)} = \frac{2.0}{1 - 0.20} = \frac{2.0}{0.80} = 2.50 \implies e_{(1)}^2 = 6.25.
    • Obs 2: e2=18−20=−2.0e_2 = 18 - 20 = -2.0. e(2)=−2.01−0.50=−2.00.50=−4.00  ⟹  e(2)2=16.00e_{(2)} = \frac{-2.0}{1 - 0.50} = \frac{-2.0}{0.50} = -4.00 \implies e_{(2)}^2 = 16.00.
    • Obs 3: e3=25−22=3.0e_3 = 25 - 22 = 3.0. e(3)=3.01−0.25=3.00.75=4.00  ⟹  e(3)2=16.00e_{(3)} = \frac{3.0}{1 - 0.25} = \frac{3.0}{0.75} = 4.00 \implies e_{(3)}^2 = 16.00.
    • Obs 4: e4=30−32=−2.0e_4 = 30 - 32 = -2.0. e(4)=−2.01−0.60=−2.00.40=−5.00  ⟹  e(4)2=25.00e_{(4)} = \frac{-2.0}{1 - 0.60} = \frac{-2.0}{0.40} = -5.00 \implies e_{(4)}^2 = 25.00.
    • Obs 5: e5=40−38=2.0e_5 = 40 - 38 = 2.0. e(5)=2.01−0.20=2.00.80=2.50  ⟹  e(5)2=6.25e_{(5)} = \frac{2.0}{1 - 0.20} = \frac{2.0}{0.80} = 2.50 \implies e_{(5)}^2 = 6.25.
  2. Sum Squared Deleted Residuals:
∑i=15e(i)2=6.25+16.00+16.00+25.00+6.25=69.50\sum_{i=1}^5 e_{(i)}^2 = 6.25 + 16.00 + 16.00 + 25.00 + 6.25 = 69.50
  1. Evaluate Average:
CV(5)=69.505=13.90\text{CV}_{(5)} = \frac{69.50}{5} = 13.90

(Notice: Simple training MSE would be 22+(−2)2+32+(−2)2+225=255=5.00\frac{2^2 + (-2)^2 + 3^2 + (-2)^2 + 2^2}{5} = \frac{25}{5} = 5.00, illustrating how training MSE severely underestimates test error).

Answer (C).

Why the other choices are wrong:


Problem 3: Tukey Boxplot Fence and Outlier Evaluation

An insurer analyzes workers' compensation loss severity across a sample of 200 settled claims. The computed sample quartiles are:

The five largest settled claims in the sample are: $22,500\$22,500, $23,100\$23,100, $23,500\$23,500, $24,200\$24,200, and $38,000\$38,000.

Using Tukey's 1.5×IQR1.5 \times \text{IQR} rule, determine:

  1. The upper fence threshold beyond which a claim is categorized as an outlier.
  2. How many of the five largest claims are flagged as outliers.
  1. AUpper fence is $19,400\$19{,}400; 5 claims are outliers
  2. BUpper fence is $23,200\$23,200; 3 claims are outliers
  3. CUpper fence is $18,900\$18{,}900; 5 claims are outliers
  4. DUpper fence is $34,600\$34{,}600; 1 claim is an outlier
  5. EUpper fence is $11,400\$11{,}400; 5 claims are outliers

Detailed 4-Step Solution:

  1. Compute Interquartile Range (IQR):
IQR=Q3−Q1=11,800−4,200=7,600\text{IQR} = Q_3 - Q_1 = 11,800 - 4,200 = 7,600
  1. Compute Upper Fence:
Upper Fence=Q3+1.5×IQR=11,800+1.5×(7,600)=11,800+11,400=23,200\text{Upper Fence} = Q_3 + 1.5 \times \text{IQR} = 11,800 + 1.5 \times (7,600) = 11,800 + 11,400 = 23,200
  1. Evaluate Observations Above Upper Fence: Any claim strictly greater than $23,200\$23,200 is flagged as an outlier:
    • $22,500<$23,200\$22,500 < \$23,200 (Regular observation)
    • $23,100<$23,200\$23,100 < \$23,200 (Regular observation)
    • $23,500>$23,200\$23,500 > \$23,200 →\to Outlier 1
    • $24,200>$23,200\$24,200 > \$23,200 →\to Outlier 2
    • $38,000>$23,200\$38,000 > \$23,200 →\to Outlier 3
  2. Conclusion: Upper fence is $23,200\$23,200; exactly 3 claims are flagged as outliers. Answer (B).

Why the other choices are wrong:


Problem 4: KK-Nearest Neighbors Regression with Scaling

A homeowner policy insurer uses KNN regression to predict contents damage (YY, in thousands of dollars) using two predictors: Home Age (X1X_1, in years) and Distance to Coast (X2X_2, in miles). The training dataset consists of 4 observations:

Policy iiAge X1X_1Distance X2X_2Damage YY ($000)
110240
220820
330460
4401030

The sample standard deviations are s1=12.91s_1 = 12.91 years for X1X_1 and s2=3.65s_2 = 3.65 miles for X2X_2. A new claim arrives with Age X1=25X_1 = 25 and Distance X2=5X_2 = 5.

Predict YY for the new policy using standardized KK-Nearest Neighbors with K=2K = 2.

  1. A60
  2. B37.5
  3. C40
  4. D50
  5. E46.3

Detailed 4-Step Solution:

  1. Standardize Distances: For each observation ii, the standardized Euclidean distance to x0=(25,5)x_0 = (25, 5) is:
d(i,x0)=(xi1−2512.91)2+(xi2−53.65)2d(i, x_0) = \sqrt{\left(\frac{x_{i1} - 25}{12.91}\right)^2 + \left(\frac{x_{i2} - 5}{3.65}\right)^2}
  1. Compute Distance to Each Policy:
    • Policy 1: Δx1=10−25=−15  ⟹  −1512.91=−1.162\Delta x_1 = 10 - 25 = -15 \implies \frac{-15}{12.91} = -1.162. Δx2=2−5=−3  ⟹  −33.65=−0.822\Delta x_2 = 2 - 5 = -3 \implies \frac{-3}{3.65} = -0.822.
d(1,x0)=(−1.162)2+(−0.822)2=1.350+0.676=2.026≈1.423d(1, x_0) = \sqrt{(-1.162)^2 + (-0.822)^2} = \sqrt{1.350 + 0.676} = \sqrt{2.026} \approx 1.423
d(2,x0)=(−0.387)2+(0.822)2=0.150+0.676=0.826≈0.909d(2, x_0) = \sqrt{(-0.387)^2 + (0.822)^2} = \sqrt{0.150 + 0.676} = \sqrt{0.826} \approx 0.909
d(3,x0)=(0.387)2+(−0.274)2=0.150+0.075=0.225≈0.474d(3, x_0) = \sqrt{(0.387)^2 + (-0.274)^2} = \sqrt{0.150 + 0.075} = \sqrt{0.225} \approx 0.474
d(4,x0)=(1.162)2+(1.370)2=1.350+1.877=3.227≈1.796d(4, x_0) = \sqrt{(1.162)^2 + (1.370)^2} = \sqrt{1.350 + 1.877} = \sqrt{3.227} \approx 1.796
  1. Identify K=2K = 2 Nearest Neighbors:
    • Smallest distance: Policy 3 (d≈0.474d \approx 0.474, Y=60Y = 60).
    • Second smallest: Policy 2 (d≈0.909d \approx 0.909, Y=20Y = 20).
  2. Compute KNN Prediction:
Y^=Y3+Y22=60+202=40\hat{Y} = \frac{Y_3 + Y_2}{2} = \frac{60 + 20}{2} = 40

Answer (C).

Why the other choices are wrong:

Related Exam SRM Free Study Guides & Syllabus

Continue studying the Exam SRM syllabus, formula sheets, and practice bank with these free companion modules:

Ready to test this topic under exam pressure?

Practice worked questions with step-by-step solutions and distractor trap diagnostics.

Open Interactive Version →