# Unraveling the Impact of Class Imbalance on Deep-Learning Models for Medical Image Classification
## 2 Materials and Methods
### R Packages for Artificial Intelligence  
In this subsection, the R packages used to build and analyze classification models based on artificial and deep neural networks using a dataset of lung pathology images are presented. Among these packages, RSNNS, Neuralnet, and Keras provide valid results, while Deepnet and nnet do not yield valid results. The algorithms for all defined neural networks undergo exploration to determine the number of neurons per layer in topologies ranging from 1 to 4 layers. Some of the hyperparameters are kept at their default values. For further information on the packages, please refer to [43; 44]. * RSNNS: This package, based on the Stuttgart Neural Network Simulator (SNNS), offers both high-level and low-level APIs in C++. The low-level interface provides access to full functionality and flexibility, while the high-level interface implements common neural network topologies and learning algorithms [45]. In this work, a multilayer perceptron network trained with backpropagation is created. Logistic and identity activation functions are used in the hidden and output layers, respectively. For the processed dataset, in most cases, training is limited to a maximum of 200 epochs. The built-in \"predict\" function is used to compute accuracy after training completion. Weight initialization ranges from \(-0.3\) to \(0.3\), and the weight update function is set to \"Topological_Order\" with a learning-rate parameter of 0.2. Figure 4: General architecture of a CNN. Figure 3: Variables associated with the pixels of an image as input in artificial neural networks. * Neuralnet: This package provides neural network training using backpropagation, allowing for adjustments in weights, neurons, layers, epochs, learning algorithms, activation functions, error functions, and other hyperparameters [46]. Hyperparameters like \"threshold\" = 10, \"stepmax\" = 1000, \"linear.output\" = TRUE, \"lifesign\" = \"minimal\", and \"act.fct\" = \"logistic\" are adjusted in this network. Various values for \"threshold\" and \"stepmax\" were tested to find optimal settings for faster training, as the algorithm's performance tends to slow down during training. Similar to RSNNS, no more than 200 training epochs are allowed for the processed dataset in most cases. * Deepnet: This package allows for the implementation of various deep-learning architectures and neural network algorithms [47]. However, it did not yield valid results for the implemented DBN network with the dataset used in this study. In spite of adjusting parameters such as learning rate and momentum, this package was unable to handle images with high dimensionality. Alternative experiments with reduced image dimensionality demonstrated its functionality, but the results could not be compared with those of other packages used in this research due to their lack of validity. * Keras: It is a high-level API based on TensorFlow, allowing for rapid development of machine learning models and artificial neural networks, including deep neural networks, within the \(R\) environment [48]. In this study, two types of networks were implemented using this package: an artificial neural network and a convolutional neural network (CNN). The artificial neural network comprises dense layers with ReLU activation, followed by a dropout layer to prevent overfitting, and a dense output layer with SoftMax activation for multi-class classification. It is compiled with categorical cross-entropy loss, RMSprop optimizer, and accuracy metrics. Training runs for up to 3000 epochs with a batch size of 128 and a 20% validation split. The CNN includes 2D convolutional layers with 32 filters and ReLU activation, each followed by a dropout layer with a 20% dropout rate. Additionally, it incorporates two more 2D convolutional layers with 64 and 128 filters, respectively, and ReLU activation, each followed by a dropout layer.