Skip to content

Instantly share code, notes, and snippets.

@ashwinprasadme
Last active January 11, 2021 11:08
Show Gist options
  • Save ashwinprasadme/1858bdf449c73089aa22904e4e2556e8 to your computer and use it in GitHub Desktop.
Save ashwinprasadme/1858bdf449c73089aa22904e4e2556e8 to your computer and use it in GitHub Desktop.
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
data = np.array(y)
scaler = MinMaxScaler(feature_range=(-1, 1))
train_data_normalized = scaler.fit_transform(data.reshape(-1, 1))
## * 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())
wltw_stock_prices=wltw_stock_prices.reshape(-1, 1)
scaler = MinMaxScaler(feature_range=(0, 1))
wltw_stock_prices = scaler.fit_transform(wltw_stock_prices)
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)
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)
# 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