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

Program 1

The document outlines a program to analyze the California Housing dataset by creating histograms and box plots for all numerical features. It includes steps to identify outliers using the IQR method and provides a summary of the dataset. The program utilizes libraries such as pandas, numpy, seaborn, and matplotlib for data visualization.

Uploaded by

nageshp2521
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)
4 views3 pages

Program 1

The document outlines a program to analyze the California Housing dataset by creating histograms and box plots for all numerical features. It includes steps to identify outliers using the IQR method and provides a summary of the dataset. The program utilizes libraries such as pandas, numpy, seaborn, and matplotlib for data visualization.

Uploaded by

nageshp2521
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

Experiement 1 :

Develop a program to create histograms for all numerical features and analyze the distribu on of
each feature. Generate box plots for all numerical features and iden fy any outliers. Use California
Housing dataset.

import pandas as pd

import numpy as np

import seaborn as sns

import [Link] as plt

from [Link] import fetch_california_housing# Step 1: Load the California Housing dataset

data = fetch_california_housing(as_frame=True)

housing_df = [Link]# Step 2: Create histograms for numerical features

numerical_features = housing_df.select_dtypes(include=[[Link]]).columns# Plot histograms

plt.figure(figsize=(15, 10))

for i, feature in enumerate(numerical_features):

[Link](3, 3, i + 1)

[Link](housing_df[feature], kde=True, bins=30, color='blue')

plt. tle(f'Distribu on of {feature}')

plt. ght_layout()

[Link]()# Step 3: Generate box plots for numerical features

plt.figure(figsize=(15, 10))

for i, feature in enumerate(numerical_features):

[Link](3, 3, i + 1)

[Link](x=housing_df[feature], color='orange')

plt. tle(f'Box Plot of {feature}')

plt. ght_layout()

[Link]()

# Step 4: Iden fy outliers using the IQR method

print("Outliers Detec on:")

outliers_summary = {}

for feature in numerical_features:

Q1 = housing_df[feature].quan le(0.25)
Q3 = housing_df[feature].quan le(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)

print(f"{feature}: {len(outliers)} outliers")# Op onal: Print a summary of the dataset

print("\nDataset Summary:")

print(housing_df.describe())

OUTPUT:

You might also like