# Ensemble Deep Learning

Referenced paper : __RMDL: Random Multimodel Deep Learning for Classification__
Referenced paper: __An Improvement of Data Classification Using Random Multimodel Deep Learning (RMDL)__

## Random Multimodel Deep Learning (RMDL):

A new ensemble, deep learning approach for classification. Deep learning models have achieved state-of-the-art results across many domains. RMDL solves the problem of finding the best deep learning structure and architecture while simultaneously improving robustness and accuracy through ensembles of deep learning architectures. RDML can accept as input a variety of data to include text, video, images, and symbolic. Random Multimodel Deep Learning (RDML) architecture for classification. RMDL includes 3 Random models, oneDNN classifier at left, one Deep CNN classifier at middle, and one Deep RNN classifier at right (each unit could be LSTMor GRU).

## Installation

There are pip and git for RMDL installation: Using pip

```
pip install RMDL
```

Using git

```
git clone --recursive
```__https://github.com/kk7nc/RMDL.git__

The primary requirements for this package are Python 3 with Tensorflow. The requirements.txt file contains a listing of the required Python packages; to install all requirements, run the following:

```
pip -r install requirements.txt
Or
pip3 install -r requirements.txt
Or:
conda install --file requirements.txt
```

Documentation: The exponential growth in the number of complex datasets every year requires more enhancement in machine learning methods to provide robust and accurate data classification. Lately, deep learning approaches have been achieved surpassing results in comparison to previous machine learning algorithms on tasks such as image classification, natural language processing, face recognition, and etc. The success of these deep learning algorithms relies on their capacity to model complex and non-linear relationships within data. However, finding a suitable structure for these models has been a challenge for researchers. This paper introduces Random Multimodel Deep Learning (RMDL): a new ensemble, deep learning approach for classification. RMDL solves the problem of finding the best deep learning structure and architecture while simultaneously improving robustness and accuracy through ensembles of deep learning architectures. In short, RMDL trains multiple models of Deep Neural Network (DNN), Convolutional Neural Network (CNN) and Recurrent Neural Network (RNN) in parallel and combines their results to produce a better result of any of those models individually. To create these models, each deep learning model has been constructed in a random fashion regarding the number of layers and nodes in their neural network structure. The resulting RDML model can be used for various domains such as text, video, images, and symbolic. In this Project, we describe RMDL model in depth and show the results for image and text classification as well as face recognition. For image classification, we compared our model with some of the available baselines using MNIST and CIFAR-10 datasets. Similarly, we used four datasets namely, WOS, Reuters, IMDB, and 20newsgroup and compared our results with available baselines. Web of Science (WOS) has been collected by authors and consists of three sets~(small, medium and large set). Lastly, we used ORL dataset to compare the performance of our approach with other face recognition methods. These test results show that RDML model consistently outperforms standard methods over a broad range of data types and classification problems.

## Datasets for RMDL:

### Text Datasets:

__IMDB Dataset__This dataset contains 50,000 documents with 2 categories.

__Reters-21578 Dataset__This dataset contains 21,578 documents with 90 categories.

__20Newsgroups Dataset__This dataset contains 20,000 documents with 20 categories.

Web of Science Dataset (DOI:

__10.17632/9rw3vkcfy4.2__)Web of Science Dataset

__WOS-11967__This dataset contains 11,967 documents with 35 categories which include 7 parents categories.

Web of Science Dataset

__WOS-46985__This dataset contains 46,985 documents with 134 categories which include 7 parents categories.

Web of Science Dataset

__WOS-5736__This dataset contains 5,736 documents with 11 categories which include 3 parents categories.

### Image datasets:

__MNIST Dataset__The MNIST database contains 60,000 training images and 10,000 testing images.

__CIFAR-10 Dataset__The CIFAR-10 dataset consists of 60000 32x32 colour images in 10 classes, with 6000 images per class. There are 50000 training images and 10000 test images.

Face Recognition
__The Database of Faces (The Olivetti Faces Dataset)__

The The Database of Faces dataset consists of 400 92x112 colour images and grayscale in 40 person

### Requirements for RMDL :

General:

Python 3.5 or later see

__Instruction Documents__TensorFlow see

__Instruction Documents__.scikit-learn see

__Instruction Documents__Keras see

__Instruction Documents__scipy see

__Instruction Documents__

### GPU (if you want to run on GPU):

CUDA® Toolkit 8.0. For details, see

__NVIDIA’s documentation__.The

__NVIDIA drivers associated with CUDA Toolkit 8.0__.cuDNN v6. For details, see

__NVIDIA’s documentation__.GPU card with CUDA Compute Capability 3.0 or higher.

The libcupti-dev library,

### Text and Document Classification

Download GloVe: Global Vectors for Word Representation

__Instruction Documents__Set data directory into

__Global.py__if you are not setting GloVe directory, GloVe will be downloaded

Parameters: Text_Classification from RMDL import RMDL_TextText_Classification(x_train, y_train, x_test, y_test, batch_size=128, EMBEDDING_DIM=50,MAX_SEQUENCE_LENGTH = 500, MAX_NB_WORDS = 75000, GloVe_dir="", GloVe_file = "glove.6B.50d.txt", sparse_categorical=True, random_deep=[3, 3, 3], epochs=[500, 500, 500], plot=True, min_hidden_layer_dnn=1, max_hidden_layer_dnn=8, min_nodes_dnn=128, max_nodes_dnn=1024, min_hidden_layer_rnn=1, max_hidden_layer_rnn=5, min_nodes_rnn=32, max_nodes_rnn=128, min_hidden_layer_cnn=3, max_hidden_layer_cnn=10, min_nodes_cnn=128, max_nodes_cnn=512, random_state=42, random_optimizor=True, dropout=0.05): Input

x_train

y_train

x_test

y_test

batch_size

batch_size: Integer. The number of samples per gradient update. If unspecified, it will default to 128.

EMBEDDING_DIM

batch_size: Integer. The shape of word embedding (this number should be same with GloVe or other pre-trained embedding techniques that be used), it will default to 50 that used with the pain of glove.6B.50d.txt file.

MAX_SEQUENCE_LENGTH

MAX_SEQUENCE_LENGTH: Integer. The maximum length of sequence or document in datasets, it will default to 500.

MAX_NB_WORDS

MAX_NB_WORDS: Integer. The maximum number of unique words in datasets, it will default to 75000.

GloVe_dir

GloVe_dir: String. Address of GloVe or any pre-trained directory, it will default to null which glove.6B.zip will be download.

GloVe_file

GloVe_dir: String. Which version of GloVe or pre-trained word emending will be used, it will default to glove.6B.50d.txt.

NOTE: if you use another version of GloVe EMBEDDING_DIM must be the same dimensions.

sparse_categorical

sparse_categorical: bool. When target’s dataset is (n,1) should be True, it will default to True.

random_deep

random_deep: Integer [3]. Number of ensembled model used in RMDL random_deep[0] is number of DNN, random_deep[1] is number of RNN, random_deep[0] is number of CNN, it will default to [3, 3, 3].

epochs

epochs: Integer [3]. Number of epochs in each ensembled model used in RMDL epochs[0] is number of epochs used in DNN, epochs[1] is number of epochs used in RNN, epochs[0] is number of epochs used in CNN, it will default to [500, 500, 500].

plot

plot: bool. True: shows confusion matrix and accuracy and loss

min_hidden_layer_dnn

min_hidden_layer_dnn: Integer. Lower Bounds of hidden layers of DNN used in RMDL, it will default to 1.

max_hidden_layer_dnn

max_hidden_layer_dnn: Integer. Upper bounds of hidden layers of DNN used in RMDL, it will default to 8.

min_nodes_dnn

min_nodes_dnn: Integer. Lower bounds of nodes in each layer of DNN used in RMDL, it will default to 128.

max_nodes_dnn

max_nodes_dnn: Integer. Upper bounds of nodes in each layer of DNN used in RMDL, it will default to 1024.

min_hidden_layer_rnn

min_hidden_layer_rnn: Integer. Lower Bounds of hidden layers of RNN used in RMDL, it will default to 1.

max_hidden_layer_rnn

man_hidden_layer_rnn: Integer. Upper Bounds of hidden layers of RNN used in RMDL, it will default to 5.

min_nodes_rnn

min_nodes_rnn: Integer. Lower bounds of nodes (LSTM or GRU) in each layer of RNN used in RMDL, it will default to 32.

max_nodes_rnn

max_nodes_rnn: Integer. Upper bounds of nodes (LSTM or GRU) in each layer of RNN used in RMDL, it will default to 128.

min_hidden_layer_cnn

min_hidden_layer_cnn: Integer. Lower Bounds of hidden layers of CNN used in RMDL, it will default to 3.

max_hidden_layer_cnn

max_hidden_layer_cnn: Integer. Upper Bounds of hidden layers of CNN used in RMDL, it will default to 10.

min_nodes_cnn

min_nodes_cnn: Integer. Lower bounds of nodes (2D convolution layer) in each layer of CNN used in RMDL, it will default to 128.

max_nodes_cnn

min_nodes_cnn: Integer. Upper bounds of nodes (2D convolution layer) in each layer of CNN used in RMDL, it will default to 512.

random_state

random_state : Integer, RandomState instance or None, optional (default=None)

If Integer, random_state is the seed used by the random number generator;

random_optimizor

random_optimizor : bool, If False, all models use adam optimizer. If True, all models use random optimizers. it will default to True

dropout

dropout: Float between 0 and 1. Fraction of the units to drop for the linear transformation of the inputs.

Image_Classification from RMDL import RMDL_ImageImage_Classification(x_train, y_train, x_test, y_test, shape, batch_size=128, sparse_categorical=True, random_deep=[3, 3, 3], epochs=[500, 500, 500], plot=True, min_hidden_layer_dnn=1, max_hidden_layer_dnn=8, min_nodes_dnn=128, max_nodes_dnn=1024, min_hidden_layer_rnn=1, max_hidden_layer_rnn=5, min_nodes_rnn=32, max_nodes_rnn=128, min_hidden_layer_cnn=3, max_hidden_layer_cnn=10, min_nodes_cnn=128, max_nodes_cnn=512, random_state=42, random_optimizor=True, dropout=0.05) Input

x_train

y_train

x_test

y_test

shape

shape: np.shape . shape of image. The most common situation would be a 2D input with shape (batch_size, input_dim).

batch_size

batch_size: Integer. Number of samples per gradient update. If unspecified, it will default to 128.

sparse_categorical

sparse_categorical: bool. When target’s dataset is (n,1) should be True, it will default to True.

random_deep

random_deep: Integer [3]. Number of ensembled model used in RMDL random_deep[0] is number of DNN, random_deep[1] is number of RNN, random_deep[0] is number of CNN, it will default to [3, 3, 3].

epochs

epochs: Integer [3]. Number of epochs in each ensembled model used in RMDL epochs[0] is number of epochs used in DNN, epochs[1] is number of epochs used in RNN, epochs[0] is number of epochs used in CNN, it will default to [500, 500, 500].

plot

plot: bool. True: shows confusion matrix and accuracy and loss

min_hidden_layer_dnn

min_hidden_layer_dnn: Integer. Lower Bounds of hidden layers of DNN used in RMDL, it will default to 1.

max_hidden_layer_dnn

max_hidden_layer_dnn: Integer. Upper bounds of hidden layers of DNN used in RMDL, it will default to 8.

min_nodes_dnn

min_nodes_dnn: Integer. Lower bounds of nodes in each layer of DNN used in RMDL, it will default to 128.

max_nodes_dnn

max_nodes_dnn: Integer. Upper bounds of nodes in each layer of DNN used in RMDL, it will default to 1024.

min_nodes_rnn

min_nodes_rnn: Integer. Lower bounds of nodes (LSTM or GRU) in each layer of RNN used in RMDL, it will default to 32.

max_nodes_rnn

maz_nodes_rnn: Integer. Upper bounds of nodes (LSTM or GRU) in each layer of RNN used in RMDL, it will default to 128.

min_hidden_layer_cnn

min_hidden_layer_cnn: Integer. Lower Bounds of hidden layers of CNN used in RMDL, it will default to 3.

max_hidden_layer_cnn

max_hidden_layer_cnn: Integer. Upper Bounds of hidden layers of CNN used in RMDL, it will default to 10.

min_nodes_cnn

min_nodes_cnn: Integer. Lower bounds of nodes (2D convolution layer) in each layer of CNN used in RMDL, it will default to 128.

max_nodes_cnn

min_nodes_cnn: Integer. Upper bounds of nodes (2D convolution layer) in each layer of CNN used in RMDL, it will default to 512.

random_state

random_state : Integer, RandomState instance or None, optional (default=None)

If Integer, random_state is the seed used by the random number generator;

random_optimizor

random_optimizor : bool, If False, all models use adam optimizer. If True, all models use random optimizers. it will default to True

dropout

dropout: Float between 0 and 1. A fraction of the units to drop for the linear transformation of the inputs.

Example MNIST

The MNIST database contains 60,000 training images and 10,000 testing images.

```
Import Packages
from keras.datasets import mnist
import numpy as np
from RMDL import RMDL_Image as RMDL
Load Data
(X_train, y_train), (X_test, y_test) = mnist.load_data()
X_train_D = X_train.reshape(X_train.shape[0], 28, 28, 1).astype('float32')
X_test_D = X_test.reshape(X_test.shape[0], 28, 28, 1).astype('float32')
X_train = X_train_D / 255.0
X_test = X_test_D / 255.0
number_of_classes = np.unique(y_train).shape[0]
shape = (28, 28, 1)
Using RMDL
batch_size = 128
sparse_categorical = 0
n_epochs = [100, 100, 100] ## DNN-RNN-CNN
Random_Deep = [3, 3, 3] ## DNN-RNN-CNNRMDL.Image_Classification(X_train, y_train, X_test, y_test,shape,
batch_size=batch_size,
sparse_categorical=True,
random_deep=Random_Deep,
epochs=n_epochs)
```

IMDB

This dataset contains 50,000 documents with 2 categories.