-
Notifications
You must be signed in to change notification settings - Fork 5
/
Evaluation.scala
53 lines (41 loc) · 1.55 KB
/
Evaluation.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package detrevid.predictionio.loadforecasting
import io.prediction.controller.AverageMetric
import io.prediction.controller.EmptyEvaluationInfo
import io.prediction.controller.EngineParams
import io.prediction.controller.EngineParamsGenerator
import io.prediction.controller.Evaluation
import org.apache.spark.SparkContext
import org.apache.spark.rdd.RDD
import math.{pow, sqrt}
case class RMSEMetric()
extends AverageMetric[EmptyEvaluationInfo, Query, PredictedResult, ActualResult] {
override
def calculate(sc: SparkContext,
evalDataSet: Seq[(EmptyEvaluationInfo,
RDD[(Query, PredictedResult, ActualResult)])]): Double = {
sqrt(super.calculate(sc, evalDataSet))
}
def calculate(query: Query, predicted: PredictedResult, actual: ActualResult): Double =
pow(predicted.label - actual.label, 2)
override
def compare(r0: Double, r1: Double): scala.Int = {
-1 * super.compare(r0, r1)
}
}
object RMSEEvaluation extends Evaluation {
engineMetric = (ForecastingEngine(), new RMSEMetric())
}
object EngineParamsList extends EngineParamsGenerator {
private[this] val baseEP = EngineParams(
dataSourceParams = DataSourceParams(appName = "EnergyForecaster", evalK = Some(5)))
engineParamsList = Seq(
baseEP.copy(
algorithmParamsList = Seq(
("alg", AlgorithmParams(iterations = 4096, miniBatchFraction = 1.0, stepSize = 0.9))
)),
baseEP.copy(
algorithmParamsList = Seq(
("alg", AlgorithmParams(iterations = 4096, miniBatchFraction = 0.5, stepSize = 1.0))
))
)
}