Q1.
Write a program to compute summary statistics such as mean, median, mode of the
given different types of data.
Mean:
Code:
import numpy as np
speed=[30,35,45,43,40,45,55]
a=[Link](speed) print
("mean = "a)
Output:
Median:
Code:
import numpy as np speed=[30,35,45,43,40,45,55]
a=[Link](speed)
print("median = ",a)
Output:
Mode:
Code:
from scipy import stats
speed=[30,35,45,43,40,45,55]
a=[Link](speed) print("mode
= ",a)
1
Output:
2
Q2. Write a program to compute summary statistics such as standard deviation, and
variance of the given different types of data.
Variance:
Code:
import numpy as np
num=[1,2,3,45,5,6,66] a=[Link](num)
print("Variance = ",a)
Output:
Standard Deviation:
Code:
import numpy as np
num=[1,2,3,45,5,6,66] a=[Link](num)
print("Standard Deviation = ",a)
3
Q3. Write a python program to demonstrate Regression analysis with residual plots on a
given dataset.
Code:
import pandas as pd import
numpy as np import
[Link] as plt
import seaborn as sns
import [Link] as sm
data = pd.read_csv("[Link]")
[Link]()
Output:
Code:
4
from [Link] import ols
data = pd.read_csv('[Link]')
[Link](columns={'Brain Weight(grams)': 'Brain_Weight', 'Head Size(cm^3)': 'Head_Size'},
inplace=True)
linear_model = ols('Brain_Weight ~ Head_Size',
data=data).fit() print(linear_model.summary()) fig =
[Link](figsize=(14, 8))
fig = [Link].plot_regress_exog(linear_model, "Head_Size", fig=fig)
[Link]()
5
Output:
Q4. Write a python program to calculate the variance.
1. Using statistics variance
Code:
import statistics
a = [-0.372, 0.073, -0.441, -0.577, 0.463, 0.569, -0.559, 0.300, -0.903, 0.442]
var = [Link](a)
print("Variance = ",var)
Output:
6
2. Using
[Link]:
import numpy as np
a = [-0.372, 0.073, -0.441, -0.577, 0.463, 0.569, -0.559, 0.300, -0.903, 0.442]
var = [Link](a)
print("Variance = ",var)
Q5. Write a program to create normal curve using python.
Code:
7
Output:
import numpy as np import
[Link] as plt
from [Link] import norm
# Parameters for the normal distribution mean
= 0 # mean
std_dev = 1 # standard deviation
# Generate a range of x values
x = [Link](mean - 4*std_dev, mean + 4*std_dev, 1000)
# Calculate the normal distribution values (y values) y
= [Link](x, mean, std_dev)
# Create the plot [Link](figsize=(10,
5))
#[Link](x, y, label='Normal Distribution', color='Black')
[Link](x, y, label=f'Normal Distribution\nMean = {mean}, Std Dev = {std_dev}', color='Red')
plt.fill_between(x, y, alpha=0.3, color='Red') [Link]('Normal Distribution Curve')
[Link]('X Value')
[Link]('Probability Density Function')
[Link](mean, color='Blue', linestyle='--', linewidth=2, label='Mean')
[Link]() [Link]()
[Link]()
8
Q6. Write a python program for correlation with scatter plot.
Code:
import [Link] as plt
import numpy as np
# Generate sample data [Link](0)
# For reproducibility
x = [Link](100) * 100 # 100 random values scaled to 0-100
y = x * 0.5 + [Link](0, 10, 100) # Linear relationship with some noise
# Calculate the correlation coefficient correlation_coefficient
= [Link](x, y)[0, 1]
# Print the correlation coefficient
print(f"Correlation coefficient: {correlation_coefficient:.2f}")
9
Output:
# Plot the data points [Link](x, y,
label='Data') [Link]('Scatter Plot
with Correlation')
# Fit a line to the data m,
b = [Link](x, y, 1)
[Link](x, m*x + b, color='red', label='Line of Best Fit')
[Link]('X values') [Link]('Y values')
[Link]() [Link]()
[Link]()
10
Output:
Q7. Write a python program to read total profit of all months and show it using a line plot.
Code:
import [Link] as plt import
numpy as np
#Create Dataset
month_number=[1,2,3,4,5,6,7,8,9,10,11,12] facecream =
[2500,2630,2140,3400,3600,2760,2980,3700,3540,1990,2340,2900] facewash =
[1500,1200,1340,1130,1740,1555,1120,1400,1780,1890,2100,1760]
toothpaste=[5200,5100,4550,5870,4560,4890,4780,5860,6100,8300,7300,7400]
bathingshop=[9200,6100,9550,8870,7760,7490,8980,9960,8100,10300,13300,14400]
shampoo=[1200,2100,3550,1870,1560,1890,1780,2860,2100,2300,2400,1800]
moisturizer=[1500,1200,1340,1130,1740,1555,1120,1400,1780,1890,2100,1760]
total_units=[21100,18330,22470,22270,20960,20140,29550,36140,23400,26670,41280,30020]
11
total_profit=[211000,183300,224700,222700,209600,201400,295500,361400,234000,266700,412800,30
0200]
[Link](month_number , total_profit , linestyle= '--' , color='red', linewidth = 3 , marker = 'o', mfc='k'
,label ="Profit data of last year",)
[Link]("Month Number") [Link]("Sold
units nuber")
[Link]("Company Sales Data of Last Year")
[Link]( loc = 4)
[Link](100000)
[Link]() [Link]()
Output:
Q8. Write a python program to read all product sales data and show it using a multiline
plot.
Code:
import [Link] as plt import
numpy as np
12
#Create Dataset
month_number=[1,2,3,4,5,6,7,8,9,10,11,12] facecream =
[2500,2630,2140,3400,3600,2760,2980,3700,3540,1990,2340,2900] facewash =
[1500,1200,1340,1130,1740,1555,1120,1400,1780,1890,2100,1760]
toothpaste=[5200,5100,4550,5870,4560,4890,4780,5860,6100,8300,7300,7400]
bathingshop=[9200,6100,9550,8870,7760,7490,8980,9960,8100,10300,13300,14400]
shampoo=[1200,2100,3550,1870,1560,1890,1780,2860,2100,2300,2400,1800]
moisturizer=[1500,1200,1340,1130,1740,1555,1120,1400,1780,1890,2100,1760]
total_units=[21100,18330,22470,22270,20960,20140,29550,36140,23400,26670,41280,30020]
total_profit=[211000,183300,224700,222700,209600,201400,295500,361400,234000,266700,412800,30
0200]
[Link](month_number,facecream, linestyle='-', label="Face cream Sales Data", marker='o' )
[Link](month_number,facewash, linestyle='-', label="Face Wash Sales Data", marker='o' )
[Link](month_number,toothpaste, linestyle='-', label="ToothPaste Sales Data", marker='o' )
[Link](month_number,bathingshop, linestyle='-', label="Bathingshop Sales Data", marker='o' )
[Link](month_number,moisturizer, linestyle='-', label="Moisturizer Sales Data", marker='o' )
[Link](month_number,shampoo, linestyle='-', label="Shampoo Sales Data", marker='o' )
[Link]("Months Number") [Link]("Sales units in number") [Link](loc=2)
[Link](1000)
[Link]()
Output:
13
Q9. Write a python program to read toothpaste sales data of each month and show it using
a scatter plot.
Code:
import [Link] as plt import
numpy as np
#Create Dataset
month_number= [1,2,3,4,5,6,7,8,9,10,11,12] facecream =
[2500,2630,2140,3400,3600,2760,2980,3700,3540,1990,2340,2900] facewash =
[1500,1200,1340,1130,1740,1555,1120,1400,1780,1890,2100,1760] toothpaste=
[5200,5100,4550,5870,4560,4890,4780,5860,6100,8300,7300,7400] bathingshop=
[9200,6100,9550,8870,7760,7490,8980,9960,8100,10300,13300,14400] shampoo=
[1200,2100,3550,1870,1560,1890,1780,2860,2100,2300,2400,1800] moisturizer=
[1500,1200,1340,1130,1740,1555,1120,1400,1780,1890,2100,1760] total_units=
[21100,18330,22470,22270,20960,20140,29550,36140,23400,26670,41280,30020]
total_profit=[211000,183300,224700,222700,209600,201400,295500,361400,234000,266700,412800,30
0200]
14
[Link](month_number,toothpaste, label="Toothpaste Sales Data")
[Link](loc=2) [Link](linestyle='--', linewidth=1) [Link]("Tooth
Paste sales data") [Link]("Month Number") [Link]("Number of
units Sold") [Link]()
Output:
15
Q10. Write a python program to read face cream and face wash product sales data and
show it using bar chart.
Code:
import [Link] as plt import
numpy as np
#Create Dataset
month_number=[1,2,3,4,5,6,7,8,9,10,11,12] facecream =
[2500,2630,2140,3400,3600,2760,2980,3700,3540,1990,2340,2900] facewash =
[1500,1200,1340,1130,1740,1555,1120,1400,1780,1890,2100,1760]
toothpaste=[5200,5100,4550,5870,4560,4890,4780,5860,6100,8300,7300,7400]
bathingshop=[9200,6100,9550,8870,7760,7490,8980,9960,8100,10300,13300,14400]
shampoo=[1200,2100,3550,1870,1560,1890,1780,2860,2100,2300,2400,1800]
moisturizer=[1500,1200,1340,1130,1740,1555,1120,1400,1780,1890,2100,1760]
total_units=[21100,18330,22470,22270,20960,20140,29550,36140,23400,26670,41280,30020]
total_profit=[211000,183300,224700,222700,209600,201400,295500,361400,234000,266700,412800,30
0200]
[Link]()
[Link]([Link](month_number), facecream , width=0.5, label="Facecream")
[Link]([Link](month_number) + 0.5, facewash, width = 0.5, label="Facewash") [Link](loc
= 1)
[Link](linestyle ='--' ,linewidth = .5)
[Link]([Link](month_number)) [Link]("Months")
[Link]("Sales Units in Number") [Link]("Facewash
and facecream sales data") [Link]()
Output:
16
Q11. Write a python program to read the total profit of each month and show it using
histogram to see the most common profit ranges.
Code:
import [Link] as plt import
numpy as np
#Create Dataset
month_number=[1,2,3,4,5,6,7,8,9,10,11,12] facecream =
[2500,2630,2140,3400,3600,2760,2980,3700,3540,1990,2340,2900] facewash =
[1500,1200,1340,1130,1740,1555,1120,1400,1780,1890,2100,1760]
toothpaste=[5200,5100,4550,5870,4560,4890,4780,5860,6100,8300,7300,7400]
bathingshop=[9200,6100,9550,8870,7760,7490,8980,9960,8100,10300,13300,14400]
shampoo=[1200,2100,3550,1870,1560,1890,1780,2860,2100,2300,2400,1800]
moisturizer=[1500,1200,1340,1130,1740,1555,1120,1400,1780,1890,2100,1760]
total_units=[21100,18330,22470,22270,20960,20140,29550,36140,23400,26670,41280,30020]
total_profit=[211000,183300,224700,222700,209600,201400,295500,361400,234000,266700,412800,30
0200]
[Link](total_profit, label="Profit Data")
[Link]("Profit range in Dollar")
17
[Link]("Actual Profit in Dollar")
[Link]("Profit Data") [Link](loc=2)
[Link]()
Output:
Q12. Write a python program to calculate total sale data for last year for each product and
show it using a pie chart.
Code:
import [Link] as plt import
numpy as np
18
#Create Dataset
month_number=[1,2,3,4,5,6,7,8,9,10,11,12] facecream =
[2500,2630,2140,3400,3600,2760,2980,3700,3540,1990,2340,2900] facewash =
[1500,1200,1340,1130,1740,1555,1120,1400,1780,1890,2100,1760]
toothpaste=[5200,5100,4550,5870,4560,4890,4780,5860,6100,8300,7300,7400]
bathingshop=[9200,6100,9550,8870,7760,7490,8980,9960,8100,10300,13300,14400]
shampoo=[1200,2100,3550,1870,1560,1890,1780,2860,2100,2300,2400,1800]
moisturizer=[1500,1200,1340,1130,1740,1555,1120,1400,1780,1890,2100,1760]
total_units=[21100,18330,22470,22270,20960,20140,29550,36140,23400,26670,41280,30020]
total_profit=[211000,183300,224700,222700,209600,201400,295500,361400,234000,266700,412800,30
0200]
total_sale = [sum(facecream), sum(facewash), sum(toothpaste), sum(bathingshop),
sum(shampoo),sum(moisturizer)]
label = ['Facecream', 'Facewash', 'Toothpaste', 'Bathingsoap','Shampoo','Moisturizer']
[Link](total_sale , autopct='%1.1f%%', labels=label) [Link](loc=4)
[Link]()
Output:
19
Q13. Write a python program to find the correlation between variables of iris data. Also
create a heatmap using seaborn to present their relations.
Code:
import pandas as pd import
numpy as np import
[Link] as plt import
seaborn as sns iris =
pd.read_csv("[Link]")
#Drop id column
iris = [Link]('Id',axis=1) X
= [Link][:, 0:4]
f, ax = [Link](figsize=(10, 8))
corr = [Link]() print(corr)
[Link](corr, mask=np.zeros_like(corr),
cmap=sns.diverging_palette(220, 10, as_cmap=True),square=True, ax=ax, linewidths=.5) [Link]()
20
Output:
21
Q14. Write a python program to create a box plot which shows the distribution of
quantitative data in a way that facilitates comparisons between variables or across levels of
a categorical variable of iris dataset. Use seaborn.
Code:
import pandas as pd import
seaborn as sns iris =
pd.read_csv("[Link]")
#Drop id column
iris = [Link]('Unnamed: 0',axis=1) box_data = iris
#variable representing the data array box_target = [Link]
#variable representing the labels array [Link](data =
box_data,width=0.5,fliersize=5)
[Link](rc={'[Link]':(10,10)})
Output:
22
Q15. Write a python program to read the mobile company name and stock data and show it
using waffle chart.
Code:
import pandas as pd import
[Link] as plt
from pywaffle import Waffle
# Sample data: Mobile company names and their stock data (in market capitalization or stock price) data
={
'Company': ['Apple', 'Samsung', 'Xiaomi', 'OnePlus', 'realme', 'Vivo'],
'Stock Price': [150, 100, 70, 80, 90, 120]
}
# Create a DataFrame
df = [Link](data)
# Normalize the stock prices to get proportions for the waffle chart total
= df['Stock Price'].sum()
df['Proportion'] = (df['Stock Price'] / total) * 100
# Create a Waffle Chart fig
=
[Link]( FigureClass=
Waffle, rows=5,
values=df['Proportion'],
labels=[f"{company} ({stock}%)" for company, stock in zip(df['Company'],
df['Proportion'].round(1))], fig size= (10, 15),
colors= ["#FF9999", "#66B2FF", "#99FF99", "#FFCC99", "#FF66B2", "#FF5733"], legend=
{'loc': 'upper left', 'b box to _anchor': (1, 1)},
icons='mobile-alt' # Optional: adds mobile icons in place of squares
icon_ size=25, icon_ legend=True
}
[Link]()
Output:
23
24