Spaces:
Running
Running
A newer version of the Streamlit SDK is available: 1.58.0
metadata
title: NBA Fantasy Predictor
emoji: π
colorFrom: blue
colorTo: red
sdk: streamlit
sdk_version: 1.53.1
python_version: 3.11
app_file: app.py
pinned: false
license: apache-2.0
NBA Fantasy Predictor
A modern Streamlit application that allows you to build a custom NBA fantasy team and compete against computer-generated opponents. The application uses a neural network model to predict game outcomes based on historical player statistics.
π Live App
Play the game here.
π Features
- Two-Page Interface: Streamlit app with a team builder and game prediction simulator, plus a landing page.
- Advanced Team Builder:
- Search for players from a dataset of historical NBA stats (local CSV).
- Input validation for secure and accurate player searches.
- Build a 5-player roster with real-time preview.
- Dynamic Opponents: Choose from multiple difficulty levels to generate challenging computer teams.
- Foundation Model Architecture:
- A complete neural network setup trained on the 2018 NBA season data.
- Implemented using Keras/TensorFlow with a focus on reproducibility and extensibility.
- Despite the focused dataset, it demonstrates a full ML lifecycle: data preprocessing, hyperparameter optimization, and deployment.
- ML-Powered Predictions:
- Predicts win probability and outcomes based on the combined stats of both starting lineups.
- Utilizes automated hyperparameter tuning via
RandomizedSearchCV.
- Game Simulation: Generates dynamic quarter-by-quarter box scores based on model predictions.
- Clean Architecture: Modular codebase with clear separation of concerns (ML, database, validation, and state management).
π Project Structure
βββ app.py # Main entry point
βββ pages/ # Streamlit page modules
βββ src/ # Core application logic
β βββ config.py # Constants, presets, logging setup
β βββ database/ # CSV data loading and queries
β βββ ml/ # Model loading and prediction
β βββ models/ # Data models and schemas
β βββ state/ # Session state management
β βββ utils/ # UI and helper utilities
β βββ validation/ # Input validation logic
βββ tests/ # Test suite
βββ scripts/ # Training and utility scripts
βββ snowflake_nba.csv # Player stats dataset (runtime data source)
βββ winner.keras # Pre-trained prediction model
βββ .github/workflows/ # CI and release workflows
βββ .pre-commit-config.yaml # Pre-commit hook configuration
βββ .streamlit/config.toml # Streamlit theme/settings
βββ pyproject.toml # Project metadata and dependencies
βοΈ Usage
Quick Start with uv (Recommended)
# Install the project and run the app
uv pip install -e .
streamlit run app.py
Development Setup
# Install with dev dependencies (testing, linting, type checking)
uv pip install -e ".[dev]"
π§ͺ Development
Running Tests
# Run all tests
pytest
# Run tests with coverage
pytest --cov=src
Linting and Type Checking
# Run Ruff for linting and formatting
ruff check src/ tests/
# Run Mypy for static type checking
mypy src/
Training the Model
The training script rebuilds the model from scratch using 2018 NBA season results. It requires two input files in the project root:
player_stats.txt-- player roster and statisticsschedule.txt-- game schedule with scores
Run the training:
python scripts/compile_model.py
The script uses RandomizedSearchCV to search for optimal hyperparameters and saves the result as winner.keras, which is required at runtime for game predictions.
π Data Files and Configuration
snowflake_nba.csv: Player statistics dataset loaded at runtime bysrc/database/connection.py. Path is resolved relative to the module location (project root).winner.keras: Pre-trained Keras model loaded bysrc/ml/model.py. Path is resolved relative to the module location (project root).src/config.py: Central configuration for column names, team size, difficulty presets, score ranges, and logging setup.
π License
This repository is licensed under the Apache License 2.0.