Created
August 1, 2022 17:12
-
-
Save amindadgar/dabf25692d43f83a1cd196e85d804731 to your computer and use it in GitHub Desktop.
A simple program to evaluate the zero mean scaling using Sklearn library and manually
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.preprocessing import StandardScaler | |
def find_manually(data, mean, var): | |
""" | |
scale the data manually using mean(`mean`) and variance (`var`) | |
""" | |
return (data - mean) / var | |
def start_program(): | |
""" | |
Start the process of the program | |
""" | |
data = [[0, 0], [0, 0], [1, 1], [1, 1]] | |
scaler = StandardScaler() | |
data_scaled = scaler.fit_transform(data) | |
print(f'Original data: {data}') | |
print(f'Scaled Original data: {data_scaled}') | |
print(f'mean: {scaler.mean_}, variance: {scaler.var_}') | |
print('-'* 50) | |
data_new = [[2, 2]] | |
print(f'new data: {data_new}, the new data scaled using sklearn: {scaler.transform(data_new)}') | |
print(f'new data: {data_new}, the new data scaled manually: {find_manually(data_new, scaler.mean_, scaler.var_)}') | |
if __name__ == '__main__': | |
start_program() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment