Unveiling IPL 2023 Player's Rating

Unveiling IPL 2023 Player's Rating

Analyzing Performance Metrics and Impact

In our previous article, we delved into the world of web scraping and successfully gathered valuable data on IPL 2023 players. Now, it's time to take our analysis to the next level and unveil the player ratings, a comprehensive evaluation of their performance and impact during this exciting season. In this follow-on article, we will explore the methodology behind calculating player ratings, examine key performance metrics, and uncover the top-performing players who made a significant difference in IPL 2023.

Before we proceed, let's briefly recap the process of web scraping IPL 2023 player data. By collecting detailed statistics on batting averages, bowling strike rates, fielding contributions, and more, we obtained a vast dataset for analysis. Now, we leverage this dataset to derive meaningful insights and assign player ratings that encapsulate their overall performance.

Understanding the Player Rating System:

The player rating system aims to assign a numeric value to each player, reflecting their impact on the game. It considers various factors that contribute to a player's success, such as runs scored, wickets taken, and consistency in performance. Each parameter is assigned a specific weight, and the total rating is computed by combining the weighted scores.

Building the Player Rating System:

To develop our player rating system, we will use Python as our programming language of choice. Python offers powerful libraries like NumPy and Pandas that enable us to handle data efficiently. We will also use the dataset we scrapped last time.

Step 1: Defining Weightings

The first step is to define weightings for each parameter. Weightings determine the relative importance of different statistics in the final player rating. For instance, if we believe that runs and batting average have a higher impact on a player's performance, we can assign them higher weights.

# Define weightings for each parameter
matches_weight = 0.2
runs_weight = 0.3
batting_avg_weight = 0.15
wickets_weight = 0.2
bowling_avg_weight = 0.15

Step 2: Implementing the Rating Calculation Function

Next, we create a function to calculate the player rating. The function takes the player statistics (matches, runs, batting average, wickets, and bowling average) as input and returns the player rating based on the provided weightings.

# Function to calculate player rating
def calculate_player_rating(matches, runs, batting_avg, wickets, bowling_avg):
    rating = (matches * matches_weight +
              runs * runs_weight +
              batting_avg * batting_avg_weight +
              wickets * wickets_weight +
              bowling_avg * bowling_avg_weight)
    return rating

The calculate_player_rating function takes in the parameters (matches, runs, batting_avg, wickets, bowling_avg) for each player and returns a rating based on the provided weightings. The weightings determine the relative importance of each parameter in calculating the overall rating.

Step 3: Gathering Player Data and Cleaning

We have already scraped the data from howstat.com. The dataset is available on both GitHub and Kaggle.

df = pd.read_csv("ipl-2023.csv")

df.replace(np.nan, 0, inplace=True)
del df['Unnamed: 0']

df = df.astype({"Matches":'float', "Runs":'float', "Batting Average":'float', "Wicket":'float', "Bowling Average":'float'}) 
df.info()

Step 4: Calculating Player Ratings

With the player statistics and weightings in place, we pass the data to our rating calculation function for each player. The function will compute the individual player ratings, providing us with a quantitative measure of their contributions.

# Iterate through each row and calculate player rating
ratings = []
for index, row in df.iterrows():
    rating = calculate_player_rating(row['Matches'], row['Runs'], row['Batting Average'], row['Wicket'], row['Bowling Average'])
    ratings.append(rating)

# Insert the "Rating" column into the DataFrame
df['Rating'] = ratings
df = df.astype({"Rating":'float'})
df.head()

The code iterates through each row in the DataFrame df and calculates the player rating using the calculate_player_rating() function. The calculate_player_rating() function takes the values of 'Matches', 'Runs', 'Batting Average', 'Wicket', and 'Bowling Average' from each row and computes the player rating based on the defined weightings.

After calculating the player ratings, a new column named "Rating" is added to the DataFrame df. This column contains the calculated ratings for each player. The code also ensures that the "Rating" column is of type 'float'.

Step 5: Normalize the Ratings:

# Finding the minimum and maximum rated player
maxi = max(df['Rating'])
mini = min(df['Rating'])
print(mini, maxi)

# Normalising the Rating
n_rating = []
for index, row in df.iterrows():
    normalised_rating = ((row['Rating'] - mini)) / ((maxi - mini)) * 100
    n_rating.append(round(normalised_rating, 2))
df['Normalised Rating'] = n_rating
df.head()
  • The code then finds the player with the minimum and maximum ratings from the "Rating" column using the min() and max() functions, respectively.

  • Normalize the Ratings: Next, the code normalizes the ratings to a 0-100 scale. It iterates through each row of the DataFrame df and calculates the normalized rating for each player. The normalized rating is computed using the formula: (rating - minimum rating) / (maximum rating - minimum rating) * 100. This transformation scales the ratings between 0 and 100, making them more interpretable and comparable.

  • Add the Normalized Rating Column: A new column named "Normalized Rating" is added to the DataFrame df, containing the normalized ratings for each player.

Step 6: Sort the DataFrame by Normalized Rating:

The DataFrame df is sorted in descending order based on the "Normalized Rating" column, using the sort_values() function with the ascending=False parameter. This step arranges the players from highest to lowest normalized rating, allowing us to identify the top-performing players of the season easily.

df_2 = df.sort_values(['Normalised Rating'], ascending=False)
df_2.head()

The complete code is available on my GitHub and the dataset file is available on my Kaggle.

Through this article, we have showcased a simple player rating system. However, the beauty of Python lies in its versatility, allowing us to extend this system with more sophisticated metrics or incorporate historical data for time-series analysis. With continuous refinement and incorporation of real-world data, the player rating system can become an indispensable resource for cricket fans and team strategists alike.

As we conclude our analysis of IPL 2023 player ratings, we realize that behind every figure and statistic lies a story of hard work, dedication, and moments of brilliance. The ratings are a testament to the exceptional skills and dedication of these cricketers who provided us with an unforgettable season of cricket. As fans, let's celebrate the players' achievements and look forward to even more excitement in the upcoming editions of the Indian Premier League.