predictionio-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From don...@apache.org
Subject [41/52] [abbrv] incubator-predictionio git commit: Update travis build to use the new python test framework
Date Tue, 09 Aug 2016 21:43:49 GMT
Update travis build to use the new python test framework


Project: http://git-wip-us.apache.org/repos/asf/incubator-predictionio/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-predictionio/commit/3a1aee70
Tree: http://git-wip-us.apache.org/repos/asf/incubator-predictionio/tree/3a1aee70
Diff: http://git-wip-us.apache.org/repos/asf/incubator-predictionio/diff/3a1aee70

Branch: refs/heads/develop
Commit: 3a1aee708b6b43209c502212630a4034b50c9962
Parents: 1b437fa
Author: Marcin Ziemiński <zieminm@gmail.com>
Authored: Wed Aug 3 15:56:22 2016 -0700
Committer: Marcin Ziemiński <zieminm@gmail.com>
Committed: Wed Aug 3 16:23:37 2016 -0700

----------------------------------------------------------------------
 testing/script.travis.sh                        |   2 +-
 .../recommendation-engine/README.md             |  42 ------
 .../recommendation-engine/build.sbt             |  12 --
 .../data/import_eventserver.py                  |  56 --------
 .../recommendation-engine/data/send_query.py    |   7 -
 .../recommendation-engine/engine.json           |  21 ---
 .../recommendation-engine/project/assembly.sbt  |   1 -
 .../recommendation-engine/project/pio-build.sbt |   1 -
 .../src/main/scala/ALSAlgorithm.scala           | 138 -------------------
 .../src/main/scala/ALSModel.scala               |  63 ---------
 .../src/main/scala/DataSource.scala             | 103 --------------
 .../src/main/scala/Engine.scala                 |  32 -----
 .../src/main/scala/Evaluation.scala             |  89 ------------
 .../src/main/scala/Preparator.scala             |  19 ---
 .../src/main/scala/Serving.scala                |  13 --
 .../recommendation-engine/template.json         |   1 -
 testing/simple_scenario/run_scenario.sh         |  34 -----
 17 files changed, 1 insertion(+), 633 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-predictionio/blob/3a1aee70/testing/script.travis.sh
----------------------------------------------------------------------
diff --git a/testing/script.travis.sh b/testing/script.travis.sh
index bb84d08..38771f8 100755
--- a/testing/script.travis.sh
+++ b/testing/script.travis.sh
@@ -17,5 +17,5 @@ else
   REPO=`pwd`
 
   ./testing/run_docker.sh $METADATA_REP $EVENTDATA_REP $MODELDATA_REP \
-    $REPO '/pio_host/testing/simple_scenario/run_scenario.sh'
+    $REPO 'python3 /tests/pio_tests/tests.py --no-shell-stdout --no-shell-stderr'
 fi

http://git-wip-us.apache.org/repos/asf/incubator-predictionio/blob/3a1aee70/testing/simple_scenario/recommendation-engine/README.md
----------------------------------------------------------------------
diff --git a/testing/simple_scenario/recommendation-engine/README.md b/testing/simple_scenario/recommendation-engine/README.md
deleted file mode 100644
index 6566db4..0000000
--- a/testing/simple_scenario/recommendation-engine/README.md
+++ /dev/null
@@ -1,42 +0,0 @@
-# Recommendation Template
-
-## Documentation
-
-Please refer to http://docs.prediction.io/templates/recommendation/quickstart/
-
-## Versions
-
-### develop
-
-### v0.3.2
-
-- Fix incorrect top items in batchPredict() (issue #5)
-
-### v0.3.1
-
-- Add Evaluation module and modify DataSource for it
-
-### v0.3.0
-
-- update for PredictionIO 0.9.2, including:
-
-  - use new PEventStore API
-  - use appName in DataSource parameter
-
-### v0.2.0
-
-- update build.sbt and template.json for PredictionIO 0.9.2
-
-### v0.1.2
-
-- update for PredictionIO 0.9.0
-
-### v0.1.1
-
-- Persist RDD to memory (.cache()) in DataSource for better performance and quick fix for
new user/item ID BiMap error issue.
-
-### v0.1.0
-
-- initial version
-- known issue:
-  * If importing new events of new users/itesm during training, the new user/item id can't
be found in the BiMap.

http://git-wip-us.apache.org/repos/asf/incubator-predictionio/blob/3a1aee70/testing/simple_scenario/recommendation-engine/build.sbt
----------------------------------------------------------------------
diff --git a/testing/simple_scenario/recommendation-engine/build.sbt b/testing/simple_scenario/recommendation-engine/build.sbt
deleted file mode 100644
index c7413bb..0000000
--- a/testing/simple_scenario/recommendation-engine/build.sbt
+++ /dev/null
@@ -1,12 +0,0 @@
-import AssemblyKeys._
-
-assemblySettings
-
-name := "template-scala-parallel-recommendation"
-
-organization := "org.apache.predictionio"
-
-libraryDependencies ++= Seq(
-  "org.apache.predictionio"    %% "core"          % pioVersion.value % "provided",
-  "org.apache.spark" %% "spark-core"    % "1.3.0" % "provided",
-  "org.apache.spark" %% "spark-mllib"   % "1.3.0" % "provided")

http://git-wip-us.apache.org/repos/asf/incubator-predictionio/blob/3a1aee70/testing/simple_scenario/recommendation-engine/data/import_eventserver.py
----------------------------------------------------------------------
diff --git a/testing/simple_scenario/recommendation-engine/data/import_eventserver.py b/testing/simple_scenario/recommendation-engine/data/import_eventserver.py
deleted file mode 100644
index 0a1e109..0000000
--- a/testing/simple_scenario/recommendation-engine/data/import_eventserver.py
+++ /dev/null
@@ -1,56 +0,0 @@
-"""
-Import sample data for recommendation engine
-"""
-
-import predictionio
-import argparse
-import random
-
-RATE_ACTIONS_DELIMITER = "::"
-SEED = 3
-
-def import_events(client, file):
-  f = open(file, 'r')
-  random.seed(SEED)
-  count = 0
-  print "Importing data..."
-  for line in f:
-    data = line.rstrip('\r\n').split(RATE_ACTIONS_DELIMITER)
-    # For demonstration purpose, randomly mix in some buy events
-    if (random.randint(0, 1) == 1):
-      client.create_event(
-        event="rate",
-        entity_type="user",
-        entity_id=data[0],
-        target_entity_type="item",
-        target_entity_id=data[1],
-        properties= { "rating" : float(data[2]) }
-      )
-    else:
-      client.create_event(
-        event="buy",
-        entity_type="user",
-        entity_id=data[0],
-        target_entity_type="item",
-        target_entity_id=data[1]
-      )
-    count += 1
-  f.close()
-  print "%s events are imported." % count
-
-if __name__ == '__main__':
-  parser = argparse.ArgumentParser(
-    description="Import sample data for recommendation engine")
-  parser.add_argument('--access_key', default='invald_access_key')
-  parser.add_argument('--url', default="http://localhost:7070")
-  parser.add_argument('--file', default="./data/sample_movielens_data.txt")
-
-  args = parser.parse_args()
-  print args
-
-  client = predictionio.EventClient(
-    access_key=args.access_key,
-    url=args.url,
-    threads=5,
-    qsize=500)
-  import_events(client, args.file)

http://git-wip-us.apache.org/repos/asf/incubator-predictionio/blob/3a1aee70/testing/simple_scenario/recommendation-engine/data/send_query.py
----------------------------------------------------------------------
diff --git a/testing/simple_scenario/recommendation-engine/data/send_query.py b/testing/simple_scenario/recommendation-engine/data/send_query.py
deleted file mode 100644
index 7eaf53e..0000000
--- a/testing/simple_scenario/recommendation-engine/data/send_query.py
+++ /dev/null
@@ -1,7 +0,0 @@
-"""
-Send sample query to prediction engine
-"""
-
-import predictionio
-engine_client = predictionio.EngineClient(url="http://localhost:8000")
-print engine_client.send_query({"user": "1", "num": 4})

http://git-wip-us.apache.org/repos/asf/incubator-predictionio/blob/3a1aee70/testing/simple_scenario/recommendation-engine/engine.json
----------------------------------------------------------------------
diff --git a/testing/simple_scenario/recommendation-engine/engine.json b/testing/simple_scenario/recommendation-engine/engine.json
deleted file mode 100644
index 8d53d56..0000000
--- a/testing/simple_scenario/recommendation-engine/engine.json
+++ /dev/null
@@ -1,21 +0,0 @@
-{
-  "id": "default",
-  "description": "Default settings",
-  "engineFactory": "org.template.recommendation.RecommendationEngine",
-  "datasource": {
-    "params" : {
-      "appName": "MyApp1"
-    }
-  },
-  "algorithms": [
-    {
-      "name": "als",
-      "params": {
-        "rank": 10,
-        "numIterations": 10,
-        "lambda": 0.01,
-        "seed": 3
-      }
-    }
-  ]
-}

http://git-wip-us.apache.org/repos/asf/incubator-predictionio/blob/3a1aee70/testing/simple_scenario/recommendation-engine/project/assembly.sbt
----------------------------------------------------------------------
diff --git a/testing/simple_scenario/recommendation-engine/project/assembly.sbt b/testing/simple_scenario/recommendation-engine/project/assembly.sbt
deleted file mode 100644
index 54c3252..0000000
--- a/testing/simple_scenario/recommendation-engine/project/assembly.sbt
+++ /dev/null
@@ -1 +0,0 @@
-addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.11.2")

http://git-wip-us.apache.org/repos/asf/incubator-predictionio/blob/3a1aee70/testing/simple_scenario/recommendation-engine/project/pio-build.sbt
----------------------------------------------------------------------
diff --git a/testing/simple_scenario/recommendation-engine/project/pio-build.sbt b/testing/simple_scenario/recommendation-engine/project/pio-build.sbt
deleted file mode 100644
index 8346a96..0000000
--- a/testing/simple_scenario/recommendation-engine/project/pio-build.sbt
+++ /dev/null
@@ -1 +0,0 @@
-addSbtPlugin("io.prediction" % "pio-build" % "0.9.0")

http://git-wip-us.apache.org/repos/asf/incubator-predictionio/blob/3a1aee70/testing/simple_scenario/recommendation-engine/src/main/scala/ALSAlgorithm.scala
----------------------------------------------------------------------
diff --git a/testing/simple_scenario/recommendation-engine/src/main/scala/ALSAlgorithm.scala
b/testing/simple_scenario/recommendation-engine/src/main/scala/ALSAlgorithm.scala
deleted file mode 100644
index 17c2806..0000000
--- a/testing/simple_scenario/recommendation-engine/src/main/scala/ALSAlgorithm.scala
+++ /dev/null
@@ -1,138 +0,0 @@
-package org.template.recommendation
-
-import org.apache.predictionio.controller.PAlgorithm
-import org.apache.predictionio.controller.Params
-import org.apache.predictionio.data.storage.BiMap
-
-import org.apache.spark.SparkContext
-import org.apache.spark.SparkContext._
-import org.apache.spark.rdd.RDD
-import org.apache.spark.mllib.recommendation.ALS
-import org.apache.spark.mllib.recommendation.{Rating => MLlibRating}
-import org.apache.spark.mllib.recommendation.ALSModel
-
-import grizzled.slf4j.Logger
-
-case class ALSAlgorithmParams(
-  rank: Int,
-  numIterations: Int,
-  lambda: Double,
-  seed: Option[Long]) extends Params
-
-class ALSAlgorithm(val ap: ALSAlgorithmParams)
-  extends PAlgorithm[PreparedData, ALSModel, Query, PredictedResult] {
-
-  @transient lazy val logger = Logger[this.type]
-
-  if (ap.numIterations > 30) {
-    logger.warn(
-      s"ALSAlgorithmParams.numIterations > 30, current: ${ap.numIterations}. " +
-      s"There is a chance of running to StackOverflowException. Lower this number to remedy
it")
-  }
-
-  def train(sc: SparkContext, data: PreparedData): ALSModel = {
-    // MLLib ALS cannot handle empty training data.
-    require(!data.ratings.take(1).isEmpty,
-      s"RDD[Rating] in PreparedData cannot be empty." +
-      " Please check if DataSource generates TrainingData" +
-      " and Preprator generates PreparedData correctly.")
-    // Convert user and item String IDs to Int index for MLlib
-
-    val userStringIntMap = BiMap.stringInt(data.ratings.map(_.user))
-    val itemStringIntMap = BiMap.stringInt(data.ratings.map(_.item))
-    val mllibRatings = data.ratings.map( r =>
-      // MLlibRating requires integer index for user and item
-      MLlibRating(userStringIntMap(r.user), itemStringIntMap(r.item), r.rating)
-    )
-
-    // seed for MLlib ALS
-    val seed = ap.seed.getOrElse(System.nanoTime)
-
-    // If you only have one type of implicit event (Eg. "view" event only),
-    // replace ALS.train(...) with
-    //val m = ALS.trainImplicit(
-      //ratings = mllibRatings,
-      //rank = ap.rank,
-      //iterations = ap.numIterations,
-      //lambda = ap.lambda,
-      //blocks = -1,
-      //alpha = 1.0,
-      //seed = seed)
-
-    val m = ALS.train(
-      ratings = mllibRatings,
-      rank = ap.rank,
-      iterations = ap.numIterations,
-      lambda = ap.lambda,
-      blocks = -1,
-      seed = seed)
-
-    new ALSModel(
-      rank = m.rank,
-      userFeatures = m.userFeatures,
-      productFeatures = m.productFeatures,
-      userStringIntMap = userStringIntMap,
-      itemStringIntMap = itemStringIntMap)
-  }
-
-  def predict(model: ALSModel, query: Query): PredictedResult = {
-    // Convert String ID to Int index for Mllib
-    model.userStringIntMap.get(query.user).map { userInt =>
-      // create inverse view of itemStringIntMap
-      val itemIntStringMap = model.itemStringIntMap.inverse
-      // recommendProducts() returns Array[MLlibRating], which uses item Int
-      // index. Convert it to String ID for returning PredictedResult
-      val itemScores = model.recommendProducts(userInt, query.num)
-        .map (r => ItemScore(itemIntStringMap(r.product), r.rating))
-      new PredictedResult(itemScores)
-    }.getOrElse{
-      logger.info(s"No prediction for unknown user ${query.user}.")
-      new PredictedResult(Array.empty)
-    }
-  }
-
-  // This function is used by the evaluation module, where a batch of queries is sent to
this engine
-  // for evaluation purpose.
-  override def batchPredict(model: ALSModel, queries: RDD[(Long, Query)]): RDD[(Long, PredictedResult)]
= {
-    val userIxQueries: RDD[(Int, (Long, Query))] = queries
-    .map { case (ix, query) => {
-      // If user not found, then the index is -1
-      val userIx = model.userStringIntMap.get(query.user).getOrElse(-1)
-      (userIx, (ix, query))
-    }}
-
-    // Cross product of all valid users from the queries and products in the model.
-    val usersProducts: RDD[(Int, Int)] = userIxQueries
-      .keys
-      .filter(_ != -1)
-      .cartesian(model.productFeatures.map(_._1))
-
-    // Call mllib ALS's predict function.
-    val ratings: RDD[MLlibRating] = model.predict(usersProducts)
-
-    // The following code construct predicted results from mllib's ratings.
-    // Not optimal implementation. Instead of groupBy, should use combineByKey with a PriorityQueue
-    val userRatings: RDD[(Int, Iterable[MLlibRating])] = ratings.groupBy(_.user)
-
-    userIxQueries.leftOuterJoin(userRatings)
-    .map {
-      // When there are ratings
-      case (userIx, ((ix, query), Some(ratings))) => {
-        val topItemScores: Array[ItemScore] = ratings
-        .toArray
-        .sortBy(_.rating)(Ordering.Double.reverse) // note: from large to small ordering
-        .take(query.num)
-        .map { rating => ItemScore(
-          model.itemStringIntMap.inverse(rating.product),
-          rating.rating) }
-
-        (ix, PredictedResult(itemScores = topItemScores))
-      }
-      // When user doesn't exist in training data
-      case (userIx, ((ix, query), None)) => {
-        require(userIx == -1)
-        (ix, PredictedResult(itemScores = Array.empty))
-      }
-    }
-  }
-}

http://git-wip-us.apache.org/repos/asf/incubator-predictionio/blob/3a1aee70/testing/simple_scenario/recommendation-engine/src/main/scala/ALSModel.scala
----------------------------------------------------------------------
diff --git a/testing/simple_scenario/recommendation-engine/src/main/scala/ALSModel.scala b/testing/simple_scenario/recommendation-engine/src/main/scala/ALSModel.scala
deleted file mode 100644
index 243c1d1..0000000
--- a/testing/simple_scenario/recommendation-engine/src/main/scala/ALSModel.scala
+++ /dev/null
@@ -1,63 +0,0 @@
-package org.apache.spark.mllib.recommendation
-// This must be the same package as Spark's MatrixFactorizationModel because
-// MatrixFactorizationModel's constructor is private and we are using
-// its constructor in order to save and load the model
-
-import org.template.recommendation.ALSAlgorithmParams
-
-import org.apache.predictionio.controller.IPersistentModel
-import org.apache.predictionio.controller.IPersistentModelLoader
-import org.apache.predictionio.data.storage.BiMap
-
-import org.apache.spark.SparkContext
-import org.apache.spark.SparkContext._
-import org.apache.spark.rdd.RDD
-
-class ALSModel(
-    override val rank: Int,
-    override val userFeatures: RDD[(Int, Array[Double])],
-    override val productFeatures: RDD[(Int, Array[Double])],
-    val userStringIntMap: BiMap[String, Int],
-    val itemStringIntMap: BiMap[String, Int])
-  extends MatrixFactorizationModel(rank, userFeatures, productFeatures)
-  with IPersistentModel[ALSAlgorithmParams] {
-
-  def save(id: String, params: ALSAlgorithmParams,
-    sc: SparkContext): Boolean = {
-
-    sc.parallelize(Seq(rank)).saveAsObjectFile(s"/tmp/${id}/rank")
-    userFeatures.saveAsObjectFile(s"/tmp/${id}/userFeatures")
-    productFeatures.saveAsObjectFile(s"/tmp/${id}/productFeatures")
-    sc.parallelize(Seq(userStringIntMap))
-      .saveAsObjectFile(s"/tmp/${id}/userStringIntMap")
-    sc.parallelize(Seq(itemStringIntMap))
-      .saveAsObjectFile(s"/tmp/${id}/itemStringIntMap")
-    true
-  }
-
-  override def toString = {
-    s"userFeatures: [${userFeatures.count()}]" +
-    s"(${userFeatures.take(2).toList}...)" +
-    s" productFeatures: [${productFeatures.count()}]" +
-    s"(${productFeatures.take(2).toList}...)" +
-    s" userStringIntMap: [${userStringIntMap.size}]" +
-    s"(${userStringIntMap.take(2)}...)" +
-    s" itemStringIntMap: [${itemStringIntMap.size}]" +
-    s"(${itemStringIntMap.take(2)}...)"
-  }
-}
-
-object ALSModel
-  extends IPersistentModelLoader[ALSAlgorithmParams, ALSModel] {
-  def apply(id: String, params: ALSAlgorithmParams,
-    sc: Option[SparkContext]) = {
-    new ALSModel(
-      rank = sc.get.objectFile[Int](s"/tmp/${id}/rank").first,
-      userFeatures = sc.get.objectFile(s"/tmp/${id}/userFeatures"),
-      productFeatures = sc.get.objectFile(s"/tmp/${id}/productFeatures"),
-      userStringIntMap = sc.get
-        .objectFile[BiMap[String, Int]](s"/tmp/${id}/userStringIntMap").first,
-      itemStringIntMap = sc.get
-        .objectFile[BiMap[String, Int]](s"/tmp/${id}/itemStringIntMap").first)
-  }
-}

http://git-wip-us.apache.org/repos/asf/incubator-predictionio/blob/3a1aee70/testing/simple_scenario/recommendation-engine/src/main/scala/DataSource.scala
----------------------------------------------------------------------
diff --git a/testing/simple_scenario/recommendation-engine/src/main/scala/DataSource.scala
b/testing/simple_scenario/recommendation-engine/src/main/scala/DataSource.scala
deleted file mode 100644
index eea3ae6..0000000
--- a/testing/simple_scenario/recommendation-engine/src/main/scala/DataSource.scala
+++ /dev/null
@@ -1,103 +0,0 @@
-package org.template.recommendation
-
-import org.apache.predictionio.controller.PDataSource
-import org.apache.predictionio.controller.EmptyEvaluationInfo
-import org.apache.predictionio.controller.EmptyActualResult
-import org.apache.predictionio.controller.Params
-import org.apache.predictionio.data.storage.Event
-import org.apache.predictionio.data.store.PEventStore
-
-import org.apache.spark.SparkContext
-import org.apache.spark.SparkContext._
-import org.apache.spark.rdd.RDD
-
-import grizzled.slf4j.Logger
-
-case class DataSourceEvalParams(kFold: Int, queryNum: Int)
-
-case class DataSourceParams(
-  appName: String,
-  evalParams: Option[DataSourceEvalParams]) extends Params
-
-class DataSource(val dsp: DataSourceParams)
-  extends PDataSource[TrainingData,
-      EmptyEvaluationInfo, Query, ActualResult] {
-
-  @transient lazy val logger = Logger[this.type]
-
-  def getRatings(sc: SparkContext): RDD[Rating] = {
-
-    val eventsRDD: RDD[Event] = PEventStore.find(
-      appName = dsp.appName,
-      entityType = Some("user"),
-      eventNames = Some(List("rate", "buy")), // read "rate" and "buy" event
-      // targetEntityType is optional field of an event.
-      targetEntityType = Some(Some("item")))(sc)
-
-    val ratingsRDD: RDD[Rating] = eventsRDD.map { event =>
-      val rating = try {
-        val ratingValue: Double = event.event match {
-          case "rate" => event.properties.get[Double]("rating")
-          case "buy" => 4.0 // map buy event to rating value of 4
-          case _ => throw new Exception(s"Unexpected event ${event} is read.")
-        }
-        // entityId and targetEntityId is String
-        Rating(event.entityId,
-          event.targetEntityId.get,
-          ratingValue)
-      } catch {
-        case e: Exception => {
-          logger.error(s"Cannot convert ${event} to Rating. Exception: ${e}.")
-          throw e
-        }
-      }
-      rating
-    }.cache()
-
-    ratingsRDD
-  }
-
-  override
-  def readTraining(sc: SparkContext): TrainingData = {
-    new TrainingData(getRatings(sc))
-  }
-
-  override
-  def readEval(sc: SparkContext)
-  : Seq[(TrainingData, EmptyEvaluationInfo, RDD[(Query, ActualResult)])] = {
-    require(!dsp.evalParams.isEmpty, "Must specify evalParams")
-    val evalParams = dsp.evalParams.get
-
-    val kFold = evalParams.kFold
-    val ratings: RDD[(Rating, Long)] = getRatings(sc).zipWithUniqueId
-    ratings.cache
-
-    (0 until kFold).map { idx => {
-      val trainingRatings = ratings.filter(_._2 % kFold != idx).map(_._1)
-      val testingRatings = ratings.filter(_._2 % kFold == idx).map(_._1)
-
-      val testingUsers: RDD[(String, Iterable[Rating])] = testingRatings.groupBy(_.user)
-
-      (new TrainingData(trainingRatings),
-        new EmptyEvaluationInfo(),
-        testingUsers.map {
-          case (user, ratings) => (Query(user, evalParams.queryNum), ActualResult(ratings.toArray))
-        }
-      )
-    }}
-  }
-}
-
-case class Rating(
-  user: String,
-  item: String,
-  rating: Double
-)
-
-class TrainingData(
-  val ratings: RDD[Rating]
-) extends Serializable {
-  override def toString = {
-    s"ratings: [${ratings.count()}] (${ratings.take(2).toList}...)"
-  }
-}

http://git-wip-us.apache.org/repos/asf/incubator-predictionio/blob/3a1aee70/testing/simple_scenario/recommendation-engine/src/main/scala/Engine.scala
----------------------------------------------------------------------
diff --git a/testing/simple_scenario/recommendation-engine/src/main/scala/Engine.scala b/testing/simple_scenario/recommendation-engine/src/main/scala/Engine.scala
deleted file mode 100644
index 79840dc..0000000
--- a/testing/simple_scenario/recommendation-engine/src/main/scala/Engine.scala
+++ /dev/null
@@ -1,32 +0,0 @@
-package org.template.recommendation
-
-import org.apache.predictionio.controller.IEngineFactory
-import org.apache.predictionio.controller.Engine
-
-case class Query(
-  user: String,
-  num: Int
-) extends Serializable
-
-case class PredictedResult(
-  itemScores: Array[ItemScore]
-) extends Serializable
-
-case class ActualResult(
-  ratings: Array[Rating]
-) extends Serializable
-
-case class ItemScore(
-  item: String,
-  score: Double
-) extends Serializable
-
-object RecommendationEngine extends IEngineFactory {
-  def apply() = {
-    new Engine(
-      classOf[DataSource],
-      classOf[Preparator],
-      Map("als" -> classOf[ALSAlgorithm]),
-      classOf[Serving])
-  }
-}

http://git-wip-us.apache.org/repos/asf/incubator-predictionio/blob/3a1aee70/testing/simple_scenario/recommendation-engine/src/main/scala/Evaluation.scala
----------------------------------------------------------------------
diff --git a/testing/simple_scenario/recommendation-engine/src/main/scala/Evaluation.scala
b/testing/simple_scenario/recommendation-engine/src/main/scala/Evaluation.scala
deleted file mode 100644
index 34e5689..0000000
--- a/testing/simple_scenario/recommendation-engine/src/main/scala/Evaluation.scala
+++ /dev/null
@@ -1,89 +0,0 @@
-package org.template.recommendation
-
-import org.apache.predictionio.controller.Evaluation
-import org.apache.predictionio.controller.OptionAverageMetric
-import org.apache.predictionio.controller.AverageMetric
-import org.apache.predictionio.controller.EmptyEvaluationInfo
-import org.apache.predictionio.controller.EngineParamsGenerator
-import org.apache.predictionio.controller.EngineParams
-import org.apache.predictionio.controller.MetricEvaluator
-
-// Usage:
-// $ pio eval org.template.recommendation.RecommendationEvaluation \
-//   org.template.recommendation.EngineParamsList
-
-case class PrecisionAtK(k: Int, ratingThreshold: Double = 2.0)
-    extends OptionAverageMetric[EmptyEvaluationInfo, Query, PredictedResult, ActualResult]
{
-  require(k > 0, "k must be greater than 0")
-
-  override def header = s"Precision@K (k=$k, threshold=$ratingThreshold)"
-
-  def calculate(q: Query, p: PredictedResult, a: ActualResult): Option[Double] = {
-    val positives: Set[String] = a.ratings.filter(_.rating >= ratingThreshold).map(_.item).toSet
-
-    // 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
-    }
-
-    val tpCount: Int = p.itemScores.take(k).filter(is => positives(is.item)).size
-
-    Some(tpCount.toDouble / math.min(k, positives.size))
-  }
-}
-
-case class PositiveCount(ratingThreshold: Double = 2.0)
-    extends AverageMetric[EmptyEvaluationInfo, Query, PredictedResult, ActualResult] {
-  override def header = s"PositiveCount (threshold=$ratingThreshold)"
-
-  def calculate(q: Query, p: PredictedResult, a: ActualResult): Double = {
-    a.ratings.filter(_.rating >= ratingThreshold).size
-  }
-}
-
-object RecommendationEvaluation extends Evaluation {
-  engineEvaluator = (
-    RecommendationEngine(),
-    MetricEvaluator(
-      metric = PrecisionAtK(k = 10, ratingThreshold = 4.0),
-      otherMetrics = Seq(
-        PositiveCount(ratingThreshold = 4.0),
-        PrecisionAtK(k = 10, ratingThreshold = 2.0),
-        PositiveCount(ratingThreshold = 2.0),
-        PrecisionAtK(k = 10, ratingThreshold = 1.0),
-        PositiveCount(ratingThreshold = 1.0)
-      )))
-}
-
-
-object ComprehensiveRecommendationEvaluation extends Evaluation {
-  val ratingThresholds = Seq(0.0, 2.0, 4.0)
-  val ks = Seq(1, 3, 10)
-
-  engineEvaluator = (
-    RecommendationEngine(),
-    MetricEvaluator(
-      metric = PrecisionAtK(k = 3, ratingThreshold = 2.0),
-      otherMetrics = (
-        (for (r <- ratingThresholds) yield PositiveCount(ratingThreshold = r)) ++
-        (for (r <- ratingThresholds; k <- ks) yield PrecisionAtK(k = k, ratingThreshold
= r))
-      )))
-}
-
-
-trait BaseEngineParamsList extends EngineParamsGenerator {
-  protected val baseEP = EngineParams(
-    dataSourceParams = DataSourceParams(
-      appName = "INVALID_APP_NAME",
-      evalParams = Some(DataSourceEvalParams(kFold = 5, queryNum = 10))))
-}
-
-object EngineParamsList extends BaseEngineParamsList {
-  engineParamsList = for(
-    rank <- Seq(5, 10, 20);
-    numIterations <- Seq(1, 5, 10))
-    yield baseEP.copy(
-      algorithmParamsList = Seq(
-        ("als", ALSAlgorithmParams(rank, numIterations, 0.01, Some(3)))))
-}

http://git-wip-us.apache.org/repos/asf/incubator-predictionio/blob/3a1aee70/testing/simple_scenario/recommendation-engine/src/main/scala/Preparator.scala
----------------------------------------------------------------------
diff --git a/testing/simple_scenario/recommendation-engine/src/main/scala/Preparator.scala
b/testing/simple_scenario/recommendation-engine/src/main/scala/Preparator.scala
deleted file mode 100644
index 8f2f7e4..0000000
--- a/testing/simple_scenario/recommendation-engine/src/main/scala/Preparator.scala
+++ /dev/null
@@ -1,19 +0,0 @@
-package org.template.recommendation
-
-import org.apache.predictionio.controller.PPreparator
-
-import org.apache.spark.SparkContext
-import org.apache.spark.SparkContext._
-import org.apache.spark.rdd.RDD
-
-class Preparator
-  extends PPreparator[TrainingData, PreparedData] {
-
-  def prepare(sc: SparkContext, trainingData: TrainingData): PreparedData = {
-    new PreparedData(ratings = trainingData.ratings)
-  }
-}
-
-class PreparedData(
-  val ratings: RDD[Rating]
-) extends Serializable

http://git-wip-us.apache.org/repos/asf/incubator-predictionio/blob/3a1aee70/testing/simple_scenario/recommendation-engine/src/main/scala/Serving.scala
----------------------------------------------------------------------
diff --git a/testing/simple_scenario/recommendation-engine/src/main/scala/Serving.scala b/testing/simple_scenario/recommendation-engine/src/main/scala/Serving.scala
deleted file mode 100644
index 38ba8b9..0000000
--- a/testing/simple_scenario/recommendation-engine/src/main/scala/Serving.scala
+++ /dev/null
@@ -1,13 +0,0 @@
-package org.template.recommendation
-
-import org.apache.predictionio.controller.LServing
-
-class Serving
-  extends LServing[Query, PredictedResult] {
-
-  override
-  def serve(query: Query,
-    predictedResults: Seq[PredictedResult]): PredictedResult = {
-    predictedResults.head
-  }
-}

http://git-wip-us.apache.org/repos/asf/incubator-predictionio/blob/3a1aee70/testing/simple_scenario/recommendation-engine/template.json
----------------------------------------------------------------------
diff --git a/testing/simple_scenario/recommendation-engine/template.json b/testing/simple_scenario/recommendation-engine/template.json
deleted file mode 100644
index fb4a50b..0000000
--- a/testing/simple_scenario/recommendation-engine/template.json
+++ /dev/null
@@ -1 +0,0 @@
-{"pio": {"version": { "min": "0.9.2" }}}

http://git-wip-us.apache.org/repos/asf/incubator-predictionio/blob/3a1aee70/testing/simple_scenario/run_scenario.sh
----------------------------------------------------------------------
diff --git a/testing/simple_scenario/run_scenario.sh b/testing/simple_scenario/run_scenario.sh
deleted file mode 100755
index 0e03ee4..0000000
--- a/testing/simple_scenario/run_scenario.sh
+++ /dev/null
@@ -1,34 +0,0 @@
-#!/bin/bash - 
-
-set -e
-
-echo "-- Starting eventserver..."
-pio eventserver &
-echo "-- Waiting for it to finish..."
-sleep 10
-
-cp -r /pio_host/testing/simple_scenario/recommendation-engine /
-cd /recommendation-engine
-
-echo "-- Adding a new app..."
-ACCESS_KEY='ppkprGNCTO_yIejzAdmDqFMOY1XhDiRiX1Da5K6-vbhVrVMoTggzsj2-rrpd4u6U' 
-pio app new --access-key $ACCESS_KEY MyApp1
-
-echo "-- Sending some data to eventserver..."
-curl https://raw.githubusercontent.com/apache/spark/master/data/mllib/sample_movielens_data.txt
--create-dirs -o data/sample_movielens_data.txt
-python data/import_eventserver.py --access_key $ACCESS_KEY
-
-echo "-- Building an engine..."
-pio build
-
-echo "-- Training a model..."
-pio train
-
-echo "-- Deploying an engine..."
-pio deploy &
-echo "-- Waiting for it to finish..."
-sleep 15
-
-echo "-- Sending a query..."
-curl -H "Content-Type: application/json" \
--d '{ "user": "1", "num": 4 }' http://localhost:8000/queries.json


Mime
View raw message