# What exactly is a trained model for machine-learning?

I am curious about the deployment phase of a machine-learning model. So, after you run your script using python to train your millions of data and it works, what are some methods of deploying your model to the real world? I know libraries such as pickle which is being used to serialize a model exists, but what exactly is a model?

Is it some sort of blueprint which is then used to craft the predicted answer? If so, what does that mean that having a pickled object in the real world is much faster at churning predictions than re-training your model again?

A machine learning model is an algorithm which learns features from the given data to produce labels which may be continuous or categorical ( regression and classification respectively ). In other words, it tries to relate the given data with its labels, just as the human brain does.

Mathematical functions are used to map the features ( produced as a result of feature extraction ) to their labels.

Models trained on a high amount of data can generalise themselves better. Generalisation is the ability of a model to give generalised predictions across varied or diverse data. It is not biased towards the data on which it was originally trained.

Production of models has these basic steps involved:

1. Collection of suitable data.
2. Preprocessing of data for training the model.
3. Training the model.
4. Evaluating the model.
5. Hosting the model for production.

Deploying a model:

This could be done in many ways. You can serve a model or run it on an IoT device. You basically want to freeze all the trainable parameters so that they are constants. The model's learning capabilities are removed so that it could only make predictions. There are some models which exhibit Online Learning.

Different frameworks like TensorFlow, Keras, PyTorch etc. have their own methods of saving models. Like in Keras, we can save a NN model as a hd5f serialized file. With TensorFlow Lite, we can run a model on an IoT device.

Firebase MLKit hosts the model in the cloud created with TensorFlow.

The best deployment platform is determined by its usability, scalability and developer friendliness.

There are two phases in Machine Learning

1. Training (creation of model)
2. Inference (deployment of model)

Now coming to your question of what do we mean by model. Either in neural networks(which is deep learning) or any traditional machine learning methods, what you are trying to do is map an approximate function between input and output. You try to get the parameters of the function using training and then use those parameters during inference to predict output for new unseen inputs. So, model is nothing but parameters. Objective of training is to find these parameters.

For example in neural networks, we have parameters as weights and bias. So, weights and bias of all layers of neural network together constitute a model. Final output of training is nothing but weights and bias of all layers of neural network. We store them, deploy them where ever necessary and use them for inference.

• So, if i am not wrong, models are sort of things like equations? Like the y=mx+c equation you get from a linear regression model? Jun 15 '19 at 3:08
• @Axois, yes you are correct. Linear regression is indeed a good example to get the idea: the training stage consists in calculating the variables m and c from a set of observations. Thus the model simply consists in these variables, and it can be applied to any new instance x in order to "predict" y. Of course some ML methods are much more complex than that, but the principle is the same. Jun 15 '19 at 14:13
• @Axois, you are perfectly right for linear regression model. Here when you say save a model, you just save m and c. During inference you use the equation above with m and c you know to predict the y for any new x. Similarly, for neural networks, model is nothing but weights, bias of all layers of neural network, and during inference, you use these model parameters to do a forward pass to predict the output for any new input to the neural network. Summary is when you say, you are saving the model, you are saving the parameters. Jun 15 '19 at 17:30