Skip to content

Instantly share code, notes, and snippets.

Last active January 13, 2019 18:15
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
using BookRecommenderShared.Configuration;
using BookRecommenderShared.Models;
using Microsoft.ML;
using Microsoft.ML.Core.Data;
using System;
using System.IO;
namespace BookRecommenderPredictor
class Program
static void Main(string[] args)
var mlContext = new MLContext();
ITransformer loadedModel;
Console.WriteLine("Reading the model from disk");
// Load the model into memory
using (var file = File.OpenRead(Path.Combine(Environment.CurrentDirectory, Filenames.TrainedModel)))
loadedModel = mlContext.Model.Load(file);
Console.WriteLine($"The model was read from file: {Filenames.TrainedModel}");
// Create the prediction function from the loaded model
var predictionFunction = loadedModel.CreatePredictionEngine<BookRating, BookRatingPrediction>(mlContext);
// Predict the outcome
var bookPrediction = predictionFunction.Predict(new BookRating
user = 91,
bookid = 10365
Console.WriteLine($"Predicted rating: {Math.Round(bookPrediction.Score, 1)}");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment