File size: 4,844 Bytes
c5393ce
 
 
 
 
 
 
 
 
 
c8e1e67
 
 
 
 
 
 
 
 
 
 
 
a0d801e
c8e1e67
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a0d801e
 
c8e1e67
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c5393ce
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
---
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