Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

ย 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿงพ An Experimental Study of Underfitting and Overfitting in Supervised Machine Learning Using Polynomial Regression

๐ŸŽฏ Aim

To understand how model complexity affects generalization performance in supervised machine learning.

๐ŸŽฏ Objectives

  • Define and understand underfitting and overfitting
  • Experimentally observe the effect of model complexity
  • Analyze training error vs validation error relationships
  • Understand the biasโ€“variance tradeoff
  • Identify the optimal model complexity for generalization

๐Ÿ“Œ Problem Statement

In supervised machine learning, selecting an appropriate model complexity is critical for achieving good generalization performance.

The Challenge:

  • Too simple models โ†’ fail to capture underlying patterns (underfitting)
  • Too complex models โ†’ memorize noise instead of patterns (overfitting)

Research Question:

How can we experimentally observe and quantify the effects of model complexity on model generalization?

๐Ÿงช Methodology

1๏ธโƒฃ Data Generation

We generate synthetic nonlinear regression data using:

y = sin(x) + noise
  • Function: Sinusoidal pattern to create a known nonlinear relationship
  • Noise: Gaussian noise added to simulate real-world uncertainty
  • Purpose: Controlled environment to study model behavior

2๏ธโƒฃ Data Splitting

The dataset is split into:

Split Purpose
Training Set Model learning and parameter fitting
Validation Set Generalization performance evaluation

3๏ธโƒฃ Model Selection

We use Polynomial Regression which allows precise control over model complexity via polynomial degree.

Degree Range Expected Behavior
1 Underfitting (too simple)
4โ€“6 Good fit (optimal complexity)
15โ€“20 Overfitting (too complex)

4๏ธโƒฃ Evaluation Metrics

We compute Mean Squared Error (MSE) for:

  • Training error (performance on training data)
  • Validation error (performance on unseen data)

5๏ธโƒฃ Analysis Approach

  • Visualization: Plot regression curves for different complexities
  • Error Analysis: Plot training vs validation error curves
  • Optimization: Identify complexity where validation error is minimized
  • Theoretical: Interpret results using biasโ€“variance decomposition

๐Ÿ”„ Research Workflow

flowchart TD
    A[Start] --> B[Define Research Question]
    B --> C[Generate Synthetic Dataset]
    C --> D[Split Data: Train/Test]
    D --> E[Select Polynomial Degrees]
    E --> F[Train Model for Each Degree]
    F --> G[Compute Training Error]
    G --> H[Compute Validation Error]
    H --> I[Create Visualizations:<br/>โ€ข Regression Curves<br/>โ€ข Error vs Complexity]
    I --> J[Analyze Biasโ€“Variance Behavior]
    J --> K[Draw Conclusions]
    K --> L[End]
Loading

๐Ÿง  Theoretical Framework

Bias-Variance Tradeoff

Generalization Error = Biasยฒ + Variance + Irreducible Noise
Model Complexity Bias Variance Result
Low (Simple) High โ†‘ Low โ†“ Underfitting
Optimal Balanced Balanced Good Generalization
High (Complex) Low โ†“ High โ†‘ Overfitting

Expected Error Behavior

Model Complexity โ†’

         Validation Error
              โ†‘
              |     โ•ญโ”€โ•ฎ
              |    โ•ฑ   โ•ฒ
              |   โ•ฑ     โ•ฒ
              |  โ•ฑ       โ•ฒ
              | โ•ฑ         โ•ฒ
   Training   |โ•ฑ___________โ•ฒ___
   Error      |             โ•ฒ
              |______________โ•ฒ____โ†’
           Under-   Optimal   Over-
           fitting            fitting

๐Ÿ“Š Current Progress & Status

โœ… Completed Implementation

Component Status Description
Data Generation โœ… Complete Synthetic sin(x) + noise generation with configurable parameters
Model Training โœ… Complete Polynomial regression with degree control and MSE evaluation
Visualization โœ… Complete Regression curve plots and error curve visualization functions
Project Setup โœ… Complete Virtual environment, dependencies, and proper project structure
Documentation โœ… Complete Comprehensive README with theory and methodology
Jupyter Notebook โœ… Complete Interactive experiment analysis setup
Version Control โœ… Complete Git repository with proper .gitignore and initial commit

๐Ÿ”ฌ Initial Experiment Setup

  • Data Generated: 100 synthetic data points using y = sin(x) + Gaussian noise
  • Train/Test Split: 70/30 split for proper evaluation
  • Model Degrees Tested: [1, 5, 15] representing underfitting, good fit, and overfitting
  • Evaluation Metric: Mean Squared Error (MSE) for both training and test sets
  • Visualization: Ready to generate regression curves and error plots

๐ŸŽฏ Next Steps & Roadmap

๐Ÿ“ˆ Phase 1: Comprehensive Experiment Execution (Next Week)

  1. Run Full Experiment

    • Execute complete polynomial degree sweep (1-20)
    • Generate training vs validation error curves
    • Create regression curve visualizations for key degrees
    • Document numerical results and observations
  2. Results Analysis

    • Identify optimal polynomial degree
    • Quantify bias-variance tradeoff observations
    • Create comprehensive plots showing underfitting โ†’ optimal โ†’ overfitting transition

๐Ÿ” Phase 2: Extended Analysis (Following Week)

  1. Parameter Sensitivity Study

    • Test different noise levels (0.1, 0.2, 0.5, 1.0)
    • Vary dataset sizes (50, 100, 200, 500 samples)
    • Compare results across different random seeds
  2. Advanced Visualizations

    • Create animated plots showing complexity progression
    • Generate bias-variance decomposition plots
    • Add confidence intervals and error bars

๐Ÿ“ Phase 3: Documentation & Presentation (Final Week)

  1. Results Documentation

    • Update README with actual experimental findings
    • Create executive summary of key insights
    • Document lessons learned and theoretical confirmations
  2. Report Generation

    • Compile comprehensive experiment report
    • Create presentation slides summarizing findings
    • Prepare code demonstrations and walkthroughs

๐Ÿš€ Getting Started

Prerequisites

  • Python 3.8 or higher
  • Virtual environment (recommended)

Installation & Setup

# Clone or download the project
cd overfitting_ml

# Activate virtual environment
source .venv/bin/activate

# Install dependencies (within the activated virtual environment)
pip install -r requirements.txt

Usage

# Make sure virtual environment is activated
source .venv/bin/activate

# Option 1: Run individual modules for testing
python3 data_generation.py      # Test data generation
python3 model_training.py       # Test model training
python3 visualization.py        # Test visualization functions

# Option 2: Run interactive experiment analysis (Recommended)
jupyter notebook notebooks/experiment_analysis.ipynb

# Option 3: Run complete experiment (when main.py is created)
python3 main.py

๐Ÿ“ Project Structure

overfitting_ml/
โ”œโ”€โ”€ README.md                    # Project documentation (this file)
โ”œโ”€โ”€ .gitignore                   # Git ignore rules for Python ML projects
โ”œโ”€โ”€ requirements.txt             # Python dependencies
โ”œโ”€โ”€ .venv/                       # Virtual environment (excluded from git)
โ”œโ”€โ”€ data_generation.py           # โœ… Synthetic data generation functions
โ”œโ”€โ”€ model_training.py            # โœ… Polynomial regression training & evaluation
โ”œโ”€โ”€ visualization.py             # โœ… Plotting functions for analysis
โ”œโ”€โ”€ notebooks/
โ”‚   โ””โ”€โ”€ experiment_analysis.ipynb # โœ… Interactive Jupyter notebook for experiments
โ””โ”€โ”€ results/ (to be created)
    โ”œโ”€โ”€ plots/                   # ๐Ÿ“Š Generated regression and error curve plots
    โ”œโ”€โ”€ metrics/                 # ๐Ÿ“ˆ Numerical results and MSE data
    โ””โ”€โ”€ reports/                 # ๐Ÿ“ Analysis summaries and findings

๐Ÿ”ง Current File Status

  • โœ… Core modules: All implemented and tested
  • โœ… Dependencies: Installed and configured
  • โœ… Notebook: Ready for interactive experimentation
  • ๐Ÿ“‹ Results folder: Will be created during first experiment run

๐Ÿ”ฌ Key Learning Outcomes

  • Practical Understanding of underfitting vs overfitting
  • Hands-on Experience with model complexity tuning
  • Visualization Skills for model evaluation
  • Theoretical Connection between bias-variance tradeoff and real results

๐Ÿ“š References

  • Hastie, T., Tibshirani, R., & Friedman, J. (2009). The Elements of Statistical Learning
  • Bishop, C. M. (2006). Pattern Recognition and Machine Learning
  • James, G., Witten, D., Hastie, T., & Tibshirani, R. (2013). An Introduction to Statistical Learning

Author: Patrick Filima
Date: February 2026
Course: Machine Learning Fundamentals# underfitting-overfitting-ml-experiment

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages