Last change
on this file since 2504 was
1888,
checked in by gkronber, 15 years ago
|
Added simple evaluators for mean absolute percentage error, mean absolute percentage of range error and, variance accounted for. #635 (Plugin HeuristicLab.Modeling as a common basis for all data-based modeling algorithms)
|
File size:
1.0 KB
|
Line | |
---|
1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using HeuristicLab.Core;
|
---|
6 | using HeuristicLab.Data;
|
---|
7 | using HeuristicLab.DataAnalysis;
|
---|
8 |
|
---|
9 | namespace HeuristicLab.Modeling {
|
---|
10 | public class SimpleMSEEvaluator : SimpleEvaluatorBase {
|
---|
11 |
|
---|
12 | public override string OutputVariableName {
|
---|
13 | get {
|
---|
14 | return "MSE";
|
---|
15 | }
|
---|
16 | }
|
---|
17 | public override double Evaluate(double[,] values) {
|
---|
18 | return Calculate(values);
|
---|
19 | }
|
---|
20 |
|
---|
21 | public static double Calculate(double[,] values) {
|
---|
22 | double sse = 0;
|
---|
23 | double cnt = 0;
|
---|
24 | for (int i = 0; i < values.GetLength(0); i++) {
|
---|
25 | double estimated = values[i, 0];
|
---|
26 | double target = values[i, 1];
|
---|
27 | if (!double.IsNaN(estimated) && !double.IsInfinity(estimated) &&
|
---|
28 | !double.IsNaN(target) && !double.IsInfinity(target)) {
|
---|
29 | double error = estimated - target;
|
---|
30 | sse += error * error;
|
---|
31 | cnt++;
|
---|
32 | }
|
---|
33 | }
|
---|
34 |
|
---|
35 | double mse = sse / cnt;
|
---|
36 | return mse;
|
---|
37 | }
|
---|
38 | }
|
---|
39 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.