3 Upvotes

Scale Data Using Standard Scaler in Sklearn

Python
Data Preparation for Models

from sklearn.preprocessing import StandardScaler

#Initalise standard scaler
scaler = StandardScaler()

#Fit the scaler using X_train data
scaler.fit(X_train)

#Transform X_train and X_test using the scaler and convert back to DataFrame
X_train = pd.DataFrame(scaler.transform(X_train), columns = X_train.columns)
X_test = pd.DataFrame(scaler.transform(X_test), columns = X_test.columns)

By analyseup - Last Updated Jan. 12, 2022, 12:36 a.m.

Did you find this snippet useful?

Sign up to bookmark this in your snippet library

COMMENTS
RELATED SNIPPETS
Create Dummy Variables with Pandas
Python
Data Preparation for Models

Pandas

1
Top Contributors
75