How to rescale features in Python?
DATA MUNGING DATA CLEANING PYTHON MACHINE LEARNING RECIPES PANDAS CHEATSHEET     ALL TAGS

How to rescale features in Python?

How to rescale features in Python?

This recipe helps you rescale features in Python

2

Recipe Objective

In a dataset there may be many outliers which effects the performance of the model. We can deal with it by scaling the data. Here we will be using min-max scaler for this.

So this is the recipe on how we can can rescale features in Python.

Step 1 - Importing Library

from sklearn import preprocessing import numpy as np

We have imported numpy and preprocessing which is needed.

Step 2 - Creating array

We have created a array with values on which we will perform operation. x = np.array([[-500.5], [-100.1], [0], [100.1], [900.9]])

Step 3 - Scaling the array

We have used min-max scaler to scale the data in the array in the range 0 to 1 which we have passed in the parameter. Then we have used fit transform to fit and transform the array according to the min max scaler. minmax_scale = preprocessing.MinMaxScaler(feature_range=(0, 1)) x_scale = minmax_scale.fit_transform(x) print(x) print(x_scale) So the output comes as

[[-500.5]
 [-100.1]
 [   0. ]
 [ 100.1]
 [ 900.9]]

[[0.        ]
 [0.28571429]
 [0.35714286]
 [0.42857143]
 [1.        ]]

Relevant Projects

Solving Multiple Classification use cases Using H2O
In this project, we are going to talk about H2O and functionality in terms of building Machine Learning models.

Predict Churn for a Telecom company using Logistic Regression
Machine Learning Project in R- Predict the customer churn of telecom sector and find out the key drivers that lead to churn. Learn how the logistic regression model using R can be used to identify the customer churn in telecom dataset.

Human Activity Recognition Using Multiclass Classification in Python
In this human activity recognition project, we use multiclass classification machine learning techniques to analyse fitness dataset from a smartphone tracker.

Topic modelling using Kmeans clustering to group customer reviews
In this Kmeans clustering machine learning project, you will perform topic modelling in order to group customer reviews based on recurring patterns.

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.

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.

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.

Mercari Price Suggestion Challenge Data Science Project
Data Science Project in Python- Build a machine learning algorithm that automatically suggests the right product prices.

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.

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.