Neural Network Regression Class

class MLP_Regressor.NN_Regressor(df, NN_Inputs, dependant_var_index)

Neural Network Regressor Class:

This Class contains the methods used for Neural Network Regression using MLP Regressor from sklearn library

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

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

  • 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.

It then 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

handle()

Data Handling Method:

This method takes the Target column index and splits the data frame “df” into X and Y numpy arrays so they are ready for being split into train and test sets.

This method is called internally once the class instance is created and the X,Y output arrays are fed to the “Regressor” method.

plotting()

Plotting Method:

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

preprocess()

Method Used to Normalize the X data if the user required

This method is called when the class instance is created and the Normalize flag in the input NN_Inputs tuple is True.

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