IPL_PREDICTOR / README.md
ministerchief's picture
Update README.md
c5393ce verified
|
Raw
History Blame Contribute Delete
4.84 kB
---
license: mit
title: Cricket AI Predictor
sdk: docker
app_file: app.py
emoji: πŸƒ
colorFrom: blue
colorTo: purple
pinned: false
---
# 🏏 Cricket AI Predictor
A full-stack IPL ball-by-ball prediction system powered by 4 pre-trained XGBoost models.
## Features
| Page | Description |
|------|-------------|
| **Predict** | Input match data β†’ get dot ball %, boundary %, run distribution, expected runs, and win probability |
| **Simulate** | Ball-by-ball T20 innings simulation with live ML predictions and win probability chart |
| **Model Info** | Technical details, feature tables, label encodings, and API reference |
---
## Quick Start in VS Code
### Step 1 β€” Open the project
```
File β†’ Open Folder β†’ select cricket_predictor/
```
### Step 2 β€” Create a virtual environment
Open the **VS Code Terminal** (`Ctrl+\``) and run:
**Windows:**
```bash
python -m venv venv
venv\Scripts\activate
```
**Mac / Linux:**
```bash
python3 -m venv venv
source venv/bin/activate
```
### Step 3 β€” Install dependencies
```bash
pip install -r requirements.txt
```
### Step 4 β€” Run the app
**Option A β€” VS Code Debugger (recommended):**
- Press `F5` or go to **Run β†’ Start Debugging**
- Select **"Run Flask App"** configuration
**Option B β€” Terminal:**
```bash
python app.py
```
### Step 5 β€” Open in browser
```
http://127.0.0.1:5000
```
---
## Project Structure
```
cricket_predictor/
β”‚
β”œβ”€β”€ app.py # Flask application & routes
β”‚
β”œβ”€β”€ models/ # Pre-trained XGBoost model files
β”‚ β”œβ”€β”€ DotBall.pkl
β”‚ β”œβ”€β”€ BoundaryModel.pkl
β”‚ β”œβ”€β”€ RunPrediction.pkl
β”‚ └── IPLchasingTeamWin.pkl
β”‚
β”œβ”€β”€ utils/
β”‚ β”œβ”€β”€ __init__.py
β”‚ β”œβ”€β”€ predictor.py # CricketPredictor class (loads + runs all 4 models)
β”‚ └── encoders.py # Team/venue label encoding maps + phase logic
β”‚
β”œβ”€β”€ templates/
β”‚ β”œβ”€β”€ base.html # Shared navbar & layout
β”‚ β”œβ”€β”€ index.html # Prediction dashboard
β”‚ β”œβ”€β”€ simulate.html # Match simulation page
β”‚ └── model_info.html # Model details & API docs
β”‚
β”œβ”€β”€ static/
β”‚ └── css/
β”‚ └── style.css # Full application stylesheet
β”‚
β”œβ”€β”€ .vscode/
β”‚ β”œβ”€β”€ launch.json # F5 debugger config
β”‚ β”œβ”€β”€ settings.json # Editor & Python settings
β”‚ └── extensions.json # Recommended extensions
β”‚
β”œβ”€β”€ requirements.txt
└── README.md
```
---
## Models
| File | Task | Input Features | Classes |
|------|------|---------------|---------|
| `DotBall.pkl` | Dot ball probability | 18 | Binary (0/1) |
| `BoundaryModel.pkl` | Boundary probability | 18 | Binary (0/1) |
| `RunPrediction.pkl` | Run distribution | 18 | Multi-class (0–5) |
| `IPLchasingTeamWin.pkl` | Win probability (2nd inn.) | 8 | Binary (0/1) |
### Ball model features (18)
`striker_enc` Β· `bowler_enc` Β· `batting_team_enc` Β· `bowling_team_enc` Β· `venue_enc` Β· `over` Β· `ball_in_over` Β· `phase` Β· `current_score` Β· `wickets_fallen` Β· `run_rate` Β· `prev_runs` Β· `prev_wicket` Β· `last_6_runs` Β· `last_12_runs` Β· `last_6_wickets` Β· `batter_sr` Β· `bowler_eco`
### Win model features (8)
`batting_team` Β· `bowling_team` Β· `venue` Β· `innings` Β· `current_score` Β· `wickets_fallen` Β· `balls_remaining` Β· `run_rate`
---
## API Endpoints
### `POST /api/predict`
```json
{
"batting_team": "Mumbai Indians",
"bowling_team": "Chennai Super Kings",
"venue": "Wankhede Stadium",
"innings": 1,
"over": 14,
"ball_in_over": 3,
"current_score": 110,
"wickets_fallen": 2,
"batter_sr": 148,
"bowler_eco": 7.4,
"last_6_runs": 11,
"last_12_runs": 19
}
```
**Response:**
```json
{
"dot_ball_prob": 24.3,
"boundary_prob": 38.7,
"expected_runs": 2.41,
"run_distribution": [0.24, 0.22, 0.08, 0.06, 0.28, 0.12],
"win_probability": null,
"phase": "Middle Overs (Ov 7-15)",
"run_rate": 7.86
}
```
### `GET /api/meta`
Returns available teams and venues.
### `GET /api/health`
Returns loaded model names and status.
---
## IPL Teams Supported
Chennai Super Kings Β· Delhi Capitals Β· Gujarat Titans Β· Kolkata Knight Riders Β·
Lucknow Super Giants Β· Mumbai Indians Β· Punjab Kings Β· Rajasthan Royals Β·
Royal Challengers Bangalore Β· Sunrisers Hyderabad
## Venues Supported
Arun Jaitley Stadium Β· Brabourne Stadium Β· DY Patil Stadium Β· Eden Gardens Β·
Feroz Shah Kotla Β· MA Chidambaram Stadium Β· MCA Stadium Β·
Maharashtra Cricket Association Stadium Β· Narendra Modi Stadium Β·
Punjab Cricket Association Stadium Β· Rajiv Gandhi International Stadium Β·
Sawai Mansingh Stadium Β· Wankhede Stadium