- Learning Salesforce Einstein
- Mohith Shrivastava
- 201字
- 2021-07-02 21:44:04
Predicted response design
The Predicted response is also of the JSON format. A simple example for our example of the result is the following JSON:
{
"itemScores":[
{"item":22,"score":4.07},
{"item":62,"score":4.05},
{"item":75,"score":4.04},
{"item":68,"score":3.81}
]
}
The PreictedResult.java file has the class for the preceding conversion:
package org.template.recommendation;
import java.io.Serializable;
import java.util.List;
public class PredictedResult implements Serializable{
private final List<ItemScore> itemScores;
public PredictedResult(List<ItemScore> itemScores) {
this.itemScores = itemScores;
}
public List<ItemScore> getItemScores() {
return itemScores;
}
@Override
public String toString() {
return "PredictedResult{" +
"itemScores=" + itemScores +
'}';
}
}
The Scala version of the code uses the case class, and you can define the query class and the predictedResult class as a case class:
package MyRecommedationScala
import org.apache.predictionio.controller.IEngineFactory
import org.apache.predictionio.controller.Engine
case class Query(
user: String,
num: Int,
categories: Option[Set[String]],
whiteList: Option[Set[String]],
blackList: Option[Set[String]]
) extends Serializable
case class PredictedResult(
itemScores: Array[ItemScore]
) extends Serializable
case class ItemScore(
item: String,
score: Double
) extends Serializable
object ECommerceRecommendationEngine extends IEngineFactory {
def apply() = {
new Engine(
classOf[DataSource],
classOf[Preparator],
Map("ecomm" -> classOf[ECommAlgorithm]),
classOf[Serving])
}
}
Case classes in Scala are regular classes that are immutable by default, decomposable through pattern matching, compared by structural equality, and you can instantiate and operate on them.
推薦閱讀
- LabVIEW Graphical Programming Cookbook
- R語言經典實例(原書第2版)
- 少年輕松趣編程:用Scratch創作自己的小游戲
- Ray分布式機器學習:利用Ray進行大模型的數據處理、訓練、推理和部署
- 微信小程序開發實戰:設計·運營·變現(圖解案例版)
- Unity 2017 Game AI Programming(Third Edition)
- Photoshop CC移動UI設計案例教程(全彩慕課版·第2版)
- Apache Solr PHP Integration
- Clojure High Performance Programming(Second Edition)
- 金融商業數據分析:基于Python和SAS
- Learning PrimeFaces Extensions Development
- Tkinter GUI Application Development Blueprints
- Opa Application Development
- Python for Secret Agents
- Instant Buildroot