CertNote/ Commute Study Notes
Roadmap
KOEN
CLF-C02 · FoundationalCloud Practitioner - Foundational
DVA-C02 · AssociateDeveloper - Associate
SAA-C03 · AssociateSolutions Architect - Associate
SOA-C02 · AssociateCloudOps Engineer - Associate
SAP-C02 · ProfessionalSolutions Architect - Professional
DOP-C02 · ProfessionalDevOps Engineer - Professional
Linux Master 2 · 2급KAIT Linux Master - Level 2
SCS-C03 · SpecialtySecurity - Specialty
Linux Master 1 · 1급KAIT Linux Master - Level 1
MLA-C01 · AssociateMachine Learning Engineer - Associate
AIF-C01 · FoundationalAI Practitioner - Foundational
DEA-C01 · AssociateData Engineer - Associate
MLS-C01 · SpecialtyMachine Learning - Specialty
  • Week 1
    • 1.The ML Lifecycle (from a Specialty Perspective)
    • 2.Data Storage for ML: S3, EFS, FSx for Lustre, and Data Formats
    • 3.Data Ingestion: Kinesis, Glue, Batch vs. Streaming
    • 4.Data Labeling: SageMaker Ground Truth, Active Learning, Label Quality
    • 5.Week 1 Comprehensive Review: ML Overview & Data Engineering 1
  • Week 2
  • Week 3
  • Week 4
  • Week 5
    • 1.Statistics Basics: Distributions, Central Tendency, Spread, Transformations, and Sample vs Population
    • 2.Correlation and Relationships: Correlation Coefficients, Causation vs. Correlation, Multivariate Relationships
    • 3.Data Leakage: Causes, Detection, Prevention, and Time-Series and Target Leakage
    • 4.Validation Design: Train/Validation/Test Splits, Cross-Validation, Time-Series Splits, Stratified Sampling
    • 5.Week 5 Comprehensive Review: Statistics and Validation Design
  • Week 6
  • Week 7
  • Week 8
  • Week 9
  • Week 10
  • Week 11
  • Week 12
SQLD · 개발자SQL Developer (SQLD)

© CertNote · 주간랩스

  • About
  • Changelog
  • Contact
  • Terms
  • Privacy
← MLS-C01/Week 5/Day 5

Based on the MLS-C01 exam guide·Report an error

MLS-C01· AssociateWeek 5 · Day 5~32 min read

Day 5 - Week 5 Comprehensive Review: Statistics and Validation Design

📌 Key Takeaways

  • This week converges on a single question: "Can I trust my validation score?" If any one of statistics, correlation, leakage, or validation collapses, the score becomes an illusion.
  • Look at the distribution first (skewness, outliers) and then choose a robust statistic. Linear scaling cannot change the shape.
  • Correlation is not causation. Suspect confounders and reverse causation, and diagnose correlation among explanatory variables (multicollinearity) with VIF.
  • Leakage is a matter of timing. "Could we have known this value at the moment of prediction?" is the only criterion.
  • The nature of the data determines the validation design. Imbalance → stratification, time series → TimeSeriesSplit, groups → GroupKFold, small data → k-fold.

Flow Map: Statistics → Correlation → Leakage → Validation

This week covered the second half of EDA: statistics basics and validation design. These are four things: summarizing data honestly (statistics), reading relationships between variables (correlation), avoiding the traps that contaminate evaluation (leakage), and credibly estimating generalization performance (validation). These four are the last gate of MLS-C01 Domain 2, and the place where the answer to "why does my model fail in production?" hides.

[Data]
   │
   ├─ 1) Statistics basics (Day1)
   │     Distribution: check skewness and kurtosis first (Anscombe's quartet)
   │     Center: median if skewed, mean if symmetric
   │     Spread: standard deviation / IQR, IQR is the robust one
   │     Transformation: linear (standardization) = shape unchanged, log/Box-Cox = reduces skew
   │     Sample ↔ population: CLT, suspect representativeness and bias
   │
   ├─ 2) Correlation and relationships (Day2)
   │     Pearson (linear) vs Spearman (monotonic, robust)
   │     Correlation ≠ causation: reverse causation, confounders, chance
   │     Multicollinearity: VIF>5–10, linear model coefficients unstable (trees insensitive)
   │     Categorical: chi-square / Cramér's V
   │
   ├─ 3) Data leakage (Day3)
   │     Target leakage: outcome information flows in → not caught by splitting, check timing
   │     Time-series leakage: no random splits, no future windows
   │     Train-test contamination: after splitting, fit on the training part only, wrap in a Pipeline
   │
   └─ 4) Validation design (Day4)
         Three-way split: test is sealed to the end, viewed exactly once
         k-fold: saves data, mean ± standard deviation (k=5/10)
         Stratification: essential for imbalanced classification
         Time series: TimeSeriesSplit (past → future)
 
   ▼
[A trustworthy validation score] ──▶ Model selection and tuning decisions become valid at last

The four stages are not an ordered pipeline but gates that check one another. If you misread the distribution, the transformation is wrong; if the transformation is done on the entire dataset, it becomes leakage; and if there is leakage, however sophisticated the validation design, the score is false.

Comparison Tables for Easily Confused Pairs

This week's content is tested as questions that "distinguish two things that look similar."

Pearson vs Spearman

ItemPearsonSpearman
What it measuresLinear relationshipMonotonic relationship (need not be a straight line)
Computed fromActual valuesRanks
OutliersVery sensitiveRobust
U-shaped nonlinearr ≈ 0, misses the relationshipAlso low if not monotonic, but catches curved monotonic relationships
Clue to pick it"Continuous, straight-line relationship""Many outliers," "rank or grade data," "nonlinear but consistent direction"

Standardization vs Normalization (Min-Max)

ItemStandardization (Z-score)Normalization (Min-Max)
Formula(x − μ) / σ(x − min) / (max − min)
ResultMean 0, standard deviation 1Range [0, 1]
Distribution shapeUnchangedUnchanged
OutliersSensitive (μ and σ get pulled)Very sensitive (a single max compresses everything)
Clue to pick it"Default for linear models, neural networks, PCA""The input range must be fixed to [0,1]"

Neither method removes skewness. To reduce skewness you need a nonlinear transformation such as log, Box-Cox, or Yeo-Johnson.

Target Leakage vs Train-Test Contamination

ItemTarget leakageTrain-test contamination
Where the leak isThe feature itselfThe preprocessing and splitting procedure
Caught by splitting?No (every split is contaminated equally)Yes (fixed just by correcting the order)
SymptomValidation and test both high, only production lowValidation high but test low from the start
FixAudit feature generation time, remove that featureSplit first → fit on the training part only → Pipeline

k-fold vs TimeSeriesSplit

Itemk-foldTimeSeriesSplit
AssumptionRows are independent and exchangeableThe order itself is information
Split methodTake turns validating each foldTraining is always earlier than validation
Data usageEvery row is used for validation onceThe early period is never used for validation
If used on a time seriesLeakage from predicting the past with the futureSame structure as the deployment situation

validation vs test

ItemValidation setTest set
PurposeHyperparameter and model selectionFinal performance estimate
Times usedMany timesExactly once
If contaminatedSelection bias accumulates and the score is optimisticThe reported number itself becomes false
Why separateBecause of the multiple comparisons problemIt is honest only if never used

Stratified Split vs GroupKFold

ItemStratifiedGroupKFold
What it preservesClass ratioGroup integrity (the same group on only one side)
Situation to useImbalanced classificationMultiple rows from the same user or patient
If not usedSome folds lack the minority classThe same entity straddles both sides and performance is inflated

Key Decision Summary

Center and Spread: What Should You Report?

SituationCenterSpread
Symmetric distributionMeanStandard deviation
Skew or outliers presentMedianIQR
CategoricalMode—

Transformation: Does It Change the Shape?

OperationDistribution shapeRequirement
Standardization, Min-Max (linear)Unchanged (skew retained)None
Log, square root (nonlinear)Reduces right skewx ≥ 0
Box-CoxApproaches normalx > 0 (positive only)
Yeo-JohnsonApproaches normalAllows negatives and zero

Measuring Relationships: What Should You Use?

Relationship / dataRecommended
Linear, continuousPearson
Nonlinear/monotonic, outliers presentSpearman
Two categorical variablesChi-square / Cramér's V
Categorical ↔ continuousGroup mean comparison (ANOVA), boxplot
Multicollinearity diagnosisCorrelation heatmap + VIF (warning at >5–10)

Blocking Leakage: Golden Rules

PrincipleExecution
Split firstTakes priority over preprocessing
Fit on the training part onlyScalers, encoders, imputers
Use a PipelineAutomatic isolation per fold
Time series in time orderNo random splits
Audit feature generation time"Can we know it at prediction time?"
Clean up duplicates and groupsHandle before splitting

Validation Strategy Selection

Data characteristicRecommended validation
General classification, plenty of dataStratified three-way split
Data is scarceStratified k-fold
Class imbalanceStratification mandatory + PR-AUC and recall
Time seriesTimeSeriesSplit
Group structure (users, patients)GroupKFold
Honest evaluation including tuningNested CV

Question Clue → Answer Mapping Table

Phrase in the questionSignal to readAnswer to pick
"There is a time order / daily or monthly data"Time seriesTimeSeriesSplit, rolling after shift
"The class is 0.5%"Extreme imbalanceStratified split + PR-AUC and recall (rule out accuracy)
"Data is scarce (a few hundred records)"A single split is unstablek-fold cross-validation, mean ± standard deviation
"Income/price is stretched to the right"Positive skewLog or Box-Cox, report the median
"Still skewed even after standardizing"A linear transformation leaves the shape unchangedA nonlinear transformation is needed
"Zeros and negatives are mixed in"Log and Box-Cox are impossibleYeo-Johnson
"VIF is 15 / the coefficient signs flipped"MulticollinearityRemove variables, PCA, Ridge (can be ignored if trees)
"The correlation is high, so increasing A will increase B"Causal leapWrong. Suspect confounders and reverse causation; A/B test needed
"Validation and test are both high, only production is low"Leakage not caught by splittingTarget leakage
"Scaled on the entire dataset, then split"Test statistics flowed inFit inside each fold with a Pipeline
"Multiple test records for the same patient"Group structureGroupKFold
"The model was fixed while watching the test score"Sealing violatedThe final estimate is contaminated

AWS Service Mapping Table (Weekly Integration)

SituationAWS service / featureReason
Explore distribution, missing values, and correlation without code and chain on transformationsSageMaker Data WranglerVisual analysis and transformation remain as a single flow that can be reproduced
Fix preprocessing identically for training and inferenceSageMaker Processing JobReusing the script reduces both training-serving skew and leakage
Manage feature definitions as shared by the teamSageMaker Feature StoreTraining and inference share the same definitions, preventing point-in-time mismatch
Fix the order of splitting, preprocessing, training, and evaluation in codeSageMaker PipelinesStructurally blocks procedural mistakes such as "preprocessing before the split"
Check class imbalance and bias before training, and feature attribution after trainingSageMaker ClarifyLook at both sample representativeness problems and single-feature monopoly (a leakage signal)
Automatically search hyperparameters against a validation metricSageMaker automatic model tuningSpecify an objective metric and compare multiple training jobs
Monitor input distribution and performance gap after deploymentSageMaker Model MonitorCatches the difference between validation and production early

Wrong-Answer Notes: What Is Easy to Get Wrong This Week

💡 Concept: This week's content converges on a single question: "Can I trust my validation score?" Statistics (distribution, sampling) ensure that the data represents the population, correlation analysis keeps you from mistaking a relationship for causation, leakage checks keep future and outcome information from seeping in, and validation design guarantees that the test set is truly independent. If any one of these four collapses, the validation score is an illusion, not generalization.

Common misconceptionWhy it is wrongCorrect understanding
① Standardizing removes skewA linear transformation changes only location and scaleThe shape stays the same. Log or Box-Cox is needed
② A strong correlation means causationThere are confounders, reverse causation, and chanceCausation only through experimental design or confounder control
③ A correlation of 0 means no relationshipPearson sees only linearA nonlinear relationship such as a U shape may be hiding
④ If you just split well, there is no leakageTarget leakage is inside the featureYou must audit feature generation time
⑤ It is fine to scale on the entire dataset and then splitTest statistics leak into trainingSplit first, fit on the training part only
⑥ A random split is enough for time series tooThe order is informationChronological split (forward-chaining)
⑦ A random split is fine for imbalanced data tooThe minority class can vanish from a foldStratified split
⑧ Accuracy is high on imbalanced data, so it is a good modelIt is high even if only the majority class is rightRe-examine with PR-AUC and recall
⑨ It is fine to tune while watching the test setThe test set becomes a validation setSeal it, look exactly once
⑩ The larger k, the unconditionally betterVariance and computational cost growk=5–10 is the balance point
⑪ Multicollinearity is fatal to every modelTree-based models are insensitive in predictionCoefficients collapse only in linear models

Integrated Checklist Code

from sklearn.pipeline import Pipeline
from sklearn.impute import SimpleImputer
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import StratifiedKFold, cross_val_score
 
# Block leakage + handle imbalance at once: Pipeline + StratifiedKFold
pipe = Pipeline([
    ("impute", SimpleImputer(strategy="median")),   # median imputation to cope with skew
    ("scale", StandardScaler()),                     # fit only on each fold's training part
    ("clf", LogisticRegression(class_weight="balanced")),
])
skf = StratifiedKFold(n_splits=5, shuffle=True, random_state=42)
scores = cross_val_score(pipe, X, y, cv=skf, scoring="f1")
print(f"F1: {scores.mean():.3f} ± {scores.std():.3f}")

⚠️ Pitfall Roundup: ① Standardization removes skew (no, the shape is unchanged) ② A strong correlation is causation (no, suspect confounders) ③ If you split well, leakage disappears (no, target leakage slips through) ④ Split after scaling the entire dataset (no, leakage) ⑤ Random split for time series (no, chronological) ⑥ Random split for imbalanced data (no, stratify) ⑦ Tune with the test set (no, seal it and look once).

The week in one sentence: "An honest validation score holds only on top of good statistics, understanding of relationships, leakage blocking, and validation design."

Next week we move beyond EDA into modeling (Domain 3), and see how algorithm selection, training, and evaluation work on the statistical and validation foundation built so far.

📖 Glossary

  • Robust statistic: A statistic that is not shaken much by outliers. The median and IQR are the standard examples.
  • Linear transformation invariance: The property that transformations that change only location and scale, such as standardization and Min-Max, cannot change the distribution's shape.
  • Confounder: A hidden variable that influences both variables and creates a spurious correlation.
  • Multicollinearity: The phenomenon in which explanatory variables are strongly correlated with each other, making regression coefficient estimates unstable. VIF of 5–10 is the warning line.
  • Target leakage: Leakage in which outcome information about the prediction target is in a feature. It is not caught by any split.
  • Train-test contamination: The phenomenon in which preprocessing before the split leaks test information into training. Prevented with a Pipeline.
  • Stratified sampling: A way of splitting so that each split preserves the original class ratio.
  • GroupKFold: Cross-validation that keeps rows from the same group from being separated between training and validation.
  • PR-AUC: The area under the precision-recall curve. More honest than accuracy or ROC-AUC when the positive ratio is very low.
  • Multiple comparisons problem: The phenomenon in which comparing multiple candidates on the same validation set selects one that fits by chance, optimistically biasing the score.

📝 Practice Questions

Click a choice to reveal the answer and explanation.

Question 1

After standardizing (StandardScaler) a right-skewed variable, the mean became 0 and the standard deviation 1. What happened to the skew of the distribution?

Question 2

Validation accuracy and test accuracy are both 98%, but production performance dropped to 60%. The split was clean. What is the MOST likely cause?

Question 3

The Pearson correlation between two variables is very high at 0.9. What is the correct interpretation?

Question 4

You run 5-fold cross-validation on classification data with a 95:5 class imbalance. In some folds the minority class is almost absent, distorting the metrics. What is the solution?

Question 5

You want to apply missing-value imputation and scaling in scikit-learn during cross-validation without leakage. Which configuration is MOST appropriate?

PreviousValidation Design: Train/Validation/Test Splits, Cross-Validation, Time-Series Splits, Stratified SamplingWeek 5 · Day 4Next Algorithm Selection: Mapping by Problem TypeWeek 6 · Day 1

Official references

  • MLS-C01 official exam page(opens in a new tab)
  • Amazon SageMaker AI documentation(opens in a new tab)

On this page

  • Key Takeaways
  • Flow Map: Statistics → Correlation → Leakage → Validation
  • Comparison Tables for Easily Confused Pairs
  • Pearson vs Spearman
  • Standardization vs Normalization (Min-Max)
  • Target Leakage vs Train-Test Contamination
  • k-fold vs TimeSeriesSplit
  • validation vs test
  • Stratified Split vs GroupKFold
  • Key Decision Summary
  • Center and Spread: What Should You Report?
  • Transformation: Does It Change the Shape?
  • Measuring Relationships: What Should You Use?
  • Blocking Leakage: Golden Rules
  • Validation Strategy Selection
  • Question Clue → Answer Mapping Table
  • AWS Service Mapping Table (Weekly Integration)
  • Wrong-Answer Notes: What Is Easy to Get Wrong This Week
  • Integrated Checklist Code
  • Glossary
  • Practice Questions