What is the Sklearn Standardscaler() function

Asked

Viewed 1,113 times

0

The code below found in the link Classifying the Iris Data Set with Keras. And I’d like to understand the usefulness of Standardscaler(), says it is important for convergence?

from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import OneHotEncoder, StandardScaler

iris = load_iris()
X = iris['data']
y = iris['target']
names = iris['target_names']
feature_names = iris['feature_names']

# One hot encoding
enc = OneHotEncoder()
Y = enc.fit_transform(y[:, np.newaxis]).toarray()

# Scale data to have mean 0 and variance 1 
# which is importance for convergence of the neural network
scaler = StandardScaler()
X_scaled = scaler.fit_transform(X)

# Split the data set into training and testing
X_train, X_test, Y_train, Y_test = train_test_split(
    X_scaled, Y, test_size=0.5, random_state=2)

n_features = X.shape[1]
n_classes = Y.shape[1]

1 answer

1


Standardscalerque implements the Transformerapi to calculate the mean and standard deviation in a training set, so that it can later reapply the same transformation in the test set. Therefore, this class is suitable for use in the initial steps of a sklearn.pipeline.Pipeline you can read all the documentation of this library on this website: https://scikit-learn.org/stable/modules/preprocessing.html

Browser other questions tagged

You are not signed in. Login or sign up in order to post.