Implement custom prediction model
The functionality is relevant to Classic UI.
Case description
Implement automatic prediction for the AccountCategory column by the values of the *Country , EmployeesNumber and Industry field while saving the account record. The following conditions should be met:
- Model learning should be created on the base of account records for last 90 days.
- Moodel Retraining should be performed every 30 days.
- Permissible value of prediction accuracy for the model – 0,6.
To complete this case you need to check the correctness of the value of the Creatio cloud services API key (CloudServicesAPIKey
code) system setting and the URL of the predictive service in the Service endpoint Url field of the ML problem types lookup.
You can use the page UI-tools (fields and filters), as well as the Predict data business process element to perform the described case. You can find more cases on implementing prediction using the default Creatio tools in the Predictive analysis article (user documentation).
Case implementation algorithm
1. Model learning
To train the model:
1. Add a record to the ML Model
lookup. View the values of the record fields are given in the table below.
Field | Value |
---|---|
Name | Predict account category |
ML problem type | Lookup prediction |
Target schema for prediction | Account |
Quality metric low limit | 0,6 |
Model retrain frequency (days) | 30 |
Training set properties |
|
Training set query |
You can find examples of queries in the Creating data queries for the machine learning model article. |
Predictions enabled (checkbox) | Enable |
2. Perform the Execute model training job action on the ML Model
lookup field.
Wait until the values of the Model processing status field will be changed in following sequence: DataTransfer
, QueuedToTrain
, Training
, Done
. The process may take several hours to finish (it depends on the amount of passed data and general workload of the predictive service.
2. Performing the prediction
To start the predictions:
-
Create a business process in the user package. Select the saving of the Contact object as a start signal for the process. Check if the required fields are populated (Fig. 1).
-
Add the
MLModelId
lookup parameter that refers to the ML Model entity. Select the record with the Predict account category model as a value. -
Add the
RecordId
lookup parameter that refers to the Account entity. Select a reference for theRecordId
parameter of the Signal element as a value. -
Add a Script task element on the business process diagram and add the following code there:
var userConnection = Get<UserConnection>("UserConnection");
// Getting the Id of the Account record.
Guid entityId = Get<Guid>("RecordId");
// Geeting the id of the model.
var modelId = Get<Guid>("MLModelId");
var connectionArg = new ConstructorArgument("userConnection", userConnection);
// Object for calling prediction.
var predictor = ClassFactory.Get<MLEntityPredictor>(connectionArg);
// Call of the forecasting service. The Data is saved in MLPrediction and in case of high probability of forecasting the data is saved in the required field of the Account.
predictor.PredictEntityValueAndSaveResult(modelId, entityId);
return true;
After saving and compiling the process, the prediction will be performed for new accounts. The prediction will be displayed on the account edit page.
This implementation of the prediction slows down the saving an account record because call of the prediction service is executed in 2 seconds. This can reduce the performance of the mass operations with data saving, like import from Excel.