Research breakthrough possible @S-Logix pro@slogix.in

Office Address

  • 2nd Floor, #7a, High School Road, Secretariat Colony Ambattur, Chennai-600053 (Landmark: SRM School) Tamil Nadu, India
  • 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.

Sample 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
standardize and Normalize the data for more optimal results using python
import pandas as pd
Initialize the standard scalar and normalizer from sklearn