Neural Network Classification Class

class MLP_Classifier.NN_Classifier(df, NN_Inputs, dependant_var_index)

Neural Network Classifier Class:

This Class contains the methods used for Neural Network Classification using MLP Classifier from sklearn library

Class input parameters:

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

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

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

Class Output Parameters:

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

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

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

  • Train_score (float) – Model Score (Accuracy) on the Training data

  • test_score (float) – Model Score (Accuracy) on the Testing data

  • model (MLPClassifier) – The MLP Classifier 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

Classify()

Classifier Creation Method:

In this method 3 different steps are done:

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

  2. The extracted Train data is resampled (or not) based on the user input Normalize flag from the NN_Inputs parameter.

  3. Model is fitted on the resampled/normal data and returns some metrics for the performance of the model on the test and train data sets.

Returns

Modified set of class parameters

Conf()

Creation of Confusion matrix:

This method outputs a confusion matrix figure to show the quality of the classification on the test data.

The Confusion matrix dimensions and Labels are derived from the number and names of the different unique values in the Labels Target column for the classification.

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 “Classify” method

handle2(df)

Data Handling Method Version 2:

This method takes the Target column index and splits the data into X and Y numpy arrays for internal use

This method is used internally by the “Classify” method after the data is resampled and reshuffled, it takes input dataframe and returns the X and Y arrays to the caller

Parameters

df (Pandas DataFrame) – the Data frame passed to handle

Returns

X,Y

Return type

numpy arrays

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 Accuracy on the Training Data

  2. Model Accuracy on the Testing Data

  3. Length of the output array

  4. Classification Report