Professional Documents
Culture Documents
Exp 2
Exp 2
Submitted by
Name: Gokul Krishnan S
Registration Number: 20BEE0184
Year: 3rd Semester: Winter Semester
Python Script:
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.
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]
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])
Submitted by
Name: Gokul Krishnan S
Registration Number: 20BEE0184
Year: 3rd Semester: Winter Semester
Python Script:
L1:
L2:
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.
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]
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
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])