How do I deploy a machine learning algorithm to a production environment?

I am new to machine learning algorithm. I am learning basic algorithms such as regression, classification, clustering, sequence modeling, online algorithms. The entire article available on the Internet shows how to use this algorithm with specific data. There is no article on deploying this algorithm in a production environment. So my questions are:

1) How do I deploy a machine learning algorithm to production?

2) The typical approach followed in a machine learning tutorial is to build a model using some training data, use it to test the data. But is it advisable to use such a model in a production environment? The input data may change, so the model will be ineffective. How long should the model refresh cycle be to accommodate such changes?

+5


source to share


3 answers


I'm not sure if this is a good question (as it is too general and not formulated well), but I suggest you read about bias bias - variance. In short, you can have a low variance / high variance machine learning model and get 100% accurate results from your test data (the data you used to implement the model), but you could force your model to overload the training data. As a result, when you try to use it on data that you didn't use during training, it will perform poorly. On the other hand, you may have a high variance / low variance system that will not fit your training data well and will also be just as bad with new production data. With this in mind, general recommendations would be as follows:

1) Get a good amount of data that can be used to prototype a machine learning system.

2) Split your data into train set, cross validation set and test set

3) Build a model that will have relatively low bias (good accuracy, in fact - a good F1 score) over your test data. Then try this cross-validation model to see the results. If the results are poor, you have a large variance problem, you used a model that overloads the data and cannot generalize well. Overwrite your model, play with model parameters, or use a different algorithm. Repeat until you get a good CV typing result

4) Since we played with the model to get a good CV set result, you want to test your final model on a test set. If that's okay, you have the final version of the model and can use it in prod.



The second question has no answer, it is based on your data and your application. But 2 general approaches can be used:

1) Do everything that I mentioned earlier to build a model with good performance on the test set. Repeat running your model on the new data once in a period of time (try different periods, but you can try to re-prepare your model as soon as you see the model performance has dropped).

2) Use the online learning method. This is not applicable for many algorithms, but it can be used in some cases. Typically, if you see that you can use the stochastic gradient descent method, you can use online training and simply update your model with the latest production data.

Keep in mind that even if you use # 2 (online learning approach), you cannot be sure that your model will last forever. Sooner or later, the data you receive may change significantly, and you can use a whole different model (for example, switch to ANN instead of SWM or logistic regression).

+7


source


DISCLAIMER: I work for this company, Datmo , creating a better workflow for ML. Have always been interested in helping other developers working on ML, feel free to contact me at anand@datmo.com if you have any questions.

1) To deploy, you must first split your code into preprocessing, training, and testing. This way you can easily encapsulate the required components for deployment. Typically you will want to preprocess, test, and file your weights (the output of your learning process) and put them all in one folder. Then you will want to host this on a server and wrap an API server around it. I would suggest Flask Restful API so that you can use request parameters as your inputs and output your response in JSON building blocks.

To host it on the server, you can use this article , which talks about how you can deploy the Flask API to EC2.



You can download and simulate and serve it as an API as mentioned in this code .

2) It's hard for me to answer without any details. It is highly dependent on data type and model type. For example, for deep learning, there is no such thing as online learning.

+5


source


As for the first question, my mlrequest service makes it easy to deploy models for production. Models are replicated across 5 data centers around the world using a single Python line. Response times are less than 60ms and models can scale to many thousands of transactions per second. You can get started with a free API key that provides 50,000 model transactions per month.

The models are online and can be updated as often as you want. You don't need to batch send old training data to update your model, it will update gradually from where it was last stopped. A simple example is shown below in Python, but you can use mlrequest with any language.

$pip install mlrequest

      

An example of training a model with one update. This code will deploy or update your replicated model across 5 global datacenters.

from mlrequest import Classifier
classifier = Classifier('my-api-key')
features = {'feature1': 'val1', 'feature2': 45}
training_data = {'features': features, 'label': 2}
r = classifier.learn(training_data=training_data, model_name='my-model', class_count=2)

      

An example of forecasting a model. Latency is routed to the nearest datacenter to get the fastest response.

features = {'feature1': 'val1', 'feature2': 77}
r = classifier.predict(features=features, model_name='my-model', class_count=2)
r.predict_result

      

As for your second question, it depends entirely on the problem you are solving. Some models require frequent updates, while others almost never need to be updated.

+1


source







All Articles