Last active
January 11, 2018 17:51
-
-
Save DylanModesitt/3c488b4ef96fa285d2bb078e3d5d1c17 to your computer and use it in GitHub Desktop.
Scale the data to have no mean and variance 1, then split that data into training and validation without implicit bias
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 standardize_data(data, training_validation_split=0.2): | |
""" | |
standardize features by removing the mean and scaling to unit variance | |
:param data: the data desired to be scaled | |
:param training_validation_split: The percentage of data to save for validation | |
:return: the standardized features and scalar in the form (training, validation, scalar) | |
""" | |
np.random.shuffle(data) | |
split = int(data.shape[0]*(1 - training_validation_split)) | |
training, validation = data[:split, :], data[split:, :] | |
scalar = StandardScaler() | |
scalar.fit(training) | |
return (scalar.transform(training), scalar.transform(validation), scalar) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment