pvabishek / Ex-06-Feature-Transformation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Ex-06-Feature-Transformation

AIM

To read the given data and perform Feature Transformation process and save the data to a file.

EXPLANATION

Feature Transformation is a technique by which we can boost our model performance. Feature transformation is a mathematical transformation in which we apply a mathematical formula to a particular column(feature) and transform the values which are useful for our further analysis.

ALGORITHM

STEP 1: Read the given Data

STEP 2: Clean the Data Set using Data Cleaning Process

STEP 3: Apply Feature Transformation techniques to all the features of the data set

STEP 4: Save the data to the file

PROGRAM AND OUTPUT:

reg no: 2122223003


import pandas as pd
from scipy import stats
import numpy as np
df=pd.read_csv("Data_to_Transform.csv")
df

image

df.skew()

image

np.log(df["Highly Positive Skew"])

image

np.reciprocal(df["Moderate Positive Skew"])

image

np.sqrt(df["Highly Positive Skew"])

image

np.square(df["Highly Positive Skew"])

image

df["Highly Positive Skew_boxcox"],parameters=stats.boxcox(df["Highly Positive Skew"])
df

image

df["Moderate Negative Skew_yeojohnson"],parameters=stats.yeojohnson(df["Moderate Negative Skew"])
df

image

from sklearn.preprocessing import QuantileTransformer
qt=QuantileTransformer(output_distribution='normal')
df["Moderate Negative Skew_1"]=qt.fit_transform(df[["Moderate Negative Skew"]])
df

image

import matplotlib.pyplot as plt
import seaborn as sns
import statsmodels.api as sm
import scipy.stats as stats
sm.qqplot(df['Moderate Negative Skew'],line='45')
plt.show()

image

sm.qqplot(df['Moderate Negative Skew_1'],line='45')
plt.show()

image

df['Highly Negative Skew_1']=qt.fit_transform(df[["Highly Negative Skew"]])
sm.qqplot(df['Highly Negative Skew'],line='45')
plt.show()

image

RESULT:

Thus,Feature transformation is performed and executed successfully for the given dataset

About

License:MIT License