A production-ready machine learning application that predicts IPL (Indian Premier League) match outcomes using a Flask backend, Scikit-Learn ML models, and React frontend.
- Overview
- Features
- Architecture
- Dataset
- ML Pipeline
- Installation
- Usage
- API Documentation
- Project Structure
- Future Improvements
This application analyzes ball-by-ball IPL cricket data to predict match outcomes. It features:
- Backend: Flask REST API with ML inference
- ML Model: Random Forest Classifier with preprocessing pipeline
- Frontend: React application with modern UI
- Model Persistence: Pickle/Joblib for model serialization
The system converts ball-by-ball data into match-level features and uses ensemble learning to predict whether the batting team will win or lose.
- β Complete feature engineering pipeline
- β Production-ready ML model training
- β RESTful API for predictions
- β Interactive React frontend
- β Real-time prediction with confidence scores
- β Input validation and error handling
- β Auto-calculated run rates
- β Responsive design
βββββββββββββββ HTTP POST ββββββββββββββββ
β React β ββββββββββββββββββ> β Flask API β
β Frontend β <ββββββββββββββββββ β (Python) β
βββββββββββββββ JSON ββββββββββββββββ
β
β load_model()
βΌ
ββββββββββββββββββββ
β Scikit-Learn β
β RandomForest β
β Pipeline β
ββββββββββββββββββββ
The project uses IPL ball-by-ball CSV data with the following key columns:
match_id- Unique identifier for each matchinnings- Innings number (1 or 2)batting_team- Team battingbowling_team- Team bowlingruns_off_bat- Runs scored off the batextras- Extra runs (wides, no-balls, etc.)is_wicket- Whether a wicket fellvenue- Match venuecity- City where match was playedseason- IPL season yearwinner- Winning team
Script: backend/preprocessing/feature_engineering.py
Converts ball-by-ball data to match-level aggregated features:
Aggregated Features:
total_runs= runs_off_bat + extrastotal_wickets= sum of wicketsballs_faced= count of ballsovers_played= balls_faced / 6run_rate= total_runs / overs_playedextras_total= sum of extras
Context Features:
- Team names (batting_team, bowling_team)
- Venue and city
- Season
- Innings number
Target:
target= 1 if batting_team won, else 0
Script: backend/model/train.py
Preprocessing Pipeline:
ColumnTransformer([
('cat', OneHotEncoder, ['batting_team', 'bowling_team', 'venue', 'city']),
('num', StandardScaler, ['total_runs', 'total_wickets', 'run_rate',
'extras_total', 'overs_played'])
])Model: RandomForestClassifier
- n_estimators: 300
- max_depth: 20
- min_samples_split: 10
- min_samples_leaf: 5
- random_state: 42
Training/Test Split: 80/20 with stratification
Evaluation Metrics:
- Accuracy
- Precision
- Recall
- Confusion Matrix
Script: backend/model/predict.py
- Loads trained model from
model.pkl - Accepts JSON input
- Returns prediction with probabilities
- Python 3.8+
- Node.js 16+
- npm or yarn
- Navigate to backend directory:
cd backend- Create virtual environment (recommended):
python -m venv venv
.\venv\Scripts\Activate- Install Python dependencies:
pip install flask flask-cors scikit-learn pandas numpy joblib- Train the model (first time only):
cd model
python train.pyThis will:
- Load and process
Data/Raw/IPL.csv - Train the RandomForest model
- Save
model.pklandmodel_features.pkl - Display performance metrics
- Start Flask server:
cd ..
python app.pyServer will run on http://localhost:5000
- Navigate to frontend directory:
cd frontend- Install npm dependencies:
npm installThis will install:
- React
- Axios (for API calls)
- Vite (dev server)
- ESLint
- Start development server:
npm run devFrontend will run on http://localhost:5173
cd backend/model
python train.pyOutput:
- Feature engineering progress
- Training metrics
- Model saved to
model.pkl
cd backend
python app.pyEndpoints:
GET /- API infoGET /api/health- Health checkPOST /api/predict- Make prediction
cd frontend
npm run devFeatures:
- Input form with dropdowns for teams, venues, cities
- Numeric inputs for match statistics
- Auto-calculated run rate
- Real-time validation
- Prediction results with confidence scores
- Open
http://localhost:5173in browser - Fill in match details:
- Batting Team
- Bowling Team
- Venue
- City
- Total Runs
- Total Wickets
- Overs Played
- Extras
- Click "Predict Match Outcome"
- View results with win/loss probabilities
Request:
{
"batting_team": "Mumbai Indians",
"bowling_team": "Chennai Super Kings",
"venue": "Wankhede Stadium",
"city": "Mumbai",
"total_runs": 180,
"total_wickets": 5,
"overs_played": 20.0,
"extras_total": 12,
"run_rate": 9.0
}Response (Success):
{
"status": "success",
"prediction": "Batting Team Wins",
"win_probability": 0.82,
"loss_probability": 0.18,
"confidence": 82.0,
"input_data": { ... }
}Response (Error):
{
"status": "error",
"message": "Missing required fields: venue",
"required_fields": [ ... ]
}Validation Rules:
- All fields required
- Numeric fields must be β₯ 0
overs_playedmust be between 0.1 and 20total_wicketsmust be between 0 and 10batting_teamβbowling_team
IPL_Predictor/
β
βββ backend/
β βββ app.py # Flask API server
β β
β βββ preprocessing/
β β βββ feature_engineering.py # Data preprocessing
β β
β βββ model/
β β βββ train.py # Model training script
β β βββ predict.py # Prediction utility
β β βββ model.pkl # Trained model (generated)
β β βββ model_features.pkl # Feature metadata (generated)
β β
β βββ Data/
β βββ Raw/
β β βββ IPL.csv # Original dataset
β βββ Cleaned/
β βββ IPL_features.csv # Processed features (generated)
β
βββ frontend/
β βββ src/
β β βββ App.jsx # Main React component
β β βββ App.css # App styles
β β β
β β βββ components/
β β β βββ PredictionForm.jsx # Prediction form component
β β β βββ PredictionForm.css # Form styles
β β β
β β βββ api/
β β βββ predict.js # API utility functions
β β
β βββ package.json # npm dependencies
β βββ vite.config.js # Vite configuration
β
βββ requirements.txt # Python dependencies
βββ README.md # This file
flask>=2.3.0
flask-cors>=4.0.0
scikit-learn>=1.3.0
pandas>=2.0.0
numpy>=1.24.0
joblib>=1.3.0
{
"dependencies": {
"react": "^19.2.0",
"react-dom": "^19.2.0",
"axios": "^1.6.0"
}
}- Dropdowns: Pre-populated with IPL teams, venues, and cities
- Auto-calculation: Run rate calculated automatically
- Validation: Real-time form validation with error messages
- Responsive: Mobile-friendly design
- Animations: Smooth transitions and loading states
- Error Handling: User-friendly error messages
curl -X POST http://localhost:5000/api/predict `
-H "Content-Type: application/json" `
-d '{
"batting_team": "Mumbai Indians",
"bowling_team": "Chennai Super Kings",
"venue": "Wankhede Stadium",
"city": "Mumbai",
"total_runs": 180,
"total_wickets": 5,
"overs_played": 20.0,
"extras_total": 12,
"run_rate": 9.0
}'import requests
url = "http://localhost:5000/api/predict"
data = {
"batting_team": "Mumbai Indians",
"bowling_team": "Chennai Super Kings",
"venue": "Wankhede Stadium",
"city": "Mumbai",
"total_runs": 180,
"total_wickets": 5,
"overs_played": 20.0,
"extras_total": 12,
"run_rate": 9.0
}
response = requests.post(url, json=data)
print(response.json())- Add XGBoost/LightGBM models
- Hyperparameter tuning with GridSearchCV
- Feature importance analysis
- Player-level statistics
- Weather data integration
- Head-to-head team statistics
- User authentication
- Prediction history
- Model performance dashboard
- Real-time match updates
- Mobile app version
- Batch prediction upload
- Docker containerization
- CI/CD pipeline
- API rate limiting
- Caching layer (Redis)
- Database integration (PostgreSQL)
- Logging and monitoring
- Unit and integration tests
- API documentation (Swagger)
- Live data scraping
- Data augmentation
- Feature engineering automation
- Time-series analysis
- Player form tracking
Contributions are welcome! Please feel free to submit a Pull Request.
This project is open source and available under the MIT License.
IPL Match Predictor Team
- IPL data source
- Scikit-Learn documentation
- Flask documentation
- React documentation
Built with β€οΈ using Flask, Scikit-Learn, and React