In the Visual Studio Code project you cloned earlier, there is a table called Rest. ML Forecast Setup with two additional functions, getMLUri and getMLKey.
Insert your URI and a key (copied from the previous step) into these functions:
Open the Train Rest. Forecast ML codeunit and find the Train() function. Let's investigate how it works. The defined variables are as follows:
From the preceding screenshot, we observe the following:
- ML Prediction Management: This is the main codeunit, which has functions to train, save, and use the ML model.
- MyModel: This is the trained model in coded text format.
- MyModelQuality: This is the quality of the trained model.
- Setup: This is the table where trained models are stored.
- RestSalesEntry: This is the historical data used to train an ML model.
Specify connections to your published predictive ML web service, as follows:
Now, prepare historical data for the training process. You can filter data or add new columns.
The important things to note here are as follows:
- There should not be empty fields in the training dataset. If you have them, fill them with any value, such as 0 or NA.
- If you have a Date field, split it into two fields (at least): day and month. Usually, the forecast depends on these fields, not on the date itself. The date format is not supported in this API.
Consider the following screenshot:
Specify the features for the model. Here, you specify the fields that influence the predictions:
Then, we specify the label. Here, you specify the fields that you are going to predict:
Next, we train the model. Here, you send a request to the web service with the historical data that's used for training. As a result, you will get a trained model in Base64 text format and the model quality:
Save your trained model. It will be used later, in the prediction process: