0% found this document useful (0 votes)
4 views

Lab-3_Normalization-of-Dataset

Lab work for normalization and data transformation

Uploaded by

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

Lab-3_Normalization-of-Dataset

Lab work for normalization and data transformation

Uploaded by

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

Lab 3: Normalization of dataset

1. Create a dataset as below:


data = { "Feature1": [10, 20, 30, 40, 50],
"Feature2": [100, 200, 300, 400, 500],
"Feature3": [5, 15, 25, 35, 45]
}

a) Perform Min-Max normalization


b) Perform Z-score normalization
c) Perform Decimal Scale normalization

import pandas as pd
from sklearn.preprocessing import MinMaxScaler
import numpy as np

# Creating the dataset


data = {
"Feature1": [10, 20, 30, 40, 50],
"Feature2": [100, 200, 300, 400, 500],
"Feature3": [5, 15, 25, 35, 45],
}

df = pd.DataFrame(data)
print("Original Data:")
print(df)

# a) Perform Min-Max normalization


min_max_scaler = MinMaxScaler()
df_min_max = min_max_scaler.fit_transform(df)
df_min_max = pd.DataFrame(df_min_max, columns=df.columns)
print("Min-Max Normalized Data:")
print(df_min_max)

# b) Perform Z-score normalization


df_z_score = (df - df.mean()) / df.std()
print("\nZ-score Normalized Data:")
print(df_z_score)

# c) Perform Decimal Scale normalization


# Decimal scale normalization: scale by the power of 10 to move the
maximum value to less than 1
df_decimal_scale = df / 10**np.floor(np.log10(df.max()))
print("\nDecimal Scale Normalized Data:")
print(df_decimal_scale)

You might also like