Created
December 3, 2019 14:19
-
-
Save icebeam7/26e8933f0d54d8611c5746406bef7ffb to your computer and use it in GitHub Desktop.
MovieRecommender: BuildTrainModel code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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