Challenge

Project 1

Data cleaning on Automobile 1985 dataset and perform descriptive analytics

About dataset:

No. of data points: 205

Number of Attributes: 26 total

-- 15 continuous

-- 1 integer

-- 10 nominal

Attribute Information:

| Attribute | Attribute Range

-- symboling: -3, -2, -1, 0, 1, 2, 3
-- normalized-losses: continuous from 65 to 256
-- make: alfa-romero, audi, bmw, chevrolet, dodge, honda, isuzu, jaguar, mazda, mercedes-benz, mercury, mitsubishi, nissan, peugot, plymouth, porsche, renault, saab, subaru, toyota, volkswagen, volvo
-- fuel-type: diesel, gas
-- aspiration: std, turbo
-- num-of-doors: four, two
-- body-style: hardtop, wagon, sedan, hatchback, convertible
-- drive-wheels: 4wd, fwd, rwd
-- engine-location: front, rear
-- wheel-base: continuous from 86.6 120.9
-- length: continuous from 141.1 to 208.1
-- width: continuous from 60.3 to 72.3
-- height: continuous from 47.8 to 59.8
-- curb-weight: continuous from 1488 to 4066
-- engine-type: dohc, dohcv, l, ohc, ohcf, ohcv, rotor
-- num-of-cylinders: eight, five, four, six, three, twelve, two
-- engine-size: continuous from 61 to 326
-- fuel-system: 1bbl, 2bbl, 4bbl, idi, mfi, mpfi, spdi, spfi
-- bore: continuous from 2.54 to 3.94
-- stroke: continuous from 2.07 to 4.17
-- compression-ratio: continuous from 7 to 23
-- horsepower: continuous from 48 to 288
-- peak-rpm: continuous from 4150 to 6600
-- city-mpg: continuous from 13 to 49
-- highway-mpg: continuous from 16 to 54
-- price: continuous from 5118 to 45400.

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
plt.rcParams["patch.force_edgecolor"] = True
%matplotlib inline
import seaborn as sns
sns.set_style('whitegrid')
import warnings
warnings.filterwarnings('ignore')
from scipy.sparse import hstack
from sklearn.preprocessing import Normalizer ,OneHotEncode
df=pd.read_csv('auto_clean.csv')

df.head()
df.info()
df.select_dtypes(include='number').head()
plt.figure(figsize=(15,10))
sns.countplot(df['normalized-losses'])
plt.title('Bore values')
plt.show()
def return_number(value):
if '?' in value:
return 0
else:
return float (value)



df['normalized-losses'].describe()

##Distribution
sns.displot(df['normalized-losses'],kde= True)
plt.title('Distribution of Loss value')
plt.show()
# handing outlier
df['normalized-losses']=df['normalized-losses'].apply(lambda x:df['normalized-losses'].median() if (x>170) else x)
sns.displot(df['normalized-losses'],kde= True)
plt.title('Distribution of Loss value')
plt.show()
#bore
plt.figure(figsize=(15,10))
sns.countplot(df['bore'])
plt.title('Bore values')
plt.show()
df['bore'].describe()
sns.displot(df.bore,kde= True)
plt.title('Distribution of Loss value')
plt.show()
# handling outlair
df['bore']=df['bore'].apply(lambda x:df['bore'].median() if (x==0) else x)
sns.displot(df.bore,kde= True)
plt.title('Distribution of Loss value')
plt.show()
# stroke
plt.figure(figsize=(15,10))
sns.countplot(df['stroke'])
plt.title('stroke values')
plt.show()

df['stroke'].describe()

sns.displot(df.stroke,kde= True)
plt.title('Distribution of stroke value')
plt.show()
#outlires handling
df['stroke']=df['stroke'].apply(lambda x:df['stroke'].median() if (x<2.50) else x)
sns.displot(df.stroke,kde= True)
plt.title('Distribution of stroke value')
plt.show()

plt.figure(figsize=(15,10))
sns.countplot(df['horsepower'])
plt.title('HP values')
plt.show()

df['horsepower'].describe()


sns.displot(df.horsepower,kde= True)
plt.title('Distribution of HP value')
plt.show()

#outlires handling
df['horsepower']=df['horsepower'].apply(lambda x:df['horsepower'].median() if (x==0 or x>250) else x)


sns.displot(df.horsepower,kde= True)
plt.title('Distribution of HP value')
plt.show()

#Peak rpm

plt.figure(figsize=(15,10))
sns.countplot(df['peak-rpm'])
plt.title('RPM values')
plt.show()

sns.displot(df['peak-rpm'],kde= True)
plt.title('Distribution of peak rpm value')
plt.show()

#outlires handling

df['peak-rpm']=df['peak-rpm'].apply(lambda x:df['peak-rpm'].median() if (x>6300) else x)
sns.displot(df['peak-rpm'],kde= True)
plt.title('Distribution of peak rpm value')
plt.show()

df['price'].value_counts()

df['price'].describe()

sns.displot(df['price'],kde= True)
plt.title('Distribution of price value')
plt.show()

df.select_dtypes(include='number').head()


df.select_dtypes(exclude='number').head()

# Analysis numerically value

plt.figure(figsize=(15,10))
sns.heatmap(df.select_dtypes(include='number').corr() ,annot= True, cmap='coolwarm')
plt.title('correlation of all Numerical features')
plt.show()

df.select_dtypes(exclude='number')

cat_columns=df.select_dtypes(exclude='number').columns


fig, axes =plt.subplots(4,2)
fig.set_figheight(15)
fig.set_figwidth(15)


for ax ,col in zip ( axes.flatten(),cat_columns):
sns.kdeplot(ax=ax,df=df, x ='Price',hue=col)
ax.set_title("Distribution of price on "+str(col))
plt.tight_layout()

 
Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.