How to standardise features in Python?

How to standardise features in Python?

How to standardise features in Python?

This recipe helps you standardise features in Python


Recipe Objective

It is very rare to find a raw dataset which perfectly follows certain specific distribution. Usually every dataset needs to be standarize by any means.

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

Step 1 - Import the library

from sklearn import preprocessing import numpy as np

We have only imported numpy and preprocessing which is needed.

Step 2 - Setting up the Data

We have created an numpy array with different values. x = np.array([[-500.5], [-100.1], [0], [100.1], [900.9]])

Step 3 - Using StandardScaler

StandardScaler is used to remove the outliners and scale the data by making the mean of the data 0 and standard deviation as 1. So we are creating an object scaler to use standardScaler.
We have fitted the fit data and transformed train and test data form standard scaler. Finally we have printed the dataset. scaler = preprocessing.StandardScaler() standardized_x = scaler.fit_transform(x) print(x) print(standardized_x) As an output we get

 [   0. ]
 [ 100.1]
 [ 900.9]]

 [ 0.0436852 ]
 [ 1.79109332]]

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.

Predict Credit Default | Give Me Some Credit Kaggle
In this data science project, you will predict borrowers chance of defaulting on credit loans by building a credit score prediction model.

Zillow’s Home Value Prediction (Zestimate)
Data Science Project in R -Build a machine learning algorithm to predict the future sale prices of homes.

Predict Census Income using Deep Learning Models
In this project, we are going to work on Deep Learning using H2O to predict Census income.

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.

Predict Employee Computer Access Needs in Python
Data Science Project in Python- Given his or her job role, predict employee access needs using amazon employee database.

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.

Data Science Project on Wine Quality Prediction in R
In this R data science project, we will explore wine dataset to assess red wine quality. The objective of this data science project is to explore which chemical properties will influence the quality of red wines.

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.