0% found this document useful (0 votes)
240 views12 pages

Player Statistics Probability Analysis

Uploaded by

Madeeha
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
240 views12 pages

Player Statistics Probability Analysis

Uploaded by

Madeeha
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

#1. From the given dataset players_info.

csv ,
#a) What is the probability distribution of genders among the players?
#b) What is the probability of each batting style?
#c) What is the probability of each bowling style?
#d) What is the probability distribution of player positions?
#e) What is the probability distribution of countries among the
players?

#A probability distribution is a function that provides the


#probabilities of occurrence of different possible outcomes in an
experiment.

"""Sample Dataset – players_info.csv """


"""| Player\_ID | Name | Gender | Batting\_Style | Bowling\
_Style | Player\_Position | Country |
| ---------- | --------------- | ------ | -------------- |
------------------ | ---------------- | ----------- |
| 1 | Virat Kohli | Male | Right-hand bat | Right-arm
medium | Batsman | India |
| 2 | David Warner | Male | Left-hand bat | Right-arm
leg spin | Batsman | Australia |
| 3 | Ben Stokes | Male | Left-hand bat | Right-arm
fast | All-rounder | England |
| 4 | Rashid Khan | Male | Right-hand bat | Right-arm
leg spin | Bowler | Afghanistan |
| 5 | Smriti Mandhana | Female | Left-hand bat | Right-arm
off spin | Batsman | India |
| 6 | Ellyse Perry | Female | Right-hand bat | Right-arm
fast | All-rounder | Australia |
| 7 | Kane Williamson | Male | Right-hand bat | Right-arm
off spin | Batsman | New Zealand |
| 8 | Jasprit Bumrah | Male | Right-hand bat | Right-arm
fast | Bowler | India |
| 9 | Joe Root | Male | Right-hand bat | Right-arm
off spin | Batsman | England |
| 10 | Mithali Raj | Female | Right-hand bat | Right-arm
leg spin | Batsman | India |
"""
import pandas as pd

# Load dataset
df = pd.read_csv("players_data_with_all_info.csv")

# a) Probability distribution of genders


gender_prob = df['gender'].value_counts(normalize=True)

# b) Probability of each batting style


batting_prob = df['battingstyle'].value_counts(normalize=True)

# c) Probability of each bowling style


bowling_prob = df['bowlingstyle'].value_counts(normalize=True)

# d) Probability distribution of player positions


position_prob = df['position'].value_counts(normalize=True)

# e) Probability distribution of countries


country_prob = df['country_id'].value_counts(normalize=True)

# Display results
print("a) Gender Probability Distribution:\n", gender_prob, "\n")
print("b) Batting Style Probability Distribution:\n", batting_prob, "\
n")
print("c) Bowling Style Probability Distribution:\n", bowling_prob, "\
n")
print("d) Player Position Probability Distribution:\n", position_prob,
"\n")
print("e) Country Probability Distribution:\n", country_prob, "\n")

a) Gender Probability Distribution:


gender
m 0.936439
f 0.063561
Name: proportion, dtype: float64

b) Batting Style Probability Distribution:


battingstyle
right-hand-bat 0.824804
left-hand-bat 0.175196
Name: proportion, dtype: float64

c) Bowling Style Probability Distribution:


bowlingstyle
right-arm-fast-medium 0.496385
right-arm-offbreak 0.158189
right-arm-fast 0.109984
slow-left-arm-orthodox 0.090448
left-arm-fast-medium 0.058988
legbreak 0.043892
legbreak-googly 0.025498
left-arm-fast 0.013574
slow-right-arm-orthodox 0.002791
left-arm-chinaman 0.000254
Name: proportion, dtype: float64

d) Player Position Probability Distribution:


position
Bowler 0.328502
Batsman 0.282715
Allrounder 0.280529
Wicketkeeper 0.097325
Middle Order Batter 0.003106
Bowling Allrounder 0.002819
Top Order Batter 0.002819
Batting Allrounder 0.002186
Name: proportion, dtype: float64

e) Country Probability Distribution:


country_id
153732 0.182859
11 0.059822
462 0.055508
251 0.053840
52126 0.046477
...
2 0.000058
26833 0.000058
213370 0.000058
20802 0.000058
867648 0.000058
Name: proportion, Length: 90, dtype: float64

#2. 80% of all the visitors to Museum of Goa end up buying souvenirs
from the souvenir shop at the museum.
#On the coming Sunday, if a random sample of 10 visitors is picked,
Find the Probability that every visitor will end up
#buying from the souvenir shop. Find the Probability that a maximum of
7 visitors will buy souvenirs from the souvenir shop.

from math import comb

# Parameters
n = int(input("Enter the number of visitors (n): "))
p = 0.8 # probability of buying souvenir

# 1. Probability all 10 visitors buy souvenirs (X = 10)


P_all_buy = (p**n)

# 2. Probability at most 7 visitors buy souvenirs (X <= 7)


P_at_most_7 = sum(comb(n, k) * (p**k) * ((1-p)**(n-k)) for k in
range(0, 8))

# Output results
print("Probability all 10 visitors buy souvenirs: ", P_all_buy)
print("Probability at most 7 visitors buy souvenirs: ", P_at_most_7)

Enter the number of visitors (n): 10


Probability all 10 visitors buy souvenirs: 0.10737418240000006
Probability at most 7 visitors buy souvenirs: 0.32220047359999987
#3. A testing agency wants to analyze the complexity of SAT exam 2022.

#They have collected the SAT scores of 1000 students in


“sat_score.csv”.
#Calculate the probability that a student will score less than 800 in
SAT exam.
#Calculate the probability that a student will score more than 1300 in
SAT exam.

"""Sample Dataset – sat_score.csv

| Student\_ID | SAT\_Score |
| ----------- | ---------- |
| 1 | 750 |
| 2 | 620 |
| 3 | 810 |
| 4 | 940 |
| 5 | 1150 |
| 6 | 1320 |
| 7 | 720 |
| 8 | 1400 |
| 9 | 860 |
| 10 | 1250 |
"""
import pandas as pd

# Load the dataset


data = pd.read_csv("[Link]")

# Total number of students


total_students = len(data)

# 1. Probability student scores less than 800


count_less_800 = len(data[data['Score'] < 800])
prob_less_800 = count_less_800 / total_students

# 2. Probability student scores more than 1300


count_more_1300 = len(data[data['Score'] > 1300])
prob_more_1300 = count_more_1300 / total_students

# Print results
print("Probability that a student scores less than 800: ",
prob_less_800)
print("Probability that a student scores more than 1300: ",
prob_more_1300)

Probability that a student scores less than 800: 0.983739837398374


Probability that a student scores more than 1300:
0.016260162601626018
#4. A Marketing services company reported that the typical American
spends a mean of 144 minutes (2.4 hours) per day
#accessing the Internet via a mobile device. Select a sample of 30
friends and family members whose mobile access time
#is stored in a CSV file “[Link]”. Is there evidence
that the population mean time spent per day accessing
#the Internet via mobile device is different from 144 minutes? (Level
of Significance α = 0.05)

""" Sample Dataset – [Link]

| Person\_ID | Mobile\_Time\_Minutes |
| ---------- | --------------------- |
| 1 | 120 |
| 2 | 135 |
| 3 | 150 |
| 4 | 160 |
| 5 | 155 |
| 6 | 140 |
| 7 | 170 |
| 8 | 130 |
| 9 | 145 |
| 10 | 152 |
"""

import pandas as pd
from scipy import stats

# Step 1: Load the dataset


data = pd.read_csv("[Link]") # The file should have one column
with times
print("First 5 rows:\n", [Link]())

# Step 2: Extract the column (assuming the column is named 'Time')


sample = data['Time']

# Step 3: Population mean given


mu = 144

# Step 4: Perform one-sample t-test


t_stat, p_value = stats.ttest_1samp(sample, mu)

print("\nOne-sample t-test results:")


print("t-statistic =", t_stat)
print("p-value =", p_value)

# Step 5: Conclusion
alpha = 0.05
if p_value < alpha:
print("Reject H₀: Evidence suggests mean is different from 144
minutes.")
else:
print("Fail to Reject H₀: No evidence that mean is different from
144 minutes.")

First 5 rows:
Time
0 130
1 160
2 150
3 140
4 155

One-sample t-test results:


t-statistic = 7.894940950405078
p-value = 7.346709789786038e-08
Reject H₀: Evidence suggests mean is different from 144 minutes.

"""5. A hotel manager looks to enhance the initial expression that


hotel guests have when they check in.
Contributing to initial impressions is the time it takes to deliver a
guest‟s luggage to the room after check_in.
A random sample of 20 deliveries on a particular day is selected in
Wing A of the hotel and a random sample of 20
deliveries is selected in Wing B. The results are stored in
“[Link]”. Analyze the data and determine
whether there is a difference between the mean delivery time in the 2
wings of the hotel.(Use α = 0.05)"""

"""Sample Dataset – [Link] (10 rows for simplicity)

| Delivery\_ID | Wing | Delivery\_Time\_Minutes |


| ------------ | ---- | ----------------------- |
| 1 | A | 12 |
| 2 | A | 15 |
| 3 | A | 14 |
| 4 | A | 11 |
| 5 | A | 13 |
| 6 | B | 18 |
| 7 | B | 20 |
| 8 | B | 22 |
| 9 | B | 19 |
| 10 | B | 21 |
"""

import pandas as pd
from [Link] import ttest_ind

# Load dataset
df = pd.read_csv("[Link]")
# Split data by Wing
wing_a = df[df["Wing"] == "A"]["Delivery_Time_Minutes"]
wing_b = df[df["Wing"] == "B"]["Delivery_Time_Minutes"]

# Perform independent two-sample t-test (equal variances assumed)


t_stat, p_value = ttest_ind(wing_a, wing_b, equal_var=True)

print("Mean Wing A:", wing_a.mean())


print("Mean Wing B:", wing_b.mean())
print("t-statistic:", t_stat)
print("p-value:", p_value)

# Decision
alpha = 0.05
if p_value < alpha:
print("Reject H0 → Significant difference between Wing A and Wing
B")
else:
print("Fail to reject H0 → No significant difference")

Mean Wing A: 12.836


Mean Wing B: 19.177333333333337
t-statistic: -24.483845664564893
p-value: 2.5730344759857236e-73
Reject H0 → Significant difference between Wing A and Wing B

"""6. The file “[Link]” contains the compressive strength in


thousands of pounds/square inch,
of 40 samples of concrete taken 2 and 7 days after pouring. At the
0.01 level of significance,
is there evidence that the mean strength is lower at 2 days than at 7
days?

Sample Dataset – [Link]


| Sample\_ID | Strength\_2days | Strength\_7days |
| ---------- | --------------- | --------------- |
| 1 | 2.9 | 4.4 |
| 2 | 2.7 | 4.6 |
| 3 | 2.8 | 4.5 |
| 4 | 3.0 | 4.8 |
| 5 | 2.6 | 4.2 |
| 6 | 2.9 | 4.7 |
| 7 | 2.8 | 4.5 |
| 8 | 3.0 | 4.9 |
| 9 | 2.7 | 4.3 |
| 10 | 2.9 | 4.6 |

"""

import pandas as pd
from [Link] import ttest_rel

# Load dataset
df = pd.read_csv("[Link]")

# Paired t-test
t_stat, p_value = ttest_rel(df["Strength_2days"],
df["Strength_7days"])

print("Mean strength at 2 days:", df["Strength_2days"].mean())


print("Mean strength at 7 days:", df["Strength_7days"].mean())
print("t-statistic:", t_stat)

# Since alternative hypothesis is μ2 < μ7, use one-tailed test


p_value_one_tailed = p_value / 2 if t_stat < 0 else 1 - (p_value / 2)
print("One-tailed p-value:", p_value_one_tailed)

# Decision at alpha = 0.01


alpha = 0.01
if p_value_one_tailed < alpha:
print("Reject H0 → Evidence that 2-day strength is lower than 7-
day strength")
else:
print("Fail to reject H0 → No sufficient evidence")

Mean strength at 2 days: 2.76


Mean strength at 7 days: 4.4925
t-statistic: -29.81418655119663
One-tailed p-value: 9.355609619419344e-29
Reject H0 → Evidence that 2-day strength is lower than 7-day strength

"""7. Two companies A and B were merged. After the first appraisal
cycle post merger, employees originally belonging to company B have
put an allegation that the management favours employees

who were originally a part of company A. At 95%confidence perform a


hypothesis test to validate if the claim holds good. Promotion Status
Company P NP Total
A 15 9 24
B 16 15 31
Total 31 24 55

"""

import pandas as pd
from [Link] import chi2_contingency

# Create the contingency table


data = {'P': [15, 16],
'NP': [9, 15]}
companies = ['A', 'B']
df = [Link](data, index=companies)

print("Contingency Table:\n", df)

# Perform Chi-square test of independence


chi2, p, dof, expected = chi2_contingency(df)

print("\nChi-square statistic:", chi2)


print("p-value:", p)
print("Degrees of freedom:", dof)
print("Expected frequencies:\n", expected)

# Decision at alpha = 0.05


alpha = 0.05
if p < alpha:
print("\nReject H0 → Promotion status depends on company
(favoritism possible)")
else:
print("\nFail to reject H0 → No evidence of favoritism based on
company")

Contingency Table:
P NP
A 15 9
B 20 15

Chi-square statistic: 0.020088931405895745


p-value: 0.8872889903297565
Degrees of freedom: 1
Expected frequencies:
[[14.23728814 9.76271186]
[20.76271186 14.23728814]]

Fail to reject H0 → No evidence of favoritism based on company

"""8. Traffic management inspector in a city wants to understand


whether carbon emissions from different cars are different.
For this reason, the inspector has taken random samples from all
registered cars on the road in that city and would like
to test if the amount of carbon emission release depends on fuel type
at 5% significance level. Dataset – [Link]

Sample Dataset – [Link]


| Car\_ID | Fuel\_Type | Carbon\_Emission\_gkm |
| ------- | ---------- | --------------------- |
| 1 | Petrol | 120 |
| 2 | Diesel | 140 |
| 3 | Petrol | 125 |
| 4 | Diesel | 135 |
| 5 | Electric | 0 |
| 6 | Petrol | 130 |
| 7 | Diesel | 145 |
| 8 | Electric | 0 |
| 9 | Petrol | 128 |
| 10 | Diesel | 138 |

"""

import pandas as pd
from [Link] import f_oneway

# Load dataset
df = pd.read_csv("[Link]")

# Split data by fuel type


petrol = df[df["Fuel_Type"] == "Petrol"]["Carbon_Emission_gkm"]
diesel = df[df["Fuel_Type"] == "Diesel"]["Carbon_Emission_gkm"]
electric = df[df["Fuel_Type"] == "Electric"]["Carbon_Emission_gkm"]

# Perform one-way ANOVA


f_stat, p_value = f_oneway(petrol, diesel, electric)

print("F-statistic:", f_stat)
print("p-value:", p_value)

# Decision at alpha = 0.05


alpha = 0.05
if p_value < alpha:
print("Reject H0 → Carbon emissions depend on fuel type")
else:
print("Fail to reject H0 → No significant difference in emissions
across fuel types")

F-statistic: 8445.003714893035
p-value: 0.0
Reject H0 → Carbon emissions depend on fuel type

#9. Find the relationship between the price of a laptop with other
factors of the dataset “[Link]”.

"""
sample dataset in rupees (laptops_inr.csv)
| Laptop\_ID | Brand | RAM\_GB | Storage\_GB | Processor | Price\_INR
|
| ---------- | ------ | ------- | ----------- | --------- | ----------
|
| 1 | Dell | 8 | 256 | i5 | 66400
|
| 2 | HP | 16 | 512 | i7 | 99600
|
| 3 | Lenovo | 8 | 512 | i5 | 74700
|
| 4 | Asus | 16 | 1024 | i7 | 116200
|
| 5 | Acer | 8 | 256 | i3 | 58100
|
| 6 | Apple | 16 | 512 | M1 | 124500
|
| 7 | Dell | 32 | 1024 | i9 | 166000
|
| 8 | HP | 8 | 512 | i5 | 70550
|
| 9 | Lenovo | 16 | 256 | i7 | 91300
|
| 10 | Asus | 8 | 256 | i5 | 62250
|

"""

import pandas as pd
from [Link] import OneHotEncoder
from sklearn.linear_model import LinearRegression

# Load dataset
df = pd.read_csv("laptops_inr.csv")

# One-hot encode categorical variables (Brand, Processor)


df_encoded = pd.get_dummies(df, columns=['Brand', 'Processor'],
drop_first=True)

# Define features and target


X = df_encoded.drop('Price_INR', axis=1)
y = df_encoded['Price_INR']

# Fit linear regression model


model = LinearRegression()
[Link](X, y)

# Print coefficients
coefficients = [Link]({
'Feature': [Link],
'Coefficient': model.coef_
})
print("Intercept:", model.intercept_)
print(coefficients)

# Predict prices (optional)


y_pred = [Link](X)
df['Predicted_Price_INR'] = y_pred.round(2)
print("\nDataset with Predicted Prices:\n", df)

Intercept: 99937.77898486686
Feature Coefficient
0 Laptop_ID 0.438433
1 RAM_GB 2505.572732
2 Storage_GB 39.725874
3 Brand_Apple 24923.837299
4 Brand_Asus -435.788345
5 Brand_Dell 5045.220123
6 Brand_HP 5048.270063
7 Brand_Lenovo 31.834067
8 Processor_i3 -85343.876374
9 Processor_i5 -65074.015314
10 Processor_i7 -45263.316635
11 Processor_i9 -10078.972019

Dataset with Predicted Prices:


Laptop_ID Brand RAM_GB Storage_GB Processor Price_INR \
0 1 Apple 4 256 i7 99006
1 2 HP 8 1024 i3 83263
2 3 Apple 4 1024 i9 162980
3 4 Dell 4 256 i5 61139
4 5 Acer 4 1024 i5 88585
.. ... ... ... ... ... ...
495 496 HP 4 1024 i3 71532
496 497 Lenovo 8 512 M1 143003
497 498 Lenovo 4 1024 i7 105730
498 499 Acer 8 256 i5 65917
499 500 HP 32 1024 M1 225780

Predicted_Price_INR
0 99790.85
1 80366.93
2 165485.55
3 60102.85
4 85567.54
.. ...
495 70561.22
496 140571.74
497 105626.22
498 65296.95
499 226062.89

[500 rows x 7 columns]

Common questions

Powered by AI

The Chi-square test assesses whether there is a significant difference in promotion status favoring employees from Company A. The null hypothesis assumes independence between company origin and promotion status. If the p-value from the test is less than the 0.05 significance level, we reject the null hypothesis, indicating bias. The test helps validate or refute the allegation by Company B employees .

If statistical evidence rejects the null hypothesis indicating that usage time is different from 144 minutes, marketers might adjust strategies to align with current patterns. For example, if usage is longer, intervention timings during high traffic might be optimized, improving engagement and conversion .

The probability that all 10 visitors will purchase souvenirs is 0.1073741824. This relatively low probability suggests a high variability in purchasing behavior among visitors. It implies strategies could be employed by the museum to enhance purchase rates, such as marketing or product positioning .

The probabilities of different bowling styles indicate a diverse usage, with 'right-arm-fast-medium' being the most common at 0.496385, followed by 'right-arm-offbreak' at 0.158189. The probabilities suggest a preference for these styles among players, reflecting perhaps their effectiveness or the players' comfort with these techniques .

If the p-value is less than the significance level, we reject the null hypothesis, suggesting the actual mean access time deviates significantly from 144 minutes. This result may indicate changing usage patterns, necessitating further investigation into factors influencing mobile internet use .

The likelihood that a student scores less than 800 in the SAT exam is very high, at 0.98374. This implies that a vast majority of students score below this threshold, potentially highlighting a need to explore causes such as educational strategies, preparedness, or test difficulty .

The batting style probability distribution (right-hand-bat at 0.824804 and left-hand-bat at 0.175196) implies a greater prevalence of right-hand batters. Teams may consider this when strategizing against opponents, leveraging diversity in batting styles for tactical advantage .

The gender distribution shows that a significant majority of players are male, with a probability of 0.936439, while females account for only 0.063561 of the total distribution .

The mean compressive strength is lower at 2 days than at 7 days. The paired t-test performed shows a significant difference with a t-statistic of -29.814 and a p-value much less than the 0.01 significance level, leading to the rejection of the null hypothesis. This strongly suggests that 2-day compressive strength is significantly lower than 7-day strength .

The analysis reveals a significant difference in delivery times between Wings A and B. With a t-statistic of -24.48 and a p-value far below 0.05, the null hypothesis is rejected, concluding that Wing B's delivery times are significantly longer than Wing A's, informing operational improvements .

You might also like