sklearn.preprocessing.normalize in Python

In this tutorial, you will learn how to normalize the given set of data in Python. Normalization is a process of scaling individual samples to have unit norm. We will also see an example code to understand the use of this operation.

Introduction to Scikit-Learn

In this section, you’ll get a summary of the scikit-learn library. Scikit-learn is a machine learning package in python. In the scikit package, all the functions are written in optimized code, it is a very simple and efficient tool for data analysis and data mining. Before using sklearn package you have got to put in it by using the subsequent command in command prompt(cmd)

pip install sklearn

 normalize function

normalize is a function present in sklearn. preprocessing package. Normalization is used for scaling input data set on a scale of 0 to 1 to have unit norm. Norm is nothing but calculating the magnitude of the vector.




data:- like input array or matrix of the data set.

norm:- type of norm we use.


STEP 1:- import clean module

from sklearn import *

In the above code, we import all the functions of the sklearn module. * means all the functions.

STEP 2:-provide the input data set

inpt_data = [[1,2,3],

Here we provide data set in the form of the matrix. and stored it in variable inpt_data.

STEP 3:-Use normalize function to normalized the input data

data_normalized = preprocessing.normalize(inpt_data,norm='l2)')

In the above code, we use norm l2, you can also use norm l1. and we import all function of sklearn so here no need to write sklearn

STEP 4:-Print the normalized data



array([[0.26726124, 0.53452248, 0.80178373],
       [0.45584231, 0.56980288, 0.68376346],
       [0.50257071, 0.57436653, 0.64616234]])

Also, read: Pipeline in Machine Learning using scikit-learn

Leave a Reply

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