Skip to content

Instantly share code, notes, and snippets.

@icebeam7
Created Dec 3, 2019
Embed
What would you like to do?
MovieRecommender: BuildTrainModel code
public static ITransformer BuildTrainModel(MLContext mlContext, IDataView trainingDataView)
{
var catalog = mlContext.Transforms.Conversion;
IEstimator<ITransformer> estimator = catalog.MapValueToKey(outputColumnName: "userIdEncoded", inputColumnName: "userId")
.Append(catalog.MapValueToKey(outputColumnName: "movieIdEncoded", inputColumnName: "movieId"));
var options = new MatrixFactorizationTrainer.Options
{
MatrixColumnIndexColumnName = "userIdEncoded",
MatrixRowIndexColumnName = "movieIdEncoded",
LabelColumnName = "Label",
NumberOfIterations = 20,
ApproximationRank = 100
};
var trainerEstimator = estimator.Append(mlContext.Recommendation().Trainers.MatrixFactorization(options));
Console.WriteLine("=============== Training the model ===============");
ITransformer model = trainerEstimator.Fit(trainingDataView);
return model;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment