Skip to content

Commit a26eca7

Browse files
authored
Fix unassigned public field (#1467)
Fix an unassigned field for matrix factorization.
1 parent 9d33efe commit a26eca7

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/Microsoft.ML.Recommender/MatrixFactorizationPredictor.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,7 @@ public MatrixFactorizationPredictionTransformer(IHostEnvironment env, MatrixFact
403403
MatrixColumnIndexColumnType = trainSchema.GetColumnType(xCol);
404404
if (!trainSchema.TryGetColumnIndex(MatrixRowIndexColumnName, out int yCol))
405405
throw Host.ExceptSchemaMismatch(nameof(yCol), RecommenderUtils.MatrixRowIndexKind.Value, MatrixRowIndexColumnName);
406+
MatrixRowIndexColumnType = trainSchema.GetColumnType(yCol);
406407

407408
BindableMapper = ScoreUtils.GetSchemaBindableMapper(Host, model);
408409

test/Microsoft.ML.Tests/TrainerEstimators/MatrixFactorizationTests.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,18 @@ public void MatrixFactorizationInMemoryData()
181181
// Train a matrix factorization model.
182182
var model = pipeline.Fit(dataView);
183183

184+
// Check if the expected types in the trained model are expected.
185+
Assert.True(model.MatrixColumnIndexColumnName == "MatrixColumnIndex");
186+
Assert.True(model.MatrixRowIndexColumnName == "MatrixRowIndex");
187+
Assert.True(model.MatrixColumnIndexColumnType.IsKey);
188+
Assert.True(model.MatrixRowIndexColumnType.IsKey);
189+
var matColKeyType = model.MatrixColumnIndexColumnType.AsKey;
190+
Assert.True(matColKeyType.Min == _synthesizedMatrixFirstColumnIndex);
191+
Assert.True(matColKeyType.Count == _synthesizedMatrixColumnCount);
192+
var matRowKeyType = model.MatrixRowIndexColumnType.AsKey;
193+
Assert.True(matRowKeyType.Min == _synthesizedMatrixFirstRowIndex);
194+
Assert.True(matRowKeyType.Count == _synthesizedMatrixRowCount);
195+
184196
// Apply the trained model to the training set
185197
var prediction = model.Transform(dataView);
186198

0 commit comments

Comments
 (0)