predictionio-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From shins...@apache.org
Subject incubator-predictionio-template-recommender git commit: closes apache/incubator-predictionio-template-recommender#17
Date Thu, 11 May 2017 23:46:23 GMT
Repository: incubator-predictionio-template-recommender
Updated Branches:
  refs/heads/develop fab31fbfa -> 5cadb5e3b


closes apache/incubator-predictionio-template-recommender#17


Project: http://git-wip-us.apache.org/repos/asf/incubator-predictionio-template-recommender/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-predictionio-template-recommender/commit/5cadb5e3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-predictionio-template-recommender/tree/5cadb5e3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-predictionio-template-recommender/diff/5cadb5e3

Branch: refs/heads/develop
Commit: 5cadb5e3bf67a769f90069a49b2856b62790836a
Parents: fab31fb
Author: Naoki Takezoe <takezoe@apache.org>
Authored: Fri May 12 08:45:37 2017 +0900
Committer: Shinsuke Sugaya <shinsuke@apache.org>
Committed: Fri May 12 08:45:37 2017 +0900

----------------------------------------------------------------------
 src/main/scala/ALSModel.scala   | 8 ++++----
 src/main/scala/Engine.scala     | 4 ++--
 src/main/scala/Evaluation.scala | 9 ++++-----
 3 files changed, 10 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-predictionio-template-recommender/blob/5cadb5e3/src/main/scala/ALSModel.scala
----------------------------------------------------------------------
diff --git a/src/main/scala/ALSModel.scala b/src/main/scala/ALSModel.scala
index afec745..6318b5e 100644
--- a/src/main/scala/ALSModel.scala
+++ b/src/main/scala/ALSModel.scala
@@ -5,8 +5,8 @@ package org.apache.spark.mllib.recommendation
 
 import org.example.recommendation.ALSAlgorithmParams
 
-import org.apache.predictionio.controller.IPersistentModel
-import org.apache.predictionio.controller.IPersistentModelLoader
+import org.apache.predictionio.controller.PersistentModel
+import org.apache.predictionio.controller.PersistentModelLoader
 import org.apache.predictionio.data.storage.BiMap
 
 import org.apache.spark.SparkContext
@@ -20,7 +20,7 @@ class ALSModel(
     val userStringIntMap: BiMap[String, Int],
     val itemStringIntMap: BiMap[String, Int])
   extends MatrixFactorizationModel(rank, userFeatures, productFeatures)
-  with IPersistentModel[ALSAlgorithmParams] {
+  with PersistentModel[ALSAlgorithmParams] {
 
   def save(id: String, params: ALSAlgorithmParams,
     sc: SparkContext): Boolean = {
@@ -48,7 +48,7 @@ class ALSModel(
 }
 
 object ALSModel
-  extends IPersistentModelLoader[ALSAlgorithmParams, ALSModel] {
+  extends PersistentModelLoader[ALSAlgorithmParams, ALSModel] {
   def apply(id: String, params: ALSAlgorithmParams,
     sc: Option[SparkContext]) = {
     new ALSModel(

http://git-wip-us.apache.org/repos/asf/incubator-predictionio-template-recommender/blob/5cadb5e3/src/main/scala/Engine.scala
----------------------------------------------------------------------
diff --git a/src/main/scala/Engine.scala b/src/main/scala/Engine.scala
index 20a5521..bbec828 100644
--- a/src/main/scala/Engine.scala
+++ b/src/main/scala/Engine.scala
@@ -1,6 +1,6 @@
 package org.example.recommendation
 
-import org.apache.predictionio.controller.IEngineFactory
+import org.apache.predictionio.controller.EngineFactory
 import org.apache.predictionio.controller.Engine
 
 case class Query(
@@ -21,7 +21,7 @@ case class ItemScore(
   score: Double
 ) extends Serializable
 
-object RecommendationEngine extends IEngineFactory {
+object RecommendationEngine extends EngineFactory {
   def apply() = {
     new Engine(
       classOf[DataSource],

http://git-wip-us.apache.org/repos/asf/incubator-predictionio-template-recommender/blob/5cadb5e3/src/main/scala/Evaluation.scala
----------------------------------------------------------------------
diff --git a/src/main/scala/Evaluation.scala b/src/main/scala/Evaluation.scala
index e0eebe1..acc85ff 100644
--- a/src/main/scala/Evaluation.scala
+++ b/src/main/scala/Evaluation.scala
@@ -24,12 +24,11 @@ case class PrecisionAtK(k: Int, ratingThreshold: Double = 2.0)
     // If there is no positive results, Precision is undefined. We don't consider this case
in the
     // metrics, hence we return None.
     if (positives.size == 0) {
-      return None
+      None
+    } else {
+      val tpCount: Int = p.itemScores.take(k).filter(is => positives(is.item)).size
+      Some(tpCount.toDouble / math.min(k, positives.size))
     }
-
-    val tpCount: Int = p.itemScores.take(k).filter(is => positives(is.item)).size
-
-    Some(tpCount.toDouble / math.min(k, positives.size))
   }
 }
 


Mime
View raw message