Data Science

Bridge To Machine Learning

From EDA to Modeling: What Changes

Every technique across Modules 1-6 has served one of two related but distinct goals — and machine learning shifts the emphasis toward the second in a way worth

JrCodex·7 min read

Jr Codex Data Science Notes

Level: Advanced Prerequisites: Module 6: Data Science in Practice Time to complete: ~20 minutes


Table of Contents

  1. Explanation vs Prediction
  2. A New Goal Changes What "Good" Means
  3. The Train/Test Split — a New Kind of Data Division
  4. What Carries Over Directly
  5. What's Genuinely New
  6. A Worked Example — the Same Dataset, Two Goals
  7. Summary & Next Steps

1. Explanation vs Prediction

Every technique across Modules 1-6 has served one of two related but distinct goals — and machine learning shifts the emphasis toward the second in a way worth naming explicitly before diving into the Machine Learning notes.

Explanation                            Prediction
─────────────────────────────         ─────────────────────────────
  "WHY did this happen?"                 "What will happen NEXT, for
                                            a case we haven't seen yet?"

  Module 1's hypothesis testing,           A model trained on past data,
  Module 3's EDA, Module 5's A/B            evaluated on its ability to
  testing — all ask WHY/WHETHER an           generalize to NEW, unseen data
  effect is real
─────────────────────────────         ─────────────────────────────

Both goals use overlapping tools (statistics, pandas, visualization) — but they optimize for different things, and conflating them is a common source of confusion when first encountering machine learning.


2. A New Goal Changes What "Good" Means

import pandas as pd
from scipy import stats
 
df = pd.DataFrame({
    "marketing_spend": [1000, 1500, 2000, 2500, 3000],
    "sales": [12000, 15500, 18000, 22500, 25000],
})
 
# EXPLANATION goal (Module 1, Ch.5): is there a real relationship?
correlation = df["marketing_spend"].corr(df["sales"])
print(f"Correlation: {correlation:.3f}")      # answers: IS there a relationship, and how strong?
 
# PREDICTION goal (Machine Learning notes): given a NEW spend level, what sales
# would we expect? This requires FITTING a model and checking how well it
# generalizes to data it DIDN'T see during fitting — a fundamentally different
# question than "is this correlation real."
Different Success Criteria
─────────────────────────────────────────
  Explanation:  "Is this relationship statistically significant?
                  Is the effect size meaningful?" (Module 1, Ch.6;
                  Module 5, Ch.2)

  Prediction:     "How accurately does this model predict sales for
                    a NEW marketing spend value it never saw during
                    training?" — measured with metrics like RMSE or
                    accuracy, covered in the Machine Learning notes'
                    Model Evaluation chapter
─────────────────────────────────────────

3. The Train/Test Split — a New Kind of Data Division

Module 5, Chapter 4 introduced a chronological train/test split specifically for time series forecasting. Machine learning generalizes this idea to all predictive modeling, even non-time-based data.

from sklearn.model_selection import train_test_split
import pandas as pd
import numpy as np
 
np.random.seed(0)
df = pd.DataFrame({
    "marketing_spend": np.random.randint(500, 5000, 200),
    "sales": np.random.randint(8000, 30000, 200),
})
 
# Split BEFORE fitting anything — train on 80%, evaluate on the untouched 20%
train_df, test_df = train_test_split(df, test_size=0.2, random_state=42)
 
print(f"Training set: {len(train_df)} rows")
print(f"Test set: {len(test_df)} rows")
Why This Split Exists
─────────────────────────────────────────
  A model can always fit the data it was TRAINED on well —
  that tells you nothing about whether it will work on NEW data.

  The test set simulates "new, unseen data" — evaluating a
  model ONLY on data it never touched during fitting is the
  standard way to estimate real-world predictive performance.
─────────────────────────────────────────

This is conceptually related to, but distinct from, Module 3's EDA practice — EDA (Module 3) is typically done on the full dataset to understand it; a train/test split is specifically about evaluating a model's ability to generalize, a concern that doesn't arise until you're building something meant to predict on new data.


4. What Carries Over Directly

Nearly everything built across this Data Science curriculum remains directly useful once you start machine learning — none of it becomes obsolete.

Skill                        How It Carries Over
─────────────────────────────────────────
  Module 1: Statistics          Understanding distributions, correlation,
                                   and hypothesis testing underlies model
                                   evaluation metrics and diagnostics
  Module 2: Wrangling             EVERY model needs clean, well-prepared
                                    input data — this work doesn't disappear,
                                    it becomes "preprocessing" (ML terminology)
  Module 2, Ch.5: Feature           Directly reused — the ML notes' Data
    Engineering                       Preprocessing chapter builds on exactly
                                        this foundation
  Module 3: EDA                        Still the essential FIRST step before
                                          modeling anything — understanding your
                                          data doesn't stop mattering once
                                          you're predicting with it
  Module 4: Visualization                Used throughout ML for diagnosing
                                            model behavior (residual plots,
                                            confusion matrices, learning curves)
  Module 5: Statistical rigor              The same rigor around significance,
                                              effect size, and avoiding
                                              p-hacking applies to comparing
                                              model performance too
─────────────────────────────────────────

5. What's Genuinely New

New Concepts the Machine Learning Notes Introduce
─────────────────────────────────────────
  Algorithms:        specific mathematical approaches for learning
                       patterns from data (linear regression, decision
                       trees, ensembles, and more)
  Model evaluation:    metrics specifically for predictive accuracy
                         (RMSE, accuracy, precision/recall, ROC-AUC) —
                         DIFFERENT from Module 1's p-values, though
                         built on the same statistical foundations
  Overfitting:           a model that fits its TRAINING data extremely
                           well but generalizes poorly to new data — a
                           concern that simply doesn't exist in pure EDA
                           or hypothesis testing
  Hyperparameter tuning:   systematically searching for the best
                             configuration of a model's own settings
─────────────────────────────────────────

Overfitting deserves special attention as the single most important new idea: it's the machine-learning-specific failure mode that the train/test split (Section 3) exists specifically to detect — a model can look perfect on training data while being nearly useless in the real world, something none of Modules 1-6's techniques would catch on their own.


6. A Worked Example — the Same Dataset, Two Goals

import pandas as pd
import numpy as np
from scipy import stats
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error
 
np.random.seed(1)
df = pd.DataFrame({
    "study_hours": np.random.uniform(0, 10, 100),
})
df["exam_score"] = 50 + df["study_hours"] * 4 + np.random.normal(0, 5, 100)
 
# GOAL 1 — Explanation (Module 1, Ch.5-6): is there a real relationship?
correlation = df["study_hours"].corr(df["exam_score"])
_, p_value = stats.pearsonr(df["study_hours"], df["exam_score"])
print(f"Correlation: {correlation:.3f}, p-value: {p_value:.5f}")
# Answers: YES, study hours and exam score are significantly related
 
# GOAL 2 — Prediction (Machine Learning notes): how well can we predict
# a NEW student's score, given their study hours?
X = df[["study_hours"]]
y = df["exam_score"]
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
 
model = LinearRegression()
model.fit(X_train, y_train)                     # fit ONLY on training data
predictions = model.predict(X_test)                # predict on data the model never saw
 
rmse = np.sqrt(mean_squared_error(y_test, predictions))
print(f"Test set RMSE: {rmse:.2f}")      # answers: HOW ACCURATELY can we predict a new score?

Same dataset, two different, complementary questions — the correlation/p-value tells you the relationship is real; the train/test RMSE tells you how precisely you could actually predict a new student's score using it. Both are valid, useful outputs of the same underlying data.


7. Summary & Next Steps

Key Takeaways

  • Data science work generally serves two related goals: explanation (is this relationship real?) and prediction (how accurately can we forecast a new case?) — machine learning shifts emphasis toward the latter.
  • The train/test split evaluates a model only on data it never touched during fitting, since performance on training data alone says nothing about real-world generalization.
  • Nearly everything from Modules 1-6 — statistics, wrangling, EDA, visualization, experimental rigor — remains directly useful in machine learning; none of it becomes obsolete.
  • Overfitting (fitting training data well but generalizing poorly) is the genuinely new failure mode that pure EDA and hypothesis testing don't encounter, and the train/test split exists specifically to catch it.

Concept Check

  1. What's the difference between the question "is this correlation statistically significant?" and "how accurately can this relationship predict a new case?"
  2. Why is a model's performance on its own training data not sufficient evidence that it will work well on new data?
  3. Name three skills from this Data Science curriculum that carry over directly into machine learning, and explain how.

Next Chapter

Chapter 2: Mapping This Curriculum to Machine Learning


Jr Codex — 1-on-1 Personalized Coaching | Back to Module Index