- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Explain how L2 Normalization can be implemented using scikit-learn library in Python?

The process of converting a range of values into standardized range of values is known as normalization. These values could be between -1 to +1 or 0 to 1. Data can be normalized with the help of subtraction and division as well.

Let us understand how L2 normalization works. It is also known as ‘Least Squares’. This normalization modifies the data in such a way that the sum of the squares of the data remains as 1 in every row.

Let us see how L2 normalization can be implemented using Scikit learn in Python −

## Example

import numpy as np from sklearn import preprocessing input_data = np.array( [[34.78, 31.9, -65.5],[-16.5, 2.45, -83.5],[0.5, -87.98, 45.62],[5.9, 2.38, -55.82]] ) normalized_data_l2 = preprocessing.normalize(input_data, norm='l2') print("

L2 normalized data is

", normalized_data_l2)

## Output

L2 normalized data is [[ 0.43081298 0.39513899 -0.81133554] [-0.19377596 0.02877279 -0.98062378] [ 0.00504512 -0.88774018 0.4603172 ] [ 0.10501701 0.04236279 -0.99356772]]

## Explanation

The required packages are imported.

The input data is generated using the Numpy library.

The ‘normalize’ function present in the class ‘preprocessing‘ is used to normalize the data such that the sum of squares of values in every row would be 1.

The type of normalization is specified as ‘l2’.

This way, any data in the array gets normalized and the sum of squares of every row would be 1 only.

This normalized data is displayed on the console.

- Related Questions & Answers
- Explain how L1 Normalization can be implemented using scikit-learn library in Python?
- How can data be scaled using scikit-learn library in Python?
- How can scikit learn library be used to preprocess data in Python?
- How can scikit-learn library be used to load data in Python?
- Explain the basics of scikit-learn library in Python?
- How can scikit learn library be used to upload and view an image in Python?
- Explain how scikit-learn library can be used to split the dataset for training and testing purposes in Python?
- How can scikit-learn library be used to get the resolution of an image in Python?
- Explain how Nelder-Mead algorithm can be implemented using SciPy Python?
- What is hysteresis thresholding? How can it be achieved using scikit-learn in Python?
- How to eliminate mean values from feature vector using scikit-learn library in Python?
- Learning Model Building in Scikit-learn: A Python Machine Learning Library
- How can a specific tint be added to grayscale images in scikit-learn in Python?
- How can transfer learning be implemented in Python using Keras?
- How can scikit-learn be used to convert an image from RGB to grayscale in Python?