Skip to main content
Sports Predictor is a Python-based machine learning tool that fetches real NBA game data, engineers rolling-window features, and trains a Random Forest classifier to predict game outcomes. It also includes a betting engine that converts odds formats and evaluates whether a predicted probability represents a worthwhile wager.

Quickstart

Get up and running — fetch data, train the model, and make your first prediction in minutes.

Data Pipeline

Learn how game data is fetched from the NBA API and stored in SQLite.

Model

Understand how the Random Forest classifier is trained, tuned, and used for inference.

Betting Engine

Convert between odds formats and evaluate whether a win probability is worth betting.

How it works

1

Fetch game data

Pull NBA regular season game logs for a given season using fetch_games_teamwins(). Data is stored in a local SQLite database.
2

Generate features

Run generate_features_teamwins() to compute rolling averages for points, rebounds, and assists, and persist them to the team_game_stats table.
3

Train the model

Call train_model_teamwins() to fit a Random Forest classifier on the feature table. The trained model is saved to models/nba_model.pkl.
4

Predict and evaluate

Use predict_game_teamwins() to get a win probability for any matchup, then pass it to evaluate_bet_teamwins() to get a bet recommendation.

Key features

  • NBA data ingestion — Pulls team game logs directly from the NBA Stats API via nba_api
  • Rolling-window features — Computes 5-game rolling averages for points, rebounds, and assists for both teams
  • Random Forest classifier — 200-estimator ensemble model trained with an 70/30 train/test split
  • Bet evaluation — Three-tier rating system: Good Bet, Slight Edge, or Avoid
  • Odds conversion — Convert between American odds, decimal odds, and implied probabilities
Sports Predictor currently supports NBA regular season data. College basketball (CBB) model files are present but the pipeline defaults to NBA.

Build docs developers (and LLMs) love