How To Standardize Data In Python With Scikit Learn

Next Story

Python Perceptron Tutorial

Standardization

Sometimes when you are working with datasets for data science, you will need to standardize your dataset before fitting a machine learning model to it.

What exactly does standardization do?

It essentially takes your values and shifts the values so that the original mean value is placed at 0 and the standard deviation is 1.

It is very convenient for statistics enthusiasts because it makes your dataset very easy to explain.

Check out below for an example for the iris dataset.


# import necessary modules
from sklearn.datasets import load_iris
from sklearn import preprocessing

# access iris data set from sklearn datasets
iris = load_iris()

# separate data to X and y for features and targets
X = iris.data
y = iris.target

# print out standardized version of features dataset X
print(preprocessing.scale(X))

Try this out on your dataset and see what happens 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

https://www.googletagmanager.com/gtag/js?id=UA-63695651-4