This is a capstone level classification ML project for predicting IPL team finishing position for an year based on Individual player's performance. The project includes web-scraping ESPN cricinfo website for ipl player statistics, pre-processing the data, and comparing different classification models and hyperparameter tuning them.
CLASSIFICATION MODELS BEING COMPARED
* Models to be created include KNN, Logistic Regression, Decision Tree , Random Forest, SVM, Naive Bayes
- Identifying a domain with a problem which can be addressed using Prediction Techniques.
- Creating a Dataset for classification with minimum 20 Features and 100 rows. The Data is scrapped from espn cricinfo's website.
- Ensure the dataset has all possible combination of feature where data preprocessing techniques can be applied ( Data Cleaning, Dimensionality Reduction, Data Transformation, Feature Engineering).
- Applying all the categories of classification algorithm( KNN, Logistic Regression, Decision Tree, Random Forest, SVM, Naïve Bayes) along with hyper parameter tuning and measure through best suited evaluation metric.
- Using the ROC curve to determine the best algorithm for your dataset.
The repository structure is highlighted below:
- The Webscrapping Espncricinfo IPL Stats folder, has
scrape_espn_cricinfo.py
, which consists of all the functions and thedriver_code_webscrape_ipl_dataset.ipynb
that has the driver code for creating the player statistics dataset, through webscrapping the ESPN cricinfo website. - The Extra Unused IPL Data folder has the salaries of each of the IPL players listed down from 2009 to 2023, this data was discarded from being used in the model, at early stages.
- The Final Model Building folder has the
classification_models_building.ipynb
which has all the classification models running on the pre-processed (PCA) dataset. - The Data Preprocessing has the
classification_models_building.ipynb
notebook which has an extensive cleaning, pre-processing, feature engineering and dimiensionality handing within it for the Espn IPL dataset.
Directory Tree Structure
|____Webscrapping Espncricinfo IPL Stats
| |____driver_code_webscrape_ipl_dataset.ipynb
| |____scrape_espn_cricinfo.py
| |____batting_scrape_sample.png
| |____team_timelines.png
| |____uncleaned_dataset.csv
| |____bowling_scrape_sample.png
| |____Finishing_Position_IPL.csv
| |____README.md
|____Extra Unused IPL Data
| |____IPL Salaries
| | |____2009_IPL_Salary..csv
| | |____2010_IPL_Salary..csv
| | |____2017_IPL_Salary.csv.csv
| | |____2019_IPL_Salary.csv.csv
| | |____2016_IPL_Salary.csv
| | |____2015_IPL_Salary.csv
| | |____2021_IPL_Salary.csv.csv
| | |____2008_IPL_Salary.csv
| | |____2011_IPL_Salary..csv
| | |____2014_IPL_Salary..csv
| | |____2020_IPL_Salary.csv.csv
| | |____2013_IPL_Salary..csv
| | |____2018_IPL_Salary.csv.csv
| | |____2012_IPL_Salary..csv
| | |____2023_IPL_Salary.csv
|____Final Model Building
| |____classification_models_building.ipynb
|____Data Preprocessing
| |____data_preprocessing_notebook.ipynb
| |____pre_processed_dataset.csv
|____requirements.txt
URL Adjustments being made for Web-Scrapping (scrape_espn_cricinfo.py)
Year: 2008
Team: Royal Challengers Bangalore
- Batting: https://stats.espncricinfo.com/ci/engine/records/batting/most_runs_career.html?id=3519;team=4340;type=tournament
- Bowling:https://stats.espncricinfo.com/ci/engine/records/bowling/most_wickets_career.html?id=3519;team=4340;type=tournament
These following teams are either new entrants, defunct, or were suspended in between seasons, so upon trying to webscrape the following, we will be thrown an error or will receive an empty dataset.
- Decan Chargers
- Pune Warriors India
- Kochi Tuskers Kerala
- Gujarat Lions
- Rising Pune Supergiants
- Lucknow Super Giants
- Gujarat Titans
- Chennai Super Kings
- Rajasthan Royals
To handle this abnormality, we created nested dictionaries in the scrape_espn_cricinfo.py
webscrapping file that hold the team's id assigned in the ESPN Cricinfo database and the years they have participated in the IPL in. These years will then be iterated through to avoid discrepencies
Function to request to espncricinfo stats teamwise, yearwise page and scrape relevant information and add to a temporary dataset.
Screenshot of a sample page to be web-scrapped:
Year: 2008
Team: Royal Challengers Bangalore
https://stats.espncricinfo.com/ci/engine/records/batting/most_runs_career.html?id=3519;team=4340;type=tournament
Function to request to espncricinfo stats teamwise, yearwise page and scrape relevant information and add to a temporary dataset.
Screenshot of a sample page to be web-scrapped:
![batting_scrape_sample](https://private-user-images.githubusercontent.com/105413094/240251870-13ea6500-bd24-4ec1-884b-e0ae8f181739.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjM3ODM0MDYsIm5iZiI6MTcyMzc4MzEwNiwicGF0aCI6Ii8xMDU0MTMwOTQvMjQwMjUxODcwLTEzZWE2NTAwLWJkMjQtNGVjMS04ODRiLWUwYWU4ZjE4MTczOS5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwODE2JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDgxNlQwNDM4MjZaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT02YmE5ZDEzZGY4NjdlNGIzZTgyZTI2Y2I0ZGRhNjNhNGYxNzA3OTM0ZDBjOWQ5Nzg5ZTVmZGUxOGJlOWZlY2QxJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.uJ0TFbboMyvrabrSToswVmZz_gJgyDxIpRGVPHsxLq4)
Year: 2008
Team: Royal Challengers Bangalore
https://stats.espncricinfo.com/ci/engine/records/batting/most_runs_career.html?id=3519;team=4340;type=tournament
Function to iterate through all the teams and years, and create the batting dataset by calling the "scrape_batting_stats_espn()" function created earlier.
Function to request to espncricinfo stats teamwise, yearwise page and scrape relevant information and add to a temporary dataset.
Screenshot of a sample page to be web-scrapped:
![bowling_scrape_sample](https://private-user-images.githubusercontent.com/105413094/240252247-30357b24-9d1b-4b0c-aa11-a395a5f9f096.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjM3ODM0MDYsIm5iZiI6MTcyMzc4MzEwNiwicGF0aCI6Ii8xMDU0MTMwOTQvMjQwMjUyMjQ3LTMwMzU3YjI0LTlkMWItNGIwYy1hYTExLWEzOTVhNWY5ZjA5Ni5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwODE2JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDgxNlQwNDM4MjZaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1kMDQxZWIwODZmOTI1MGQwMTUyMTVkNjk0NDIwZmViNThkMDNiYTJlOTgxYTVkMzdhYmU0YjViZjE5NTFhYzBmJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.84EdwVuiORVmvNoss-cd3Njw74BKbTTok7YncYj5A_0)
Year: 2008
Team: Royal Challengers Bangalore
https://stats.espncricinfo.com/ci/engine/records/bowling/most_wickets_career.html?id=3519;team=4340;type=tournament
Function to iterate through all the teams and years, and create the batting dataset by calling the "scrape_bowling_stats_espn()" function created earlier.
Some of the techniques applied within data pre-processing are:
- Handling NA values: After analyzing the missing values for both batting and bowling columns, I have found that if a player has not batted or bowled in a particular season, all of their corresponding batting and bowling columns have missing values. Hence, it is reasonable to assume that these missing values are not actual values but rather an indication that the player did not bat or bowl in those matches. Therefore, I will fill all of these missing values with 0, which is a common practice in such cases, and an accurate depiction.
- Adding new columns
- Data Type Casting
- Ordinal Encoding
- Label Encoding
- Robust Scaling
- PCA (Principal Component Analysis)
Hypothesis: Winning or success rate in a team sport like cricket, football does not entirely depend on the individual performance of the player, rather a team wins or performs well when most of the players of that team plays exceptionally good.
The calssification models used (from sci-kit learn) in tandem for the project include:
- KNN (KNeighborsClassifier)
- Random Forest (RandomForestClassifier)
- Decision Tree (DecisionTreeClassifier)
- Logistic Regression (LogisticRegression)
- Naive Bayes (GaussianNB)
- SVM - Support Vector Machine (SVC)
GridSearch CV is used for extensive hyperparameter tuning.