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

Time Series Forecasting with LSTM Neural Network Python
Deep Learning Project- Learn to apply deep learning paradigm to forecast univariate time series data.

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.

Perform Time series modelling using Facebook Prophet
In this project, we are going to talk about Time Series Forecasting to predict the electricity requirement for a particular house using Prophet.

Customer Market Basket Analysis using Apriori and Fpgrowth algorithms
In this data science project, you will learn how to perform market basket analysis with the application of Apriori and FP growth algorithms based on the concept of association rule learning.

Sequence Classification with LSTM RNN in Python with Keras
In this project, we are going to work on Sequence to Sequence Prediction using IMDB Movie Review Dataset​ using Keras in Python.

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.

Resume parsing with Machine learning - NLP with Python OCR and Spacy
In this machine learning resume parser example we use the popular Spacy NLP python library for OCR and text classification.

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.

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.

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.