0
0

Fix evaluate method

This commit is contained in:
Serghei Cebotari 2024-01-12 00:23:58 +03:00
parent 3fc8fc9db6
commit fb94d14854

View File

@ -9,7 +9,6 @@ public class RhSolutionsMLBuilder
private static string _testDataPath = Path.Combine(_appPath, "..", "..", "..", "..", "TestData", "*"); private static string _testDataPath = Path.Combine(_appPath, "..", "..", "..", "..", "TestData", "*");
private static MLContext _mlContext = new MLContext(seed: 0); private static MLContext _mlContext = new MLContext(seed: 0);
private static ITransformer? _trainedModel = null;
public static void RebuildModel() public static void RebuildModel()
{ {
@ -20,10 +19,13 @@ public class RhSolutionsMLBuilder
SaveModelAsFile(_mlContext, _trainDataView.Schema, _trainedModel); SaveModelAsFile(_mlContext, _trainDataView.Schema, _trainedModel);
} }
public static MulticlassClassificationMetrics? EvaluateModel() public static MulticlassClassificationMetrics EvaluateModel()
{ {
var testDataView = _mlContext.Data.LoadFromTextFile<Product>(_testDataPath, hasHeader: false, separatorChar: ';'); var testDataView = _mlContext.Data.LoadFromTextFile<Product>(_testDataPath, hasHeader: false, separatorChar: ';');
return _mlContext.MulticlassClassification.Evaluate(_trainedModel?.Transform(testDataView)); MLContext mlContext = new(seed: 0);
string modelPath = Path.Combine(_appPath, "..", "..", "..", "..", "Models", "model.zip");
var trainedModel = mlContext.Model.Load(modelPath, out _);
return _mlContext.MulticlassClassification.Evaluate(trainedModel.Transform(testDataView));
} }
private static IEstimator<ITransformer> ProcessData() private static IEstimator<ITransformer> ProcessData()