#5, First Floor, 4th Street , Dr. Subbarayan Nagar Kodambakkam, Chennai-600 024 pro@slogix.in

Office Address

  • #5, First Floor, 4th Street Dr. Subbarayan Nagar Kodambakkam, Chennai-600 024 Landmark : Samiyar Madam
  • pro@slogix.in
  • +91- 81240 01111

Social List

How to do standardize and Normalize the data for more optimal results using python?
Description

To standardize and normalize the input features for more accurate results in python.

Input

Features from Iris flower data set.

Sepal-Length

Sepal-Width

Petal-Length

Petal-Width

Output

Standardized features.

Normalized features between 0 to 1.

Process

   Import the libraries.

   Load the data set. (Sample)

   Initialize the standard scalar and normalizer from sklearn.

   Fit the data into the constructor, which features you want to standardize or normalize.

   Print the results.

Sapmle Code

#Import libraries
import pandas as pd

#load data
data = pd.read_csv(‘/home/soft50/soft50/Sathish/practice/iris.csv’)

#make it as dataframe
df = pd.DataFrame(data)

#Feature extraction
X = df.iloc[:,0:4]
print(“Before standardization\n\n”,X)
print(“\n”)

#Scaling the independent variable
from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
X = sc.fit_transform(X)
stand_X = sc.transform(X)
print(“After standardization\n\n”,stand_X)
print(“\n”)

#variable normalization
from sklearn.preprocessing import Normalizer
scaler = Normalizer().fit(X)
normalized_X = scaler.transform(X)
print(“After Normalization\n\n”,normalized_X)

Screenshots