How to normalize a matrix in numpy?
MACHINE LEARNING RECIPES DATA CLEANING PYTHON DATA MUNGING PANDAS CHEATSHEET     ALL TAGS

How to normalize a matrix in numpy?

How to normalize a matrix in numpy?

This recipe helps you normalize a matrix in numpy

0

Recipe Objective

Normalization is a process of organizing the data in a database to avoid data redundancy, insertion anomaly, update anomaly & deletion anomaly. Many a times, it becomes unavoidable when dealing with large datasets especially image processing.

So this recipe is a short example on how to to normalize matrix in numpy. Let's get started.

Step 1 - Import the library

import numpy as np

Let's pause and look at these imports. Numpy is generally helpful in data manipulation while working with arrays. It also helps in performing mathematical operation.

Step 2 - Setup the Data

df= np.random.random((3,3)) print("Original Array:") print(df)

We have a created a simple 3x3 matrix in form of an array, containing random values.

Step 3 - Performing Normalization

dfmax, dfmin = df.max(), df.min() df = (df - dfmin)/(dfmax - dfmin) print(df)

For normalization, the calculation follows as subtracting each element by minimum value of matrix and thereby dividing the whole with difference of minimum and maximum of whole matrix.

Step 4 - Printing matrix

print("After normalization:") print(df)

We are simply trying to print normalized array in here.

Step 5 - Lets look at our dataset now

Once we run the above code snippet, we will see:

Scroll down the ipython notebook to visualize the output.

Relevant Projects

Natural language processing Chatbot application using NLTK for text classification
In this NLP AI application, we build the core conversational engine for a chatbot. We use the popular NLTK text classification library to achieve this.

Loan Eligibility Prediction using Gradient Boosting Classifier
This data science in python project predicts if a loan should be given to an applicant or not. We predict if the customer is eligible for loan based on several factors like credit score and past history.

Machine Learning or Predictive Models in IoT - Energy Prediction Use Case
In this machine learning and IoT project, we are going to test out the experimental data using various predictive models and train the models and break the energy usage.

Learn to prepare data for your next machine learning project
Text data requires special preparation before you can start using it for any machine learning project.In this ML project, you will learn about applying Machine Learning models to create classifiers and learn how to make sense of textual data.

Music Recommendation System Project using Python and R
Machine Learning Project - Work with KKBOX's Music Recommendation System dataset to build the best music recommendation engine.

Data Science Project-TalkingData AdTracking Fraud Detection
Machine Learning Project in R-Detect fraudulent click traffic for mobile app ads using R data science programming language.

PySpark Tutorial - Learn to use Apache Spark with Python
PySpark Project-Get a handle on using Python with Spark through this hands-on data processing spark python tutorial.

Predict Macro Economic Trends using Kaggle Financial Dataset
In this machine learning project, you will uncover the predictive value in an uncertain world by using various artificial intelligence, machine learning, advanced regression and feature transformation techniques.

Ensemble Machine Learning Project - All State Insurance Claims Severity Prediction
In this ensemble machine learning project, we will predict what kind of claims an insurance company will get. This is implemented in python using ensemble machine learning algorithms.

Walmart Sales Forecasting Data Science Project
Data Science Project in R-Predict the sales for each department using historical markdown data from the Walmart dataset containing data of 45 Walmart stores.