本文整理汇总了Scala中org.dmg.pmml.PMML类的典型用法代码示例。如果您正苦于以下问题:Scala PMML类的具体用法?Scala PMML怎么用?Scala PMML使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PMML类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: LRPmmlEvaluator
//设置package包名称以及导入依赖的类
package com.inneractive.cerberus
import java.io.{File, FileInputStream}
import java.util
import javax.xml.transform.stream.StreamSource
import org.dmg.pmml.{FieldName, Model, PMML}
import org.jpmml.evaluator.{EvaluatorUtil, FieldValue, ModelEvaluator, ModelEvaluatorFactory}
import org.jpmml.model.JAXBUtil
import scala.collection.Map
import scala.util.Try
class LRPmmlEvaluator(modelLocation: String, threshold: Option[Double]) {
val inputStream = new FileInputStream(new File(modelLocation, "/model/PMML/PMML.xml"))
val pmmModel: PMML = JAXBUtil.unmarshalPMML(new StreamSource(inputStream))
val evaluatorFactory: ModelEvaluatorFactory = ModelEvaluatorFactory.newInstance()
val evaluator: ModelEvaluator[_ <: Model] = evaluatorFactory.newModelManager(pmmModel)
val activeFields: util.List[FieldName] = evaluator.getActiveFields
val targetFields: util.List[FieldName] = EvaluatorUtil.getTargetFields(evaluator)
val outputFields: util.List[FieldName] = EvaluatorUtil.getOutputFields(evaluator)
def arguments(eval: FieldName => (FieldName, FieldValue)) = (activeFields map eval).toMap
def getResults(result: java.util.Map[FieldName, _]) = {
val targets = targetFields map (f => EvaluatorUtil.decode(result.get(f)))
val outputs = outputFields map (f => result.get(f))
Tuple3(targets.head.asInstanceOf[Double], outputs.head.asInstanceOf[Double], outputs(1).asInstanceOf[Double])
}
def callEvaluator(params : Map[FieldName, _]) = getResults(evaluator.evaluate(params))
def predict(features: Features) = Try {
val r = callEvaluator(arguments((f: FieldName) => {
val value = features.vector(f.getValue)
val activeValue = evaluator.prepare(f, value)
(f, activeValue)
}))
new Prediction("", if (r._1 == 0.0) true else false, if (r._1 == 0) r._2 else r._3)
}
}