Segmenting and clustering contacts by RFM values. Example of usage Sitecore Cortex with ML.Net.
Contains 2 solutions:
Full overview of demo located here
Sitecore 9.1.0 (for 9.1.1 and higher versions package references in project should be updated to corresponding versions)
Install the sitecore package RFM Demo-1.0 (sitecore package).zip
- Extract and copy xconnect to your xConnect instance
- Restart xConnect instance and xconnect jobs in windows services
- Build solution.
- Run Demo.Project.DemoDataExplorer.exe from project Demo.Project.DemoDataExplorer
- Copy your sitecore website root url to "API address"
- Click "Browse" and select Online Retail.xlsx (~500k records)
- Click "Upload file". Wait for finishing uploading process (it takes ~10 min). During process you can see logs in sitecore instance and new contacts appearance in Experience Profile:
INFO Excel import: 272 from 4339: CustomerID=15332
- Run MLServer solution in IIS Express (or install it as IIS application)
- Make sure that it is accessible by requesting http://localhost:56399/api/rfm/test
- If you change localhost url to your own, make corresponding change in Processing Engine -> sc.Processing.Services.MLNet.xml
- POST request to http://sitecoreInstance.url/api/contactapi/RegisterTasks with POSTMAN
- Or change processing agent sleep period in Processing Engine -> sc.Processing.Engine.DemoAgents.xml
- All processes execution takes ~10 minutes (~500k records). During process you can see logs in Processing Engine job:
[Information] Registered Distributed Processing Task, TaskId: 19260a83-e180-457a-9bdb-b9210f6e757f, Worker: Sitecore.Processing.Engine.ML.Workers.ProjectionWorker`1[[Sitecore.XConnect.Interaction, Sitecore.XConnect, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null]], Sitecore.Processing.Engine.ML, DataSource: Sitecore.Processing.Engine.DataSources.DataExtraction.InteractionDataSource, Sitecore.Processing.Engine
[Information] Registered Deferred Processing Task, Id: 1a0f5ca3-2118-4c43-a57d-2dcabce48a16, Worker: Sitecore.Processing.Engine.ML.Workers.MergeWorker, Sitecore.Processing.Engine.ML
[Information] Registered Deferred Processing Task, Id: 4eb84501-15f2-4861-849d-cb671d932dfd, Worker: Demo.Foundation.ProcessingEngine.Train.Workers.RfmTrainingWorker, Demo.Foundation.ProcessingEngine
[Information] Registered Distributed Processing Task, TaskId: b8784a8a-ac13-4d86-af86-676a6fe11bc1, Worker: Demo.Foundation.ProcessingEngine.Predict.Workers.RfmEvaluationWorker, Demo.Foundation.ProcessingEngine, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null, DataSource: Sitecore.Processing.Engine.DataSources.DataExtraction.ContactDataSource, Sitecore.Processing.Engine
[Information] TaskAgent Executing worker. Machine: BRIMIT-SBA-PC, Process: 26164, AgentId: 8, TaskId: 19260a83-e180-457a-9bdb-b9210f6e757f, TaskType: DistributedProcessing.
[Information] TaskAgent Executing worker. Machine: BRIMIT-SBA-PC, Process: 26164, AgentId: 7, TaskId: 1a0f5ca3-2118-4c43-a57d-2dcabce48a16, TaskType: DeferredAction.
[Information] TaskAgent Worker execution completed. Machine: BRIMIT-SBA-PC, Process: 26164, AgentId: 8, TaskId: 19260a83-e180-457a-9bdb-b9210f6e757f, TaskType: DistributedProcessing.
[Information] TaskAgent Worker execution completed. Machine: BRIMIT-SBA-PC, Process: 26164, AgentId: 7, TaskId: 1a0f5ca3-2118-4c43-a57d-2dcabce48a16, TaskType: DeferredAction.
[Information] TaskAgent Executing worker. Machine: BRIMIT-SBA-PC, Process: 26164, AgentId: 7, TaskId: 4eb84501-15f2-4861-849d-cb671d932dfd, TaskType: DeferredAction.
[Information] RfmTrainingWorker.RunAsync
[Information] Update RFM info: customerId=12534, R=2, F=2, M=2, Recency=1, Frequency=63, Monetary=1089.18
[Information] Update RFM info: customerId=14947, R=2, F=1, M=1, Recency=59.2618055555556, Frequency=14, Monetary=290.82
[Information] Update RFM info: customerId=17941, R=2, F=1, M=1, Recency=1, Frequency=2, Monetary=304.56
...
[Information] TaskAgent Worker execution completed. Machine: BRIMIT-SBA-PC, Process: 26164, AgentId: 7, TaskId: 4eb84501-15f2-4861-849d-cb671d932dfd, TaskType: DeferredAction.
[Information] TaskAgent Executing worker. Machine: BRIMIT-SBA-PC, Process: 26164, AgentId: 7, TaskId: b8784a8a-ac13-4d86-af86-676a6fe11bc1, TaskType: DistributedProcessing.
[Information] RFM info: [email protected], R=1, F=1, M=1, Recency=1, Frequency=12, Monetary=227.39, CLUSTER=5
[Information] RFM info: [email protected], R=1, F=1, M=1, Recency=1, Frequency=12, Monetary=196.89, CLUSTER=5
[Information] RFM info: [email protected], R=1, F=3, M=2, Recency=1, Frequency=77, Monetary=469.48, CLUSTER=4
...
[Information] RFM info: [email protected], R=3, F=3, M=3, Recency=343.147222222222, Frequency=172, Monetary=3237.54, CLUSTER=2
[Information] TaskAgent Worker execution completed. Machine: BRIMIT-SBA-PC, Process: 26164, AgentId: 7, TaskId: b8784a8a-ac13-4d86-af86-676a6fe11bc1, TaskType: DistributedProcessing.
If you are faced with any issues or have questions/suggestions you can contact me in sitecore slack channel #cortexmachinelearning @x3mxray