Learning

Here is a list of classes in the package.

Overview:

class neural_network.AbstractLearner(network: Network, data: DataFrame, batch_size: int, weighted: bool = False, bins: int = 10)[source]

Base class for trainer, tester and validator

__init__(network: Network, data: DataFrame, batch_size: int, weighted: bool = False, bins: int = 10)[source]

Constructor method

Parameters:
  • network (Network) – The neural network to train

  • data (pd.DataFrame) – All the data for the Network

  • batch_size (int) – The number of datapoints used in each epoch

  • weighted (bool) – If True then we use the WeightedPartitioner, otherwise we use the standard Partitioner

  • bins (int) – If weighted is True and regression is True, then we need to specify the number of bins for the weighted partitioner

_update_categorical_dataframe()[source]

Update the categorical dataframe with y_hat data but using the original categories from the data - to be used for plotting and outputs to the user. Note that this method will be called after training/testing/validation is complete so that the y_hat values are fully updated.

abs_comparison_scatter(phase: str = 'training', title: str = '')[source]

Creates scatter plot comparing the predicted and actual values in a regressional problem. Cannot be called with classification problems

Parameters:
  • phase (str) – The phase of learning

  • title (str) – An optional title to append to the plot

abs_generate_scatter(phase: str = 'training', title: str = '')[source]

Creates scatter plot from the data and their predicted values. For classification, we use the categories the user provided with the data instead of arbitrary integer classes.

Parameters:
  • phase (str) – The phase of learning

  • title (str) – An optional title to append to the plot

forward_pass_one_batch(batch_ids: List[int]) float[source]

Performs the forward pass for one batch of the data.

Parameters:

batch_ids (List[int]) – The random list of ids for the current batch

Returns:

The total loss of the batch (to keep track)

Return type:

float

run()[source]

Performs training/validation/testing

store_gradients(batch_id: int)[source]

To be overridden by subclasses.

Parameters:

batch_id (id of the current batch) –

class neural_network.Plotter[source]

Class to track progress of training/testing

static comparison_scatter(df: DataFrame, phase: str = 'training', title: str = '')[source]

Creates a scatter plot comparing the true and predicted values from the network.

Parameters:
  • df (pd.DataFrame) – The data

  • phase (str) – The phase of learning (training/validation/testing)

  • title (str) – The title

static datapoint_scatter(df: DataFrame, phase: str = 'training', title: str = '', regression: bool = False)[source]

Creates a scatter plot of the predicted/true classes for a given set of data.

Parameters:
  • df (pd.DataFrame) – The data

  • phase (str) – The phase of learning (training/validation/testing) or true for just the true data

  • title (str) – The title

  • regression (bool) – Whether this is for regressional data or classificational data

static plot_loss(df: DataFrame, title: str = '')[source]

Plots (normally) the training and validation losses over time.

Parameters df : pd.DataFrame

The data

class neural_network.Tester(network: Network, data: DataFrame, batch_size: int, weighted: bool = False)[source]

Class to test a neural network.

__init__(network: Network, data: DataFrame, batch_size: int, weighted: bool = False)[source]

Constructor method

Parameters:
  • network (Network) – The neural network

  • data (pd.DataFrame) – All the testing data for the Network

  • batch_size (int) – The number of datapoints used in each epoch

  • weighted (bool) – If True then we use the WeightedPartitioner, otherwise we use the standard Partitioner

comparison_scatter(title: str = '')[source]

Creates scatter plot comparing predicted to actual values (for regressional problems only).

Parameters:

title (str) – An optional title to append to the plot

generate_confusion()[source]

Creates a confusion matrix from the results.

generate_scatter(title: str = '')[source]

Creates scatter plot from the data and their predicted values.

Parameters:

title (str) – An optional title to append to the plot

run()[source]

Performs testing of the network.

class neural_network.Trainer(network: Network, data: DataFrame, num_epochs: int, batch_size: int, validator: Validator | None = None, weighted: bool = False)[source]

Class to train a neural network

__init__(network: Network, data: DataFrame, num_epochs: int, batch_size: int, validator: Validator | None = None, weighted: bool = False)[source]

Constructor method

Parameters:
  • network (Network) – The neural network to train

  • data (pd.DataFrame) – All the training data for the Network

  • num_epochs (int) – The number of epochs we are training for

  • batch_size (int) – The number of datapoints used in each epoch

  • validator (Validator) – The validator used (if any)

  • weighted (bool) – If True then we use the WeightedPartitioner, otherwise we use the standard Partitioner

back_propagate_one_batch()[source]

Performs back propagation for one batch of datapoints (stored within the memory of the edges).

comparison_scatter(title: str = '')[source]

Creates scatter plot comparing predicted to actual values (for regressional problems only).

Parameters:

title (str) – An optional title to append to the plot

generate_loss_plot(title: str = '')[source]

Creates a plot of the training and validation loss over time.

Parameters:

title (str) – An optional title to append to the plot

generate_scatter(title: str = '')[source]

Creates scatter plot from the data and their predicted values.

Parameters:

title (str) – An optional title to append to the plot

run()[source]

Performs training of the network

store_gradients(_id: int)[source]

Stores the gradients of the loss functions after a forward pass

Parameters:

_id (int) – The id of the datapoint

class neural_network.Validator(network: Network, data: DataFrame, batch_size: int, weighted: bool = False)[source]

Class to validate a neural network

__init__(network: Network, data: DataFrame, batch_size: int, weighted: bool = False)[source]

Constructor method

Parameters:
  • network (Network) – The neural network

  • data (pd.DataFrame) – All the validation data for the Network

  • batch_size (int) – The number of datapoints used in each epoch

  • weighted (bool) – If True then we use the WeightedPartitioner, otherwise we use the standard Partitioner

comparison_scatter(title: str = '')[source]

Creates scatter plot comparing predicted to actual values (for regressional problems only).

Parameters:

title (str) – An optional title to append to the plot

generate_scatter(title: str = '')[source]

Creates scatter plot from the data and their predicted values

Parameters:

title (str) – An optional title to append to the plot

validate(factor: int)[source]

Performs validation of the network.

Parameters:

factor (int) – The epochs on which we need to print out the validation