Skip to content

Commit c1c9b66

Browse files
prathyusha12345JRAlexander
authored andcommitted
Migrate Movie recommender to 1.0.0-preview (#839)
* Upgraded TaxiFare solution to v0.11 * Migrated Movie Recommender to 1.0.0-preview * Removed unnecessary code I added for debugging.
1 parent 6fd8121 commit c1c9b66

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

machine-learning/tutorials/MovieRecommendation/MovieRecommendation.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="Microsoft.ML" Version="0.11.0" />
10-
<PackageReference Include="Microsoft.ML.Recommender" Version="0.11.0" />
9+
<PackageReference Include="Microsoft.ML" Version="1.0.0-preview" />
10+
<PackageReference Include="Microsoft.ML.Recommender" Version="0.12.0-preview" />
1111
</ItemGroup>
1212

1313
<ItemGroup>

machine-learning/tutorials/MovieRecommendation/Program.cs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
using System.IO;
44
using Microsoft.ML;
55
using Microsoft.ML.Trainers;
6-
using Microsoft.ML.Data;
7-
using Microsoft.Data.DataView;
86
// </SnippetUsingStatements>
97

108
namespace MovieRecommendation
@@ -43,7 +41,7 @@ static void Main(string[] args)
4341

4442
// Save model
4543
// <SnippetSaveModelMain>
46-
SaveModel(mlContext, model);
44+
SaveModel(mlContext, trainingDataView.Schema, model);
4745
// </SnippetSaveModelMain>
4846
}
4947

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

105103
// <SnippetEvaluate>
106-
var metrics = mlContext.Regression.Evaluate(prediction, label: DefaultColumnNames.Label, score: DefaultColumnNames.Score);
104+
var metrics = mlContext.Regression.Evaluate(prediction, labelColumnName: "Label", scoreColumnName: "Score");
107105
// </SnippetEvaluate>
108106

109107
// <SnippetPrintMetrics>
110-
Console.WriteLine("Rms: " + metrics.Rms.ToString());
108+
Console.WriteLine("Root Mean Squared Error : " + metrics.RootMeanSquaredError.ToString());
111109
Console.WriteLine("RSquared: " + metrics.RSquared.ToString());
112110
// </SnippetPrintMetrics>
113111
}
@@ -117,7 +115,7 @@ public static void UseModelForSinglePrediction(MLContext mlContext, ITransformer
117115
{
118116
// <SnippetPredictionEngine>
119117
Console.WriteLine("=============== Making a prediction ===============");
120-
var predictionEngine = model.CreatePredictionEngine<MovieRating, MovieRatingPrediction>(mlContext);
118+
var predictionEngine = mlContext.Model.CreatePredictionEngine<MovieRating, MovieRatingPrediction>(model);
121119
// </SnippetPredictionEngine>
122120

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

142140
//Save model
143-
public static void SaveModel(MLContext mlContext, ITransformer model)
141+
public static void SaveModel(MLContext mlContext, DataViewSchema trainingDataViewSchema, ITransformer model)
144142
{
145143
// Save the trained model to .zip file
146144
// <SnippetSaveModel>
147145
var modelPath = Path.Combine(Environment.CurrentDirectory, "Data", "MovieRecommenderModel.zip");
148146

149147
Console.WriteLine("=============== Saving the model to a file ===============");
150-
using (var fs = new FileStream(modelPath, FileMode.Create, FileAccess.Write, FileShare.Write))
151-
mlContext.Model.Save(model, fs);
148+
mlContext.Model.Save(model, trainingDataViewSchema, modelPath);
152149
// </SnippetSaveModel>
153150
}
154151

0 commit comments

Comments
 (0)