IA_training module#

The EntrainementIA algorithm is designed to train an artificial neural network, specifically a Multi-Layer Perceptron (MLP), using the preprocessed databases.

Features

The algorithm begins by importing the preprocessed databases, which contain data in the form required for training the MLP. These databases include different shapes such as squares, circles, triangles, pentagons, and stars. The data from each shape is organized and combined into a single dataset.

Next, the algorithm sets up the training and testing data witch will be used to evaluate the trained model’s performance.

The MLP classifier is configured with specific hyperparameters, such as the number and size of hidden layers, activation function, learning rate, and optimization algorithm. These parameters can be adjusted to optimize the model’s performance.

The algorithm then proceeds to train the MLP model using the training data. During training, the MLP learns to classify the input images into their respective shape categories based on the provided target labels.

After training, the algorithm provides various information about the trained model. It displays the accuracy score, indicating how well the model performs on the testing data. The loss curve is also shown, which represents the training loss at each iteration, providing insights into the model’s convergence.

The algorithm includes additional functionalities, such as displaying individual images from the datasets, visualizing weight matrices of the trained model, and generating a confusion matrix to evaluate the model’s performance in detail.

Tip

The algorithm also provides the ability to save the trained model’s weights for future use. It also allows loading previously saved weights to set the MLP model’s parameters.

class IA_training.EntrainementIA[source]#

Bases: object

Class for training an artificial neural network (MLP) using the preprocessed databases.

x_train#

Input features for training.

Type:

ndarray

y_train#

Target labels for training.

Type:

ndarray

x_test#

Input features for testing.

Type:

ndarray

y_test#

Target labels for testing.

Type:

ndarray

mlp#

Multi-layer Perceptron classifier.

Type:

MLPClassifier

Fit()[source]#

Train the MLP model.

This method trains the MLP model using the configured training data and target labels.

Impoids()[source]#

Display weight matrices.

This method displays the weight matrices of the trained model.

__init__()[source]#

Initialize the EntrainementIA class.

This method imports the preprocessed databases, sets up the training and testing data, configures the MLP classifier, and performs the training.

Warning

  • The preprocessed databases should be stored in CSV files with specific filenames.

  • The MLP classifier hyperparameters can be adjusted within the method.

afficheinfo()[source]#

Display information about the trained model.

This method displays the accuracy score and loss curve of the trained model.

matconf()[source]#

Display the confusion matrix.

This method displays the confusion matrix of the trained model.

montreimage(k, set)[source]#

Display the k-th image from the specified dataset.

Parameters:
  • k (int) – Index of the image to display.

  • set (ndarray) – Dataset to retrieve the image from.

Returns:

Always returns 0.

Return type:

int

sauvgarde()[source]#

Save the trained model’s weights.

This method saves the weight matrices and biases of the trained model.

setparam()[source]#

Set the weights of the MLP model to previously saved weights.

This method sets the weight matrices and biases of the MLP model to previously saved weights.