0% found this document useful (0 votes)
0 views3 pages

Program 1

The program aims to create histograms and box plots for all numerical features in the California Housing dataset to analyze their distributions and identify outliers. It utilizes libraries such as pandas, seaborn, and matplotlib for data visualization and employs the IQR method for outlier detection. Finally, it prints a summary of the dataset including the number of outliers for each feature.

Uploaded by

rajakumar524p
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)
0 views3 pages

Program 1

The program aims to create histograms and box plots for all numerical features in the California Housing dataset to analyze their distributions and identify outliers. It utilizes libraries such as pandas, seaborn, and matplotlib for data visualization and employs the IQR method for outlier detection. Finally, it prints a summary of the dataset including the number of outliers for each feature.

Uploaded by

rajakumar524p
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

Program 1:

AIM: Develop a program to create histograms for all numerical features and analyze the distribution
of each feature. Generate box plots for all numerical features and identify any outliers. Use California
Housing dataset.

Source code:
import pandas as pd
import numpy as np
import seaborn as sns
import [Link] as plt
from [Link] import fetch_california_housing

.IN
# Step 1: Load the California Housing dataset
data = fetch_california_housing(as_frame=True)
housing_df = [Link]
C
N
# Step 2: Create histograms for numerical features
SY

numerical_features = housing_df.select_dtypes(include=[[Link]]).columns
# Plot histograms
[Link](figsize=(15, 10))
U

for i, feature in enumerate(numerical_features):


VT

[Link](3, 3, i + 1)
[Link](housing_df[feature], kde=True, bins=30, color='blue')
[Link](f'Distribution of {feature}')
plt.tight_layout()
[Link]()

# Step 3: Generate box plots for numerical features


[Link](figsize=(15, 10))
for i, feature in enumerate(numerical_features):
[Link](3, 3, i + 1)
[Link](x=housing_df[feature], color='orange')
[Link](f'Box Plot of {feature}')
plt.tight_layout()
10
[Link]()
# Step 4: Identify outliers using the IQR method
print("Outliers Detection:")
outliers_summary = {}
for feature in numerical_features:
Q1 = housing_df[feature].quantile(0.25)
Q3 = housing_df[feature].quantile(0.75)
IQR = Q3 - Q1
lower_bound = Q1 - 1.5 * IQR
upper_bound = Q3 + 1.5 * IQR
outliers = housing_df[(housing_df[feature] < lower_bound) | (housing_df[feature] > upper_bound)]
outliers_summary[feature] = len(outliers)

.IN
print(f"{feature}: {len(outliers)} outliers")
#Print a summary of the dataset
print("\nDataset Summary:")
print(housing_df.describe()) C
N
SY

Output:
U
VT

11
VT
U
SY

12
N
C
.IN

You might also like