Ejemplo n.º 1
0
        public override void Evaluate(Split split, EvaluationContext context)
        {
            if (DataType == DataType.Ratings)
            {
                var results = new Dictionary <string, string>();
                results.Add("LibFmTrainRMSE", string.Format("{0:0.0000}", _trainRmse));
                results.Add("LibFmTestRMSE", string.Format("{0:0.0000}", _testRmse));
                results.Add("LibFmLowestRMSE", string.Format("{0:0.0000}", _lowestTestRmse));
                results.Add("LowestIteration", _lowestIter.ToString());

                context.AddResultsSet("libfm", results);

                // test split and tested predictions (in the file) have the same order
                List <float> testPredictions = File.ReadAllLines(_outputPath).Select(l => float.Parse(l)).ToList();
                int          i = 0;
                foreach (var feedback in split.Test)
                {
                    // no need to call Predict(feedback) becuase the predictions are already saved in the output file
                    context.PredictedScores.Add(feedback, testPredictions[i++]);
                }
            }

            PureEvaluationTime = (int)Wrap.MeasureTime(delegate()
            {
                context.Evaluators.ForEach(e => e.Evaluate(context, this, split));
            }).TotalMilliseconds;
        }