Time Series Neural Network Regression Class

class MLP_TimeSeries.NN_TimeSeries_Reg(df, NN_Inputs, dependant_var_index, time_index)

Neural Network Time Series Regressor Class:

This Class contains the methods used for Neural Network Regression using MLP Regressor for Timeseries data

Class input parameters:

Parameters
  • df (Pandas DataFrame) – The input data frame

  • NN_Inputs (Named Tuple) – Tuple of parameters for the Regressor clarified by the user

  • dependant_var_index (int) – The index of the target column in the df for the Regression

  • time_index (int) – The index of the column with timeseries data in the df

Class Output Parameters:

Parameters
  • y_pred (float) – The resulting output of the Regression test

  • y_actual (float) – The expected output of the Regression test

  • length (int) – The length of the output of the Regression test set

  • mean_squared_error (float) – The MSE of the y_pred with respect to the y_actual

  • Train_score (float) – Model Score (R^2) on the Training data

  • test_score (float) – Model Score (R^2) on the Testing data

  • model (MLPRegressor) – The MLP Regressor model created using the specified inputs

  • group_object (dataframe) – Output array of the list of unique values in a specified column for grouping

  • Error_message (str) – Error message if an exception was encountered during the processing of the code

  • flag (bool) – internal flag for marking if an error occurred while processing a previous method

Regressor()

Regressor Creation Method:

This method splits the data into train and test sets, then creates the MLP regressor based on the user inputs from NN_Inputs Named Tuple.

The data is Normalized using MinMaxScaler() and then the method fits the model and returns some metrics for the performance of the model on the test and train data sets.

Returns

Modified set of class parameters

features()

Extracting features method: This method deals with Internal_df parameter in the Class, It extracts datetime information from datetime column into 6 separate columns for “Year,Month,Day,Hour,Minute,Second”.

This method is called internally in one of 2 separate places:
  1. During the Class Instance Creation if the user doesn’t wish to group data based on a specific value in a column.

  2. In the grouping method after the creation of the subset dataframe based on the specific group identifier if the grouping flag is True.

After these features are extracted the data is reshuffled and then split into X and Y dataframes with the X being the 6 columns including datetime information and the Y the target column for the regression.

The X,Y dataframes are then fed to the “Regressor” Method.

group(i)

Grouping method:

This method gets an index of the value the user wants to group the data on from the list of unique values created by the listing method, It then creates the dataframe subset with this group only for the regression to use.

Parameters

i (int) – index of the group identifier

listing(i)

Method for Creating unique values list:

This method takes a column index and outputs a dataframe with the list of unique values in this specific column in order for the user to choose a group to run the regression on.

Parameters

i (int) – Unique Values column index

plotting()

Plotting Method:

This method plots the scatter plot of the predicted vs Expected output to visualize the quality of the regression

printing()

Printing Outputs:

This method prints the chosen metrics to the user after the model is trained and fitted.

The metrics are:
  1. Model R2 Score on the Training Data

  2. Model R2 Score on the Testing Data

  3. Length of the output array

  4. Root Mean Squared Error