-
-
Save ashwinprasadme/1858bdf449c73089aa22904e4e2556e8 to your computer and use it in GitHub Desktop.
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
def normalize_data(df): | |
min_max_scaler = sklearn.preprocessing.MinMaxScaler() | |
df['open'] = min_max_scaler.fit_transform(df.open.values.reshape(-1,1)) | |
df['high'] = min_max_scaler.fit_transform(df.high.values.reshape(-1,1)) | |
df['low'] = min_max_scaler.fit_transform(df.low.values.reshape(-1,1)) | |
df['close'] = min_max_scaler.fit_transform(df['close'].values.reshape(-1,1)) | |
return df |
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
data = np.array(y) | |
scaler = MinMaxScaler(feature_range=(-1, 1)) | |
train_data_normalized = scaler.fit_transform(data.reshape(-1, 1)) |
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
## * Note: I scale all features in range of [0,1]. | |
## If you would like to train based on the resampled data (over hour), then used below | |
values = df_resample.values | |
## full data without resampling | |
#values = df.values | |
# integer encode direction | |
# ensure all data is float | |
#values = values.astype('float32') | |
# normalize features | |
scaler = MinMaxScaler(feature_range=(0, 1)) | |
scaled = scaler.fit_transform(values) | |
# frame as supervised learning | |
reframed = series_to_supervised(scaled, 1, 1) | |
# drop columns we don't want to predict | |
reframed.drop(reframed.columns[[8,9,10,11,12,13]], axis=1, inplace=True) | |
print(reframed.head()) |
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
wltw_stock_prices=wltw_stock_prices.reshape(-1, 1) | |
scaler = MinMaxScaler(feature_range=(0, 1)) | |
wltw_stock_prices = scaler.fit_transform(wltw_stock_prices) |
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
def normalize_data(df): | |
min_max_scaler = preprocessing.MinMaxScaler() | |
df['open'] = min_max_scaler.fit_transform(df.open.values.reshape(-1,1)) | |
df['high'] = min_max_scaler.fit_transform(df.high.values.reshape(-1,1)) | |
df['low'] = min_max_scaler.fit_transform(df.low.values.reshape(-1,1)) | |
df['volume'] = min_max_scaler.fit_transform(df.volume.values.reshape(-1,1)) | |
df['adj close'] = min_max_scaler.fit_transform(df['adj close'].values.reshape(-1,1)) | |
return df | |
df = normalize_data(df) |
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
train = train.sort_values('visit_date') | |
values = np.log1p(train['visitors'].values).reshape(-1,1) | |
values = values.astype('float32') | |
scaler = MinMaxScaler(feature_range=(0, 1)) | |
scaled = scaler.fit_transform(values) |
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
# Scaling the training set | |
sc = MinMaxScaler(feature_range=(0,1)) | |
training_set_scaled = sc.fit_transform(training_set) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment