Download as pdf or txt
Download as pdf or txt
You are on page 1of 13

School of Electrical Engineering

Department of Electrical Engineering

Lab Task Sheet


Experiment No. 2 Sub Task. 1
Title: Rescaling of the Pollution Data
Date: 4 January 2023

Submitted by
Name: Gokul Krishnan S
Registration Number: 20BEE0184
Year: 3rd Semester: Winter Semester

Faculty: Dr. R. Sitharthan, SELECT, VIT-Vellore-14


Rescaling of the Pollution Data
Aim:
To read the file “pollution.csv” and rescale to a range 0-10 and
display the first 10 rows.

Python Script:

Faculty: Dr. R. Sitharthan, SELECT, VIT-Vellore-14


Spreadsheet Window (CSV File):

Procedure:
• Open Python IDE and create a new script.
• Install pandas library.
• Install scikit-learn library.
• Locate to the directory where the csv file has been stored.
• Type the scaling code in the newly created script.
• Make the range to 0 to 10.
• Click run.
• Now the data will be scaled to 10 rows.
• In the python shell we can see the scaled data.

Faculty: Dr. R. Sitharthan, SELECT, VIT-Vellore-14


Experimental Pictures (OUTPUT):

Scaled data:
[[0.00e+00 0.00e+00 0.00e+00 0.00e+00 0.00e+00 2.79e-01 1.31e-01
5.45e-01
2.29e-03 0.00e+00 0.00e+00]
[2.28e-05 0.00e+00 0.00e+00 0.00e+00 4.35e-02 2.79e-01 1.15e-01
5.27e-01
7.64e-03 0.00e+00 0.00e+00]
[4.56e-05 0.00e+00 0.00e+00 0.00e+00 8.70e-02 2.79e-01 1.31e-01
5.09e-01
1.07e-02 0.00e+00 0.00e+00]
[6.85e-05 0.00e+00 0.00e+00 0.00e+00 1.30e-01 2.79e-01 8.20e-02
5.09e-01
1.60e-02 0.00e+00 0.00e+00]

Faculty: Dr. R. Sitharthan, SELECT, VIT-Vellore-14


[9.13e-05 0.00e+00 0.00e+00 0.00e+00 1.74e-01 2.94e-01 1.15e-01
4.91e-01
2.14e-02 0.00e+00 0.00e+00]
[1.14e-04 0.00e+00 0.00e+00 0.00e+00 2.17e-01 3.09e-01 1.48e-01
4.73e-01
2.67e-02 0.00e+00 0.00e+00]
[1.37e-04 0.00e+00 0.00e+00 0.00e+00 2.61e-01 3.09e-01 1.64e-01
4.73e-01
3.21e-02 0.00e+00 0.00e+00]
[1.60e-04 0.00e+00 0.00e+00 0.00e+00 3.04e-01 3.09e-01 1.64e-01
4.73e-01
3.52e-02 0.00e+00 0.00e+00]
[1.83e-04 0.00e+00 0.00e+00 0.00e+00 3.48e-01 3.09e-01 1.64e-01
4.73e-01
4.05e-02 0.00e+00 0.00e+00]
[2.05e-04 0.00e+00 0.00e+00 0.00e+00 3.91e-01 2.94e-01 1.80e-01
4.73e-01
4.59e-02 0.00e+00 0.00e+00]]

CODE:
from pandas import read_csv
from numpy import set_printoptions
from sklearn import preprocessing
# Read the CSV file and prepare the array
names = ['No', 'year', 'month', 'day', 'hour', 'DEWP', 'TEMP', 'PRES', 'Iws',
'Is', 'Ir']
dataframe = read_csv("pollution.csv")
array = dataframe.values
# Using MinMaxScaler class to rescale the data in the range of 0 and 1.
data_scaler = preprocessing.MinMaxScaler(feature_range=(0,1))
data_rescaled = data_scaler.fit_transform(array)
# Setting the precision to 2
set_printoptions(precision=2)
# Showing the first 10 rows in the output
print ("\nScaled data:\n", data_rescaled[0:10])

Faculty: Dr. R. Sitharthan, SELECT, VIT-Vellore-14


RESULTS:
The machine learning techniques and power of the python and
its libraries like pandas, scikit-learn has been used to rescale the
pollution data. The whole dataset is fed into a machine learning pre-
processing technique. The final scaled data to a range of 10 rows has
been printed on the python shell.

Faculty: Dr. R. Sitharthan, SELECT, VIT-Vellore-14


School of Electrical Engineering
Department of Electrical Engineering

Lab Task Sheet


Experiment No. 2 Sub Task. 2
Title: Normalizing of the Pollution Data
Date: 4 January 2023

Submitted by
Name: Gokul Krishnan S
Registration Number: 20BEE0184
Year: 3rd Semester: Winter Semester

Faculty: Dr. R. Sitharthan, SELECT, VIT-Vellore-14


Normalizing of the Pollution Data
Aim:
To read the file “pollution.csv” and normalize using L1 & L2 norms
and display first 10 rows.

Python Script:
L1:

L2:

Faculty: Dr. R. Sitharthan, SELECT, VIT-Vellore-14


Spreadsheet Window (CSV File):

Procedure:
• Open Python IDE and create a new script.
• Install pandas library.
• Install scikit-learn library.
• Locate to the directory where the csv file has been stored.
• Type the scaling code in the newly created script.
• Make the range to 0 to 10.
• Click run.
• Now the data will be scaled to 10 rows.
• In the python shell we can see the scaled data.

Faculty: Dr. R. Sitharthan, SELECT, VIT-Vellore-14


Experimental Pictures (OUTPUT):
L1:

Normalized data:
[[ 3.26e-04 6.55e-01 3.26e-04 3.26e-04 0.00e+00 -6.85e-03 -3.59e-03
3.33e-01 5.83e-04 0.00e+00 0.00e+00]
[ 6.51e-04 6.54e-01 3.25e-04 3.25e-04 3.25e-04 -6.83e-03 -3.91e-03
3.32e-01 1.60e-03 0.00e+00 0.00e+00]
[ 9.76e-04 6.54e-01 3.25e-04 3.25e-04 6.50e-04 -6.83e-03 -3.58e-03
3.31e-01 2.18e-03 0.00e+00 0.00e+00]
[ 1.30e-03 6.52e-01 3.24e-04 3.24e-04 9.73e-04 -6.81e-03 -4.54e-03
3.31e-01 3.19e-03 0.00e+00 0.00e+00]
[ 1.62e-03 6.52e-01 3.24e-04 3.24e-04 1.30e-03 -6.49e-03 -3.89e-03
3.30e-01 4.21e-03 0.00e+00 0.00e+00]
[ 1.94e-03 6.52e-01 3.24e-04 3.24e-04 1.62e-03 -6.16e-03 -3.24e-03
3.30e-01 5.22e-03 0.00e+00 0.00e+00]
[ 2.27e-03 6.51e-01 3.24e-04 3.24e-04 1.94e-03 -6.15e-03 -2.91e-03
3.29e-01 6.22e-03 0.00e+00 0.00e+00]

Faculty: Dr. R. Sitharthan, SELECT, VIT-Vellore-14


[ 2.59e-03 6.50e-01 3.23e-04 3.23e-04 2.26e-03 -6.14e-03 -2.91e-03
3.29e-01 6.80e-03 0.00e+00 0.00e+00]
[ 2.90e-03 6.49e-01 3.23e-04 3.23e-04 2.58e-03 -6.13e-03 -2.90e-03
3.28e-01 7.79e-03 0.00e+00 0.00e+00]
[ 3.22e-03 6.48e-01 3.22e-04 3.22e-04 2.90e-03 -6.44e-03 -2.58e-03
3.28e-01 8.79e-03 0.00e+00 0.00e+00]]

L2:

Normalized data:
[[ 4.44e-04 8.92e-01 4.44e-04 4.44e-04 0.00e+00 -9.31e-03 -4.88e-03
4.53e-01 7.94e-04 0.00e+00 0.00e+00]
[ 8.87e-04 8.92e-01 4.44e-04 4.44e-04 4.44e-04 -9.32e-03 -5.32e-03
4.53e-01 2.18e-03 0.00e+00 0.00e+00]
[ 1.33e-03 8.92e-01 4.44e-04 4.44e-04 8.87e-04 -9.32e-03 -4.88e-03
4.52e-01 2.98e-03 0.00e+00 0.00e+00]
[ 1.77e-03 8.92e-01 4.44e-04 4.44e-04 1.33e-03 -9.32e-03 -6.21e-03
4.52e-01 4.37e-03 0.00e+00 0.00e+00]
[ 2.22e-03 8.92e-01 4.44e-04 4.44e-04 1.78e-03 -8.88e-03 -5.33e-03
4.52e-01 5.76e-03 0.00e+00 0.00e+00]
[ 2.66e-03 8.92e-01 4.44e-04 4.44e-04 2.22e-03 -8.43e-03 -4.44e-03

Faculty: Dr. R. Sitharthan, SELECT, VIT-Vellore-14


4.51e-01 7.15e-03 0.00e+00 0.00e+00]
[ 3.11e-03 8.92e-01 4.44e-04 4.44e-04 2.66e-03 -8.43e-03 -3.99e-03
4.51e-01 8.54e-03 0.00e+00 0.00e+00]
[ 3.55e-03 8.92e-01 4.44e-04 4.44e-04 3.11e-03 -8.43e-03 -3.99e-03
4.51e-01 9.33e-03 0.00e+00 0.00e+00]
[ 3.99e-03 8.92e-01 4.44e-04 4.44e-04 3.55e-03 -8.43e-03 -3.99e-03
4.51e-01 1.07e-02 0.00e+00 0.00e+00]
[ 4.44e-03 8.92e-01 4.44e-04 4.44e-04 3.99e-03 -8.88e-03 -3.55e-03
4.51e-01 1.21e-02 0.00e+00 0.00e+00]]

CODE:
L1:
from pandas import read_csv
from numpy import set_printoptions
from sklearn.preprocessing import Normalizer
# Read the CSV file and prepare the array
names = ['No', 'year', 'month', 'day', 'hour', 'DEWP', 'TEMP', 'PRES', 'Iws',
'Is', 'Ir']
dataframe = read_csv("pollution.csv")
array = dataframe.values
# Using Normalizer class with L1 to normalize the data.
Data_normalizer = Normalizer(norm='l1').fit(array)
Data_normalized = Data_normalizer.transform(array)
# Setting the precision to 2
set_printoptions(precision=2)
# Showing the first 3 rows in the output
print ("\nNormalized data:\n", Data_normalized [0:10])

L2:
from pandas import read_csv
from numpy import set_printoptions
from sklearn.preprocessing import Normalizer
# Read the CSV file and prepare the array
names = ['No', 'year', 'month', 'day', 'hour', 'DEWP', 'TEMP', 'PRES', 'Iws',
'Is', 'Ir']
dataframe = read_csv("pollution.csv")
array = dataframe.values
# Using Normalizer class with L2 to normalize the data.
Data_normalizer = Normalizer(norm='l2').fit(array)
Data_normalized = Data_normalizer.transform(array)
# Setting the precision to 2
set_printoptions(precision=2)
# Showing the first 3 rows in the output
print ("\nNormalized data:\n", Data_normalized [0:10])

Faculty: Dr. R. Sitharthan, SELECT, VIT-Vellore-14


RESULTS:
The machine learning techniques and power of the python and
its libraries like pandas, scikit-learn has been used to normalize the
pollution data. The whole dataset is fed into a machine learning pre-
processing technique. The final normalized data in both the L1 and
L2 norms were processed to a range of 10 rows has been printed on
the python shell.

Faculty: Dr. R. Sitharthan, SELECT, VIT-Vellore-14

You might also like