# Programmingempire

In this post on Artificial Neural Network (ANN) Model using Scikit-Learn, I will demonstrate how to use the scikit-learn library of python to build an Artificial Neural Network. Before proceeding further, let us first discuss what is an Artificial Neural Network.

**Artificial Neural Network** (ANN)

Basically, an Artificial Neural Network (ANN) has comprises of an input layer of neurons, an output layer and one or more hidden layers in between. Also, a fully connected ANN is known as Multi-layer Perceptron.

**What is a Multi-layer Perceptron**?

While a perceptron has an input layer and an output layer of neurons, the Multi-layer Perceptron also includes hidden layers along with input and output layers. Basically, a Multi-layer Perceptron works as follows.

Firstly, it computes a dot product of the input and the weight present at the input layer neuron. After that, it sends it to the hidden layer neuron. The input to a hidden layer goes through an activation function and the resulting output of the activation function is used in computing the dot product with the weight present at that neuron.

Consequently, the resulting dot product at hidden layer acts the input of the next layer neurons and the same process repeats until the output layer reaches.

Finally, the neurons at the output layer carry out computations using the activation function present there. Further, the computed results are used in either backpropagation for the purpose of training or they are used for making predictions in case of the model is already trained.

**Creating an Artificial Neural Network (ANN) Model using Scikit-Learn**

In fact, the scikit-learn library of python comprises a classifier known as the ** MLPClassifier** that we can use to build a Multi-layer Perceptron model. Additionally, the

**r works using a backpropagation algorithm for training the network. The following code shows the complete syntax of the MLPClassifier function.**

*MLPClassifie*`MLPClassifier(hidden_layer_sizes, activation, solver, alpha, batch_size, learning_rate, learning_rate_init, power_t, max_iter, shuffle, random_state, tol, verbose, warm_start, momentum, nesterovs_momentum, early_stopping, validation_fraction, beta_1, beta_2, epsilon, n_iter_no_change, max_fun)`

In short, we describe the parameters below.

Basically, ** hidden_layer_sizes** represents the number of neurons in a hidden layer. Moreover, you can specify number of hidden layers using a comma separated list of their respective size. For example, the following MLP Classifier has four hidden layers with given sizes.

`MLPClassifier(hidden_layer_sizes=(12, 13, 10, 8), ......)`

Similarly, we can specify the activation function which a hidden layer uses with the help of ** activation** parameter. For the purpose of weight optimization we use a solver. Basically, it is an optimization algorithm that updates the learning rate. The default is

**solver. In order to prevent overfitting, we use the parameter**

*adam***which is used for regularization.**

*alpha***Parameters Related to Learning**

The next parameter, ** batch_size** refers to the size of particular mini batches. Likewise,

**parameter indicates whether the learning rate is**

*learning_rate***(inverse scaling learning rate). Further, the**

*constant, adaptive, or invscaling***refers to the initial learning rate.**

*learning_rate_init*In case, you use the inverse scaling learning rate by providing the value ** invscaling** to the

**parameter, use power_t also. Here you can specify the exponent for it using the parameter**

*learning_rate***. Further, you can specify maximum number of iterations using**

*power_t***parameter. Also, the boolean parameter shuffle specifies whether the samples should be shuffled in each iteration.**

*max_iter***Parameters for Stopping the Learning Process**

Likewise, for weights and bias initialization, random numbers can be generated by using the ** random_state** parameter. Significantly, the MLP Classifier has a parameter known as

**for specifying tolerance for the optimization. In other words, when the loss is not improved by the value specified in**

*tol***parameter after successive iterations, the network stops further learning and the training is finished. The parameter**

*tol***indicates the number of iterations till the value in**

*n_iter_no_change***is not achieved.**

*tol*The boolean parameter ** verbose** is used to display the progress messages, While the parameter

**makes use of values previously used. Similarly, momentum refers to the momentum for gradient descent updates. Additionally,**

*warm_start***indicates the use of**

*nesteroves_momentum***.**

*Nesterov Momentum*Sometimes it happens that the validation score doesn’t improve, then we can terminate the learning by setting the boolean parameter ** early_stopping** to true. Meanwhile, we can put the fraction of training data for the purpose of validation by specifying the

**parameter.**

*validation_fraction*The parameters ** beta_1, and beta_2** refer to the exponential decay rate for estimates for first moment vector and the second moment vector in

**respectively. Further, we can specify the value for numerical stability using the parameter**

*adam***that we can use only with the**

*epsilon***.**

*adam solver*Finally, we can specify maximum number of calls of the loss function using the parameter ** max_fun** that we use only with

**.**

*lbfgs solver***Further Reading**

How to Implement Inheritance in Python

Find Prime Numbers in Given Range in Python

Running Instructions in an Interactive Interpreter in Python

Deep Learning Practice Exercise

Deep Learning Methods for Object Detection

Image Contrast Enhancement using Histogram Equalization

Transfer Learning and its Applications

Examples of OpenCV Library in Python

Understanding Blockchain Concepts

Example of Multi-layer Perceptron Classifier in Python

Measuring Performance of Classification using Confusion Matrix

Artificial Neural Network (ANN) Model using Scikit-Learn

Popular Machine Learning Algorithms for Prediction

Long Short Term Memory – An Artificial Recurrent Neural Network Architecture

Python Project Ideas for Undergraduate Students

Creating Basic Charts using Plotly

Visualizing Regression Models with lmplot() and residplot() in Seaborn

Data Visualization with Pandas