0% found this document useful (0 votes)
2 views1 page

program 2

The document provides a Python script that utilizes the Seaborn and Matplotlib libraries to analyze the Iris dataset. It generates a scatter plot to visualize the relationship between sepal length and petal length, computes the Pearson correlation, and displays both the covariance and correlation matrices. Additionally, it creates a heatmap to illustrate the correlation coefficients among the dataset's numerical features.

Uploaded by

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

program 2

The document provides a Python script that utilizes the Seaborn and Matplotlib libraries to analyze the Iris dataset. It generates a scatter plot to visualize the relationship between sepal length and petal length, computes the Pearson correlation, and displays both the covariance and correlation matrices. Additionally, it creates a heatmap to illustrate the correlation coefficients among the dataset's numerical features.

Uploaded by

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

import pandas as pd

import seaborn as sns


import matplotlib.pyplot as plt

# Load built-in Iris dataset


df = sns.load_dataset('iris')

# Display first few rows


print(df.head())

# Select two numerical columns


x, y = 'sepal_length', 'petal_length'

# Scatter plot & Pearson correlation


sns.scatterplot(data=df, x=x, y=y)
plt.title(f'Scatter Plot: {x} vs {y}')
plt.show()
print(f"Pearson Correlation between {x} and {y}: {df[x].corr(df[y]):.2f}")

# Covariance & Correlation Matrix


cov_matrix = df.cov(numeric_only=True)
corr_matrix = df.corr(numeric_only=True)
print("\nCovariance Matrix:\n", cov_matrix)
print("\nCorrelation Matrix:\n", corr_matrix)

# Correlation Heatmap
plt.figure(figsize=(6, 4))
sns.heatmap(corr_matrix, annot=True, cmap='coolwarm', fmt=".2f")
plt.title("Correlation Heatmap")
plt.tight_layout()
plt.show()

You might also like