import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
# Load the iris Dataset
df = pd.read_csv("iris.csv")
# Display basic info
df.head()
# Create a figure with subplots (2 rows, 2 columns)
fig, axes = plt.subplots(2, 2, figsize=(12, 8))
# Histogram for Sepal Length
sns.histplot(df["sepal_length"], bins=20, kde=True, color="blue", ax=axes[0, 0])
axes[0, 0].set_title("Distribution of Sepal Length")
axes[0, 0].set_xlabel("Sepal Length (cm)")
axes[0, 0].set_ylabel("Count")
# Histogram for Sepal Width
sns.histplot(df["sepal_width"], bins=20, kde=True, color="green", ax=axes[0, 1])
axes[0, 1].set_title("Distribution of Sepal Width")
axes[0, 1].set_xlabel("Sepal Width (cm)")
axes[0, 1].set_ylabel("Count")
# Histogram for Petal Length
sns.histplot(df["petal_length"], bins=20, kde=True, color="black", ax=axes[1, 0])
axes[1, 0].set_title("Distribution of Petal Length")
axes[1, 0].set_xlabel("Petal Length (cm)")
axes[1, 0].set_ylabel("Count")
# Histogram for Petal Width
sns.histplot(df["petal_width"], bins=20, kde=True, color="red", ax=axes[1, 1])
axes[1, 1].set_title("Distribution of Petal Width")
axes[1, 1].set_xlabel("Petal Width (cm)")
axes[1, 1].set_ylabel("Count")
# Adjust layout
plt.tight_layout()
plt.show()
# 2️⃣ Scatter Plot: Sepal Length vs Sepal Width
# ------------------------------ #
plt.figure(figsize=(6, 4))
sns.scatterplot(x="sepal_length", y="sepal_width", hue="species", data=df, palette="deep")
plt.title("Sepal Length vs Sepal Width")
plt.xlabel("Sepal Length (cm)")
plt.ylabel("Sepal Width (cm)")
plt.show()
# 8️⃣ Correlation Heatmap
# ------------------------------ #
plt.figure(figsize=(6, 4))
# Select only numerical columns for correlation calculation
numerical_df = df.select_dtypes(include=['number'])
sns.heatmap(numerical_df.corr(), annot=True, cmap="coolwarm", linewidths=0.5)
plt.title("Feature Correlation Heatmap")
plt.show()
Comments
Post a Comment