Search code examples
machine-learningmatrix-factorizationml.net

Update a trained model in ML.NET


This example shows how to use matrix factorization to build a recommendation system. This example is particulary suitable for a dataset with only two related ids like user id and product id that the corresponding user has purchased.

Based on this example, I prepared an input data like below.

[UserId] [ProductId]
3    1
3    15
3    23
5    9
5    1
8    2
8    1
.
.

And change the column name, making TextLoader.

var reader = ctx.Data.TextReader(new TextLoader.Arguments()
{
     Separator = "tab",
     HasHeader = true,
     Column = new[]
     {
              new TextLoader.Column("Label", DataKind.R4, 0),
              new TextLoader.Column("UserId", DataKind.U4, new [] { new TextLoader.Range(0) }, new KeyRange(0, 100000)),
              new TextLoader.Column("ProductId", DataKind.U4, new [] { new TextLoader.Range(1) }, new KeyRange(0, 300))
     }
     });

It works great. It recommends a list of products that the target user may purchase with individual scores. However, it doesn't work with a new customer data that didn't exist in the initial input data, say UserId 1, it gives score NaN as a result of the prediction.

Retraining the model could be an obvious answer, but it seems futile to retrain the model everytime a new data comes in. I think there's definitely a way to update the existing model but I cannot find the relevant documentation, APIs, or a sample anywhere. I ended up leaving a question in the official github of ML.NET but I've got no answers so far.

Question would be very simple, in a nutshell, how can I update a trained model in ML.NET? Linking a relevant source of information would be greatly appreciated too.


Solution

  • As of 2021:

    The re-training process is described in details here: https://learn.microsoft.com/en-us/dotnet/machine-learning/how-to-guides/retrain-model-ml-net