anonymous
anonymous

Reputation: 4064

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.

Upvotes: 3

Views: 2597

Answers (2)

Alexandre Daubricourt
Alexandre Daubricourt

Reputation: 4903

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

Upvotes: 2

lqdev
lqdev

Reputation: 11

In this particular example because of the task being performed you are limited to the scope of observations the model was trained on and can make predictions on that set. As you mentioned, a good way to go about it would be to re-train. I haven't tried this myself, but you might want to try one of the following:

  1. Run Fit function again using the new data you want to train with as your input. Not only should the model persist it's previous training but also re-train using the additional data you have provided it with.
  2. Save model to file, Load persisted model, Run Fit function like above.

Upvotes: 1

Related Questions