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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.179.85