DEPARTMENT OF MECHANICAL ENGINEERING
DATA ANALYTICS ASSIGNMENT-5
NAME : Kusum Gore
MIS : 612210056 BATCH : C DIV : 1
#a
# Consider the same Iris Dataset and perform visualiza on on the
same:
# Write a Python program to create a Bar plot and pie plot to get the
frequency of the three species of the Iris data.
import pandas as pd
import matplotlib.pyplot as plt
# Load the Iris dataset
from sklearn.datasets import load_iris
iris = load_iris()
df = pd.DataFrame(data=iris.data, columns=iris.feature_names)
df['species'] = pd.Categorical.from_codes(iris.target,
iris.target_names)
# Frequency of each species
species_counts = df['species'].value_counts()
# Bar plot
plt.figure(figsize=(12, 6))
plt.subplot(1, 2, 1)
species_counts.plot(kind='bar', color='skyblue')
plt. tle('Bar Plot of Iris Species')
plt.xlabel('Species')
plt.ylabel('Frequency')
# Pie plot
plt.subplot(1, 2, 2)
species_counts.plot(kind='pie', autopct='%1.1f%%',
colors=['lightcoral', 'lightblue',
'lightgreen'])
plt. tle('Pie Plot of Iris Species')
plt. ght_layout()
plt.show()
OUTPUT :
#b
# Write a Python program to create a graph to see how the length
and width of Sepal Length, Sepal Width, Petal Length, Petal Width are
distributed.
import seaborn as sns
import matplotlib.pyplot as plt
# Distribu on plots for all features
plt.figure(figsize=(12, 10))
plt.subplot(2, 2, 1)
sns.histplot(df['sepal length (cm)'], kde=True)
plt. tle('Sepal Length Distribu on')
plt.subplot(2, 2, 2)
sns.histplot(df['sepal width (cm)'], kde=True)
plt. tle('Sepal Width Distribu on')
plt.subplot(2, 2, 3)
sns.histplot(df['petal length (cm)'], kde=True)
plt. tle('Petal Length Distribu on')
plt.subplot(2, 2, 4)
sns.histplot(df['petal width (cm)'], kde=True)
plt. tle('Petal Width Distribu on')
plt. ght_layout()
plt.show()
OUTPUT :
#c
# Write a Python program to create a joinplot to describe individual
distribu ons on the same plot between Sepal length and Sepal width.
# Note: joinplot - Draw a plot of two variables with bivariate and
univariate graphs.
import seaborn as sns
import matplotlib.pyplot as plt
plt.figure(figsize=(8, 6))
sns.jointplot(x='sepal length (cm)', y='sepal width (cm)', data=df,
kind='sca er',
color='blue')
plt.sup tle('Jointplot of Sepal Length and Sepal Width', y=1.02)
plt.show()
OUTPUT :
#d
# Write a Python program to draw a sca erplot,
# then add a joint density es mate to describe individual
distribu ons on the same plot between Sepal length and Sepal width.
import seaborn as sns
import matplotlib.pyplot as plt
plt.figure(figsize=(8, 6))
sns.jointplot(x='sepal length (cm)', y='sepal width (cm)', data=df,
kind='kde', color='green')
plt.sup tle('Joint Density Es mate of Sepal Length and Sepal Width',
y=1.02)
plt.show()
OUTPUT :
#e
#Write a Python program using seaborn to Create a kde (Kernel
Density Es mate) plot of sepal_length versus sepal width for setosa
species of flower.
import seaborn as sns
import matplotlib.pyplot as plt
# Import the iris dataset using seaborn
iris = sns.load_dataset('iris')
# Assign the iris dataset to df
df = iris
# Filter for Setosa species
setosa_df = df[df['species'] == 'setosa']
plt.figure(figsize=(8, 6))
sns.kdeplot(x='sepal_length', y='sepal_width', data=setosa_df,
cmap='coolwarm') #
plt. tle('KDE Plot of Sepal Length vs Sepal Width for Setosa')
plt.show()
OUTPUT :
#f
# Write a Python program to create a box plot (or box-and-whisker
plot) which shows the distribu on of quan ta ve data in a way that
facilitates comparisons between variables or across levels of a
categorical variable of iris dataset.
# Useseaborn
import seaborn as sns
import matplotlib.pyplot as plt
plt.figure(figsize=(12, 8))
sns.boxplot(data=df, orient='h')
plt. tle('Box Plot of Iris Features')
plt.show()