DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
The Latest "Software Integration: The Intersection of APIs, Microservices, and Cloud-Based Systems" Trend Report
Get the report
  1. DZone
  2. Data Engineering
  3. Data
  4. Data Normalization 101: MinMaxScalar

Data Normalization 101: MinMaxScalar

In this post, we take a look at how to better work with big data sets by using data normalization techniques in Python using the sklearn library.

Matt Hughes user avatar by
Matt Hughes
·
Aug. 27, 18 · Tutorial
Like (2)
Save
Tweet
Share
6.32K Views

Join the DZone community and get the full member experience.

Join For Free

As a part of any data cleanup process you’re probably going to want to normalize your data.

Image title

Like in golf, if you’re playing against Tiger Woods, you’ll want to give him a handicap, just so that he won’t totally blow you away and that the game might still be fun.

Also, with data, you may want all things equal.  

Assume you’re trying to compare the height of a building and it’s internal temperature.  The two different units are fine, except when you're trying to teach a machine about the data you may want the units to have some sort of equal measure (300 meters vs. 26 degrees. To us that makes sense, but the actual value of the digits is clearly incongruous).

There are many different ways of doing this. Personally I like the MinMaxScalar function in the sklearn package. First off, it gives you pretty straight-forward results (everything ends up being between 0 and 1), and, secondly, it's the only one I know how to use so far.

So take it or leave it, my pretties...

Let’s make a numpy array. Here are 6 tuples of fictional height/temperature data:

buildingData = np.array([[300,24],[200,21],[126,18],[567,27],[420,19],[189,30]])
print (buildingData)

=

[[300  24]
 [200  21]
 [126  18]
 [567  27]
 [420  19]
 [189  30]]

As I said, we'll be using sklearn to do this stuff, so first you’ll need to import the MinMaxScalar function:

from sklearn.preprocessing import MinMaxScaler

Then we need to figure out the largest and smallest data point in your data set:

scaler_model = MinMaxScaler()
scaler_model.fit(buildingData)

Then scale the data appropriately:

scaled_data = scaler_model.transform(buildingData)

This will take the highest and lowest values in your data, turn them into 1 and 0 respectively, then stuff all the other values into relative numbers between 1 and zero.  So we get:

print (scaled_data)

=

[[ 0.39455782  0.5 ]
 [ 0.16780045  0.25 ]
 [ 0.          0. ]
 [ 1.          0.75 ]
 [ 0.66666667  0.08333333]
 [ 0.14285714  1. ]]

Voila, all of your data is (proportionately speaking) the same as it was before, but  reducing it into relative values between 0 and 1 will allow a machine to process it appropriately.

Data (computing)

Published at DZone with permission of Matt Hughes. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Building Microservice in Golang
  • Multi-Cloud Integration
  • Stop Using Spring Profiles Per Environment
  • Custom Validators in Quarkus

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: