Skip to Content
Deep Learning Quick Reference
book

Deep Learning Quick Reference

by Mike Bernico
March 2018
Intermediate to advanced
272 pages
7h 53m
English
Packt Publishing
Content preview from Deep Learning Quick Reference

Scaling a time series

We will use MinMaxScaler in this example to scale each difference data point into a scale with a minimum value of -1 and a maximum value of 1. This will put our data on the same scale as the hyperbolic tangent function (tanh), which is our activation function for the problem. We will use the following code for scaling the series:

def scale_data(df, scaler=None):    scaled_df = pd.DataFrame(index=df.index)    if not scaler:        scaler = MinMaxScaler(feature_range=(-1,1))    scaled_df["Price"] = scaler.fit_transform(df.Close.values.reshape(-1,1))    return scaler, scaled_df

Note that this function can optionally take a scaler that's already been fit. This allows us to apply our train scalers on our test set.

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Keras Deep Learning Cookbook

Keras Deep Learning Cookbook

Rajdeep Dua, Sujit Pal, Manpreet Singh Ghotra
Deep Learning with Keras

Deep Learning with Keras

Antonio Gulli, Sujit Pal

Publisher Resources

ISBN: 9781788837996Supplemental Content