Sitecore Page Recommender: How to build a machine learning service

page recommender

This blog post is part of a larger series that looks at the steps to create a
Page Recommendation Engine for Sitecore.


Building a machine learning model is straight forward with the help of some built in tool for visual studio.

First of all, you need to download and install Visual Studio 2022. Then download and install ML.NET Model Builder 2022 UI Tools via this link: https://marketplace.visualstudio.com/items?itemName=MLNET.ModelBuilder2022

To begin:

  1. Create a new console app solution. 


  2. Select “.Net 6.0“


  3. Right click on project and select Add=> Machine Learning


    • Select Machine Learning Algorithm to use (in our case recommendation)


    • Select local training environment


    • Select prepared training data (e.g. see training.csv attached)


    • Click Train - This tries the data provided against a variety of algorithms that are packaged with ML.Net and selects the one with the best quality (this is determined by the lowest value for RSquared.



    • Evaluate the model - the dialog automatically selects some values to test (from provided data). Those values are then passed to the model and an example prediction is shown. Further to this, on the right side, it shows which pageIds return the highest prediction (i.e. these would be our recommendations).



    • Consume step. If you select => Console App => Add to solution. A new console application is added, with some test code that shows how to consume your new model and make predictions.


    Example code shown below:

    // Create single instance of sample data from first line of dataset for model input CourseRecommender.ModelInput sampleData = new CourseRecommender.ModelInput()
    { 
      UserId = @"8c5ee22e-4c4f-0000-0000-068628b2a64d", 
      PageId = @"0034ce1d-7073-4384-abc4-7ecec25909ed", 
    }; 
    
    // Make a single prediction on the sample data and print results 
    var predictionResult = PageRecommender.Predict(sampleData); 

    Summary

    This shows how quick and easy it is to use the OTB feature and tools from Visual Studio to create a machine learning model and to scaffold code to be able to consume it.

    However, straight out of the box, the scaffold code lacks some key features that we will need, if we are using this along side the cortex processing engine. Namely, we will need to be able to do the following on a regular basis:

    • Load new data
    • Retrain the model
    • Save the model to disk
    • Load the model from disk

    Next up in the series: Building our Page Recommendation Model

    Leave a Reply

    Your email address will not be published. Required fields are marked *