# Neural Networks Tutorial 7. Model deployment

The concept of deployment in machine learning refers to the application of a model for the prediction of new data.

Indeed, the knowledge gained when building a predictive model will need to be organized and presented in a way that the customer can use it.

Depending on the requirements, the deployment phase can be as simple as generating a report or as complex as implementing a continous learning process.

The following techniques are used for deploying a neural network:

## Neural network outputs

A neural network produces a set of outputs for each set of inputs applied.

The following table shows the input values together with the corresponding output value for the case of estimating the fuel consumption of a car as a function of its attributes.

Cylinders Displacement Horsepower Weight Acceleration Model year Fuel consumption
8 307 130 3504 12 1980 17 mpg

## Output data

In many cases, the objective is to predict the outputs for many different cases stored in a data file. Each row in the data file contains the input values of the case to be predicted. A new file is created with the outputs of the model also arranged in rows.

The next table illustrates this deployment technique. Here a neural network predicts the probability of conversion for several customers in a marketing campaign as a function of engagement factors.

Recency Frequency Monetary Conversion
2 months 5 times 125 USD 70%
5 months 2 times 20 USD 8%
3 months 9 times 225 USD 85%
4 months 1 times 15 USD 5%
1 months 3 times 70 USD 75%

## Directional outputs

It is very useful to see how the outputs vary as a function of a single input, when all the others are fixed. This allows to perform prescriptions. Directional outputs can be seen as the cut of the neural network model along some input direction and through some reference point.

The next table shows the reference point for plotting all the directional output charts. In this case, the model estimates the residuary resistance of a sailing yacht as a function of design parameters and sailing conditions.

 Center of buoyancy -2.38 Prismatic coefficient 0.56 Lenght displacement 4.79 Beam draught ratio 3.94 Lenght beam ratio 3.21

The next chart shows how the residuary resistance varies with the Froude number (which represents the velocity of the yacht), with all the other inputs being fixed.

As we can see, the residuary resistance increases exponentialy for high values of the Froude number. Therefore, this yacht design does not perform well at high speeds.

## Mathematical expression

Any neural network represents a function of the outputs with respect to the inputs. That function also depends on the parameters. The mathematical expression represented by the neural network can be used to embed it into another software, in the so-called production mode.

An example of the mathematical model represented by a neural network is listed next.

$$scaled_shear_rate = 2*(shear_rate-50)/(90-50)-1; scaled_particle_diameter = 2*(particle_diameter-0.72)/(6.596-0.72)-1; y_1_1 = tanh(-1.06007+(scaled_shear_rate*0.448487)+(scaled_particle_diameter*-0.861393)); y_1_2 = tanh(0.756922+(scaled_shear_rate*2.00716)+(scaled_particle_diameter*0.391539)); y_1_3 = tanh(0.862072+(scaled_shear_rate*-0.726115)+(scaled_particle_diameter*-1.46053)); scaled_particles_adhering = (-1.30536+(y_1_1*-1.0244)+(y_1_2*0.56055)+(y_1_3*-0.565459)); particles_adhering = (0.5*(scaled_particles_adhering+1.0)*(74.75-13.22)+13.22);$$

## Python expression

The mathematical expression represented by the model can be exported to different programming languages, like Python.

The next listing is an example of a neural network in the Python programming language.

 

## R expression

A programming language widely used for statistical analysis is R.

The next code is an example of a neural network in the R programming language.