-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel-deploy-instructions.Rmd
64 lines (35 loc) · 20.5 KB
/
model-deploy-instructions.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
---
title: "Model Deploy Instructions"
output:
html_document: default
---
# Introduction
Imagine that you are a data scientist at a company that has to perform dynamic inventory management. An example of that would be a ride-sharing company where you want to know which parts of a city to direct your drivers to depending on the time of day and other factors.
Using data from pickups made by Uber in New York City, we created a random forest model to predict demand given the hour, date, and location. The algorithm includes feature engineering (day of the week, whether it is a holiday, and weather), which the model uses to predict the number of pickups.
In this section we'll deploy this model. After it has been deployed, we can query it in real time to obtain predictions for demand at a particular time and place.
The model will take in the hour, date, and location names as inputs and return the predicted demand (in terms of number of expected pickups) as the output.
## The Model Script
The main script that contains the model code is <span style="padding: 2px 5px 2px 5px; font-family:courier; background-color:#DDDDDD;">model.R</span> Let's open the file to look at the structure of a model.
We first load libraries that we will use and then train the model. The training steps are not carried out when we deploy this model; instead we will load a pre-trained model in the interest of time. However it is good practice to have the code easily accessible so we can retrain the model and/or retrace our work if needed. After training/loading the pre-trained model, we get to the prediction function,
<span style="padding: 2px 5px 2px 5px; font-family:courier; background-color:#DDDDDD;">pred_pickups(hour, date, location_name)</span>
When a model is deployed, the script is run once from top to bottom. This allows us to define all of the functions we need and load all of the data, models, and functions we need to load into memory.
After the script is run once and the model is set up, when an API call is made, the predict function, in our case <span style="padding: 2px 5px 2px 5px; font-family:courier; background-color:#DDDDDD;">pred_pickups(hour, date, location_name)</span> is called.
Now that we conceptually understand how a model script works, let's look at how we can set it up to deploy.
## Deploying the Model
From the project page click the <img style = "display: inline; width:30px; height:30px" src ="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFIAAABSCAYAAADHLIObAAAMGGlDQ1B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mRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPgogICAgICA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIgogICAgICAgICAgICB4bWxuczpleGlmPSJodHRwOi8vbnMuYWRvYmUuY29tL2V4aWYvMS4wLyI+CiAgICAgICAgIDxleGlmOlBpeGVsWERpbWVuc2lvbj44MjwvZXhpZjpQaXhlbFhEaW1lbnNpb24+CiAgICAgICAgIDxleGlmOlBpeGVsWURpbWVuc2lvbj44MjwvZXhpZjpQaXhlbFlEaW1lbnNpb24+CiAgICAgIDwvcmRmOkRlc2NyaXB0aW9uPgogICA8L3JkZjpSREY+CjwveDp4bXBtZXRhPgpeaTVCAAAAHGlET1QAAAACAAAAAAAAACkAAAAoAAAAKQAAACkAAAthT9rwugAACy1JREFUeAHEmg2QTtcZx593dymqiwSLTbISQUWQMqEkgxHahHZotFH6EanQMtGmmCZpk0paU1EmTUh8VJio8VGpIilVVYNJGTLRVoZEhFjshlSJj9TaLz3/c+5z73PPe+59793V9gzv83m+fp5773nvK3NVNapHS9M9TW49lpTVNZPJZPmiHGly5RiZuoJMAyVNLhaXND/tptPkp8nFmusEMslGr1UOFpm2JYFwrXJ4balAXgs412IMf/EJLtlcwHLFMVeiHLWxRPfIXGlx8brGGFgaGbfpusaSwExUkXEgMElU3OV3+RhUXIxzXDItoKj8KD/PGRePBZlrY1Fxlz+pjxcN6eoDf9yGouKuPi5fVH/4ubn6RYKM2gQP5orbPttG36Q+nieNdG7QcR+182wbc7p8ci123AnStVkexBWzfWltjG334fmSSntj6Gf70tquMeR65HhZIOM25IrZPmlLHQuQttR5cbZPPwXtR6E6W9vHa7khHkv6pI64tKVux1xjsY8l9w+BtDfCyZCumPQl0e1xZJ+zH5+n0uNlVFZ+mk7/8wydPXeeLly8RJcrKqi6ukYvpaAgnxo3akSFn2lK17VoRkWtWlJxuyIquamYrmveTOfggzdn67YdlSf96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NH/mXbZ+iKz/WinvznBl1kCMLaFqDmW2lzZRH8ZuPqg/QVCcNCs7b1x2BpvFjMwsfYIeDjJ07Svv0f0MFDhxnqMTp2/ASd4t9F4jdB9XXua2AF/8ylqkULas1/u+7Av6/s3Kk9devSmXp86lL56R/G1YUqBPWprXFI+9I8lWFM/VZCR5NcXlDm81coSIjp6gtBqB9SXzqGxrSP+iGtz/pDHbY2TFyb1eELgYU+zZfFJzCRY/1hHxvP0zMViSRdNHQ0a6tuZTHdxnSsmE9jVkJvSgsBxOw8n/Xn6ZiDxkLd2gUgEdTFQkezdqjDVl8otdpCf6yPO1L+sTQO2aSFXUC1YVx96fGaciyZEy82s7V1AF18zLYxhaK+mIz57Lgah8/qmlNMhgsNbfRVH6TVYzGN21ioR22eOBpiBS30WzvUYYc+DKg+rU7rC3XYNg92Y03PiZqXB0LzNK4S/aDrq7FxNF/zVJbxQoWiLlgDKkO/tUNd7VBiLOtT3fr1eHk+G1fdwoj5LBybq7qVqmOcPD2M6THFz4sqChJJduGN2baitJ9K21d9KhFDC23nzX+3i0aW2qGMxeDTSrVx6Gg6hrMKbfVLLk/c72uj2hzRYzHrs3oMpg5o81RXiRyra59i0i5WdZXoZ/XQzoMY9gn7wbYN+f8He3sBZCez54gAAAAASUVORK5CYII"></img> button and select <span style="padding: 2px 5px 2px 5px; font-family:courier; background-color:#DDDDDD;">Deploy an API</span> from the drop-down menu.
Fill in a name and a description for the model and click <span style="padding: 2px 5px 2px 5px; font-family:courier; background-color:#DDDDDD;">Next</span>.
Under branch, select the branch containing the model code to be deployed. For this demo select <span style="padding: 2px 5px 2px 5px; font-family:courier; background-color:#DDDDDD;">master</span>.
The field <span style="padding: 2px 5px 2px 5px; font-family:courier; background-color:#DDDDDD;">Set Script Entry Point</span> points to the model script to be deployed. For this demo we will deploy the model script <span style="padding: 2px 5px 2px 5px; font-family:courier; background-color:#DDDDDD;">model.R</span>, so enter that in this field.
We will now configure the model environment. Click the <span style="padding: 2px 5px 2px 5px; font-family:courier; background-color:#DDDDDD;">edit</span> button next to <span style="padding: 2px 5px 2px 5px; font-family:courier; background-color:#DDDDDD;">Environment Configuration</span>. In this screen we can configure the language, package dependencies, and compute resources our model will require. Select <span style="padding: 2px 5px 2px 5px; font-family:courier; background-color:#DDDDDD;">R</span> for the model language.
We may wish to pre-define packages and dependencies that will be installed when we deploy our model. To do this, we can list these packages and dependencies in text files, and point the platform to these files using the <span style="padding: 2px 5px 2px 5px; font-family:courier; background-color:#DDDDDD;">Add Requirements</span> section. Under <span style="padding: 2px 5px 2px 5px; font-family:courier; background-color:#DDDDDD;">Add Requirements</span> next to the field labeled <span style="padding: 2px 5px 2px 5px; font-family:courier; background-color:#DDDDDD;">R</span>, enter <span style="padding: 2px 5px 2px 5px; font-family:courier; background-color:#DDDDDD;">requirements.R</span>. This will install packages on the model environment's operating system.
Finally, select a <span style="padding: 2px 5px 2px 5px; font-family:courier; background-color:#DDDDDD;">2GB</span> environment under <span style="padding: 2px 5px 2px 5px; font-family:courier; background-color:#DDDDDD;">Computational Resources</span> and click <span style="padding: 2px 5px 2px 5px; font-family:courier; background-color:#DDDDDD;">Save</span>.
Next, we need to specify the function that will run when the API is called. We saw earlier that the function in our script is called <span style="padding: 2px 5px 2px 5px; font-family:courier; background-color:#DDDDDD;">pred_pickups</span> so enter that in the <span style="padding: 2px 5px 2px 5px; font-family:courier; background-color:#DDDDDD;">Specify Function</span> text box.
We can also <span style="padding: 2px 5px 2px 5px; font-family:courier; background-color:#DDDDDD;">Give an Example</span> input to the API that will show up in the DS Platform deploy UI. While this is not required, it is important to help others know how to use your model. Our model takes three arguments: hour (24H, integer), date (YYYY-MM-DD format), and location_name (character). Input data is passed to the model as valid JSON with function arguments as keys. To pass in the arguments hour = 20, date = "2017-01-01", and location_name = "West Village" enter <span style="padding: 2px 5px 2px 5px; font-family:courier; background-color:#DDDDDD;">{"hour": 20, "date": "2017-01-01", "location_name": "West Village"}</span> as your example.
We're ready to deploy the model! <span style="padding: 2px 5px 2px 5px; font-family:courier; background-color:#DDDDDD;">Add a Commit Message</span> and click <span style="padding: 2px 5px 2px 5px; font-family:courier; background-color:#DDDDDD;">Deploy</span>
On the screen overlay that comes up, click <span style="padding: 2px 5px 2px 5px; font-family:courier; background-color:#DDDDDD;">Go To Model</span>.
The deployed model will first run through a number of automated setup steps to spin up an environment that will host the model, and to install model requirements. When this process completes successfully, we will see its status change to <span style="padding: 2px 5px 2px 5px; font-family:courier; background-color:#DDDDDD;">running</span>, indicating that we can now use the model</span>
When models are updated or changed, new versions can be deployed using the <span style="padding: 2px 5px 2px 5px; font-family:courier; background-color:#DDDDDD;">Deploy New Version</span> button, and any of the different versions can be deployed simultaneously, providing for the ability to test model changes on real-time data.
Now that our model is successfuly deployed we can get use it to get predictions. The DataScience Platform provides an easy way to run samples to make sure the model is working properly. The example input we defined appears in the model GUI to help users understand how to use the model. Let's run a few samples.
The DataScience Platform also generates the API endpoint we need to query to generate predictions. We can for example embed the cURL, Python, or Node code into any application or program. For example, we can copy the cURL to a terminal window and run it from there.
## Congratulations!
You've deployed your first model on the DataScience Platform. In a very short time frame we were able to deploy a model behind an API so that it can be used by anyone in the organization and can be accessed in a variety of different contexts including applications and websites. Importantly, we were able to quickly accomplish this without relying heavily on engineering resources that may be constrained.