0

So I have the following test 2 tests

This test keeps returning the first answer it gives and mimics the way we predict with live data.

if (_bModelPredictor is null)
    _bModelPredictor = bModel.MakePredictionFunction<TestClass, Prediction>(mlContext);

if(assumption is null)
    assumption = new Prediction();  

_bModelPredictor.Predict(new TestClass(myMapper),ref assumption);

DoSomethingWith(assumption );

if the first score is say "XYZ" all following tests are going to give the same answer.

This setup where I test the model with new database data however works:

var result = new Prediction();
var evalution[]= Database.GetTestArray();
var predictor=bModel.MakePredictionFunction<TestClass, Prediction>(mlContext);
for (var i = 0; i < evalution.Length; i++)
{
    r++;
    //holds the value we think it should have (source database)
    var expect = evalution[i].Prediction;

    evalution[i].Trend = string.Empty;

    //evaluates and puts the trend in "result"
    predictor.Predict(new TestClass(evalution[i]),ref result);
    score+= result.actual==expect? 1 :-1;
    ...
}

why is the first one returning a "cashed" answer?

Walter Verhoeven
  • 3,867
  • 27
  • 36
  • Maybe because of the `if` checks? – Hackerman Nov 21 '18 at 22:11
  • good question, The if's create the PredictionFunction when it needs it, once created in memory one should re-use them. also the loop re-uses the prediction method as well as the class used to hold the prediction. in the documentation this is recommended. – Walter Verhoeven Nov 22 '18 at 11:11
  • please add a working minimal examlple. As of right now, crucial information is missing, so I cannot help – Zruty Nov 25 '18 at 21:28
  • can it be that on WinForms you need a special MLContext? – Walter Verhoeven Nov 30 '18 at 01:20
  • I looked at the source code comments above MLContext and noted it states that it needs to execute on the application's Main thread. If that's the case then that would explain why I get errors as it is on a background thread listning to exchange prices…. – Walter Verhoeven Nov 30 '18 at 12:46

0 Answers0