Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.ML" Version="0.11.0" />
<PackageReference Include="Microsoft.ML.Recommender" Version="0.11.0" />
<PackageReference Include="Microsoft.ML" Version="1.0.0-preview" />
<PackageReference Include="Microsoft.ML.Recommender" Version="0.12.0-preview" />
</ItemGroup>

<ItemGroup>
Expand Down
15 changes: 6 additions & 9 deletions machine-learning/tutorials/MovieRecommendation/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
using System.IO;
using Microsoft.ML;
using Microsoft.ML.Trainers;
using Microsoft.ML.Data;
using Microsoft.Data.DataView;
// </SnippetUsingStatements>

namespace MovieRecommendation
Expand Down Expand Up @@ -43,7 +41,7 @@ static void Main(string[] args)

// Save model
// <SnippetSaveModelMain>
SaveModel(mlContext, model);
SaveModel(mlContext, trainingDataView.Schema, model);
// </SnippetSaveModelMain>
}

Expand Down Expand Up @@ -103,11 +101,11 @@ public static void EvaluateModel(MLContext mlContext, IDataView testDataView, IT
// </SnippetTransform>

// <SnippetEvaluate>
var metrics = mlContext.Regression.Evaluate(prediction, label: DefaultColumnNames.Label, score: DefaultColumnNames.Score);
var metrics = mlContext.Regression.Evaluate(prediction, labelColumnName: "Label", scoreColumnName: "Score");
// </SnippetEvaluate>

// <SnippetPrintMetrics>
Console.WriteLine("Rms: " + metrics.Rms.ToString());
Console.WriteLine("Root Mean Squared Error : " + metrics.RootMeanSquaredError.ToString());
Console.WriteLine("RSquared: " + metrics.RSquared.ToString());
// </SnippetPrintMetrics>
}
Expand All @@ -117,7 +115,7 @@ public static void UseModelForSinglePrediction(MLContext mlContext, ITransformer
{
// <SnippetPredictionEngine>
Console.WriteLine("=============== Making a prediction ===============");
var predictionEngine = model.CreatePredictionEngine<MovieRating, MovieRatingPrediction>(mlContext);
var predictionEngine = mlContext.Model.CreatePredictionEngine<MovieRating, MovieRatingPrediction>(model);
// </SnippetPredictionEngine>

// Create test input & make single prediction
Expand All @@ -140,15 +138,14 @@ public static void UseModelForSinglePrediction(MLContext mlContext, ITransformer
}

//Save model
public static void SaveModel(MLContext mlContext, ITransformer model)
public static void SaveModel(MLContext mlContext, DataViewSchema trainingDataViewSchema, ITransformer model)
{
// Save the trained model to .zip file
// <SnippetSaveModel>
var modelPath = Path.Combine(Environment.CurrentDirectory, "Data", "MovieRecommenderModel.zip");

Console.WriteLine("=============== Saving the model to a file ===============");
using (var fs = new FileStream(modelPath, FileMode.Create, FileAccess.Write, FileShare.Write))
mlContext.Model.Save(model, fs);
mlContext.Model.Save(model, trainingDataViewSchema, modelPath);
// </SnippetSaveModel>
}

Expand Down