Reputation: 11
I developed a product recommender using ML.NET matrix factorization. The train data contains only pairs of product ids, so I adapted the trainer accordingly to Microsoft documentation.
There are two problems:
1- Each time I train the model using exactly the same data I get different top scored results for the same product.
2- Sometimes results don't even make sense since when asking for suggestions for a man product, woman products are suggested. The train data product pairs are always pairs of man products or pairs of woman products, never mixed.
The data process pipeline seems correct:
The product ids are text so I normalize them using ML.NET MapValueToKey.
var dataProcessPipeline = mlContext.Transforms.Conversion
.MapValueToKey("CoPurchaseProductIdEncoded", "CoPurchaseProductId")
.Append(MLContext.Transforms.Conversion.MapValueToKey("ProductIdEncoded","ProductId"));
The option passed to the trainer are:
MatrixFactorizationTrainer.Options options = new MatrixFactorizationTrainer.Options();
options.MatrixColumnIndexColumnName = "ProductIdEncoded";
options.MatrixRowIndexColumnName = "CoPurchaseProductIdEncoded";
options.LabelColumnName = "Label";
options.LossFunction = MatrixFactorizationTrainer.LossFunctionType.SquareLossOneClass;
options.Alpha = 0.01;
options.Lambda = 0.025;
options.NumberOfIterations = 500;
var est = MLContext.Recommendation().Trainers.MatrixFactorization(options);
Upvotes: 0
Views: 247
Reputation: 41403
You don't show how you build your MLContext
, but I suspect you are not passing in a fixed seed
value. Doing so would give you deterministic results. See the remarks section in the documentation.
These models are not perfect, so there will be some bleed over to the different product groups. If you want to restrict the recommendations to distinct groups, you could train two models or filter the recommendations afterward.
Upvotes: 0