Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

NFL Predictor

Predicts NFL game outcomes using machine learning. Uses logistic regression with team stats from 2015-2025, combining long-term averages and recent form to make predictions.

Setup

  1. Clone this repo and navigate to the folder

  2. Create a virtual environment:

    • Windows: python -m venv venv
    • Mac/Linux: python3 -m venv venv
  3. Activate it:

    • Windows (PowerShell): .\venv\Scripts\Activate.ps1
    • Windows (CMD): venv\Scripts\activate.bat
    • Mac/Linux: source venv/bin/activate

    If you get an execution policy error on Windows, run:

    Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process
  4. Install dependencies:

    pip install -r requirements.txt

Running

Just run:

python main.py

The program loads NFL data (will download on first run), trains a model on historical games, and can make predictions. Some features are commented out in the code - feel free to uncomment Block 8 if you want to see the visualization charts.

The model uses two types of features:

  • Anchor: Long-term team averages
  • Spark: Recent form (weighted last 5 games)

Team Names

You can use abbreviations or full names (e.g., "kc", "chiefs", or "Kansas City Chiefs"). See team_abbr_map in main.py for all options.

How It Works

The script is organized into blocks that run sequentially:

Block 2: Data Loading - Downloads team stats and schedules from 2015-2025 using nflreadpy

Block 3: Team Mapping - Converts team abbreviations to full names so everything is standardized

Block 4: Data Merging - Combines stats with win/loss records from schedules. Creates rows where each game has data for both teams involved.

Block 5: Feature Engineering - This is where the magic happens. Creates two types of features:

  • Anchor features: Expanding mean of all historical stats (lifetime averages). This captures long-term team quality.
  • Spark features: Exponentially weighted moving average of last 5 games (recent form). This catches hot/cold streaks.
  • Also adds opponent stats (both Anchor and Spark) and home/away indicator
  • Each row ends up with ~100+ features combining both teams' stats

Block 6: Walk-Forward Backtesting (currently commented out) - Simulates a season week-by-week:

  • For each week in the target season, trains the model on ALL previous data (past seasons + earlier weeks)
  • Makes predictions for that week's games
  • Calculates accuracy and tracks results
  • Uses this walk-forward approach to avoid look-ahead bias

Block 7: Interactive Predictions (currently commented out) - After backtesting:

  • Retrains model on full dataset
  • Lets you input any matchup (home team vs away team)
  • Outputs win probabilities for both teams

Block 8: Visualization (currently commented out) - Creates charts showing:

  • Weekly accuracy (volatile, shows "Spark")
  • Cumulative season accuracy (stable trend, shows "Anchor")
  • Reference lines at 50% (coin flip) and 60% (pro target)

Currently, only Blocks 1-5 run by default. Uncomment the sections you want to use!

Troubleshooting

  • Module not found: Make sure venv is activated and run pip install -r requirements.txt again
  • Slow first run: Data download takes a few minutes initially, then it's cached

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages