blob: 6ddc67def7dd675216243687e47bdc9a1859f651 [file] [log] [blame]
package org.template.classification
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 io.prediction.controller.Workflow
import org.apache.spark.SparkContext
import org.apache.spark.SparkContext._
import org.apache.spark.rdd.RDD
case class Precision
extends AverageMetric[EmptyEvaluationInfo,
Query, PredictedResult, ActualResult] {
def header: String = "Precision"
def calculate(query: Query, predicted: PredictedResult, actual: ActualResult)
: Double = (if (predicted.label == actual.label) 1.0 else 0.0)
}
object PrecisionEvaluation
extends Evaluation with EngineParamsGenerator {
// Define Engine and Metric used in Evaluation
engineMetric = (ClassificationEngine(), new Precision())
// Define list of EngineParams used in Evaluation
// First, we define the base engine params. It specifies the appId from which
// the data is read, and a evalK parameter is used to define the
// cross-validation.
private[this] val baseEP = EngineParams(
dataSourceParams = DataSourceParams(appId = 18, evalK = Some(5)))
// Second, we specify the engine params list by explicitly listing all
// algorithm parameters. In this case, we evaluate 3 engine params, each with
// a different algorithm params value.
engineParamsList = Seq(
baseEP.copy(algorithmParamsList = Seq(("naive", AlgorithmParams(10.0)))),
baseEP.copy(algorithmParamsList = Seq(("naive", AlgorithmParams(100.0)))),
baseEP.copy(algorithmParamsList = Seq(("naive", AlgorithmParams(1000.0)))))
}
// To be replaced by "pio eval xxx"
object Eval {
def main(args: Array[String]) {
Workflow.runEvaluation(PrecisionEvaluation, PrecisionEvaluation)
}
}