Title: Standardize A Feature
Slug: standardize_a_feature
Summary: How to standardize a feature for machine learning in Python.
Date: 2016-09-06 12:00
Category: Machine Learning
Tags: Preprocessing Structured Data
Authors: Chris Albon
In [1]:
# Load libraries
from sklearn import preprocessing
import numpy as np
In [2]:
# Create feature
x = np.array([[-500.5],
[-100.1],
[0],
[100.1],
[900.9]])
In [3]:
# Create scaler
scaler = preprocessing.StandardScaler()
# Transform the feature
standardized = scaler.fit_transform(x)
# Show feature
standardized
Out[3]: