Skip to main content

Graphing

Function Signature

def graph(self, metric: str = "cost") -> None:

Parameters

  • metric (str, optional): The metric to plot. Default is "cost". Valid metrics are "cost", "acc", or "accuracy", and "error".

Return Value

  • None

Description

The graph function uses matplotlib to plot the change of the specified metric over the epochs. It should be called after training the network.

Examples

Here's an example of how to use the graph function:

from deeprai.models import FeedForward

model = FeedForward()
model.add_dense(784)
model.add_dense(128, activation='relu')
model.add_dense(64, activation='relu')
model.add_dense(10, activation='softmax')
model.config(optimizer='gradient descent', loss='mean square error')

train_inputs, train_targets, test_inputs, test_targets = # load data

model.train_model(train_inputs, train_targets, test_inputs, test_targets)

model.graph(metric='accuracy')

This code creates a FeedForward model with a single dense layer of size 784, followed by two additional dense layers with ReLU activation functions, and a final dense layer with a softmax activation function. The config function sets the optimizer to gradient descent and the loss function to mean square error.

The train_model function trains the model on the loaded data. After training, the graph function is called with the "accuracy" metric to plot the accuracy over the epochs.

The output should be a plot of the specified metric over the epochs.