aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXiangrui Meng <meng@databricks.com>2015-08-26 14:02:19 -0700
committerXiangrui Meng <meng@databricks.com>2015-08-26 14:02:32 -0700
commitefbd7af44e855efcbb1fa224e80db24947e2b153 (patch)
tree639d8772bd92a0444712237855a5a340800d6478
parentb0dde36009ce371824ce3e47e60fa0711d7733bb (diff)
downloadspark-efbd7af44e855efcbb1fa224e80db24947e2b153.tar.gz
spark-efbd7af44e855efcbb1fa224e80db24947e2b153.tar.bz2
spark-efbd7af44e855efcbb1fa224e80db24947e2b153.zip
[SPARK-10241] [MLLIB] update since versions in mllib.recommendation
Same as #8421 but for `mllib.recommendation`. cc srowen coderxiang Author: Xiangrui Meng <meng@databricks.com> Closes #8432 from mengxr/SPARK-10241. (cherry picked from commit 086d4681df3ebfccfc04188262c10482f44553b0) Signed-off-by: Xiangrui Meng <meng@databricks.com>
-rw-r--r--mllib/src/main/scala/org/apache/spark/mllib/recommendation/ALS.scala22
-rw-r--r--mllib/src/main/scala/org/apache/spark/mllib/recommendation/MatrixFactorizationModel.scala8
2 files changed, 25 insertions, 5 deletions
diff --git a/mllib/src/main/scala/org/apache/spark/mllib/recommendation/ALS.scala b/mllib/src/main/scala/org/apache/spark/mllib/recommendation/ALS.scala
index b27ef1b949..33aaf853e5 100644
--- a/mllib/src/main/scala/org/apache/spark/mllib/recommendation/ALS.scala
+++ b/mllib/src/main/scala/org/apache/spark/mllib/recommendation/ALS.scala
@@ -28,7 +28,10 @@ import org.apache.spark.storage.StorageLevel
* A more compact class to represent a rating than Tuple3[Int, Int, Double].
*/
@Since("0.8.0")
-case class Rating(user: Int, product: Int, rating: Double)
+case class Rating @Since("0.8.0") (
+ @Since("0.8.0") user: Int,
+ @Since("0.8.0") product: Int,
+ @Since("0.8.0") rating: Double)
/**
* Alternating Least Squares matrix factorization.
@@ -59,6 +62,7 @@ case class Rating(user: Int, product: Int, rating: Double)
* indicated user
* preferences rather than explicit ratings given to items.
*/
+@Since("0.8.0")
class ALS private (
private var numUserBlocks: Int,
private var numProductBlocks: Int,
@@ -74,6 +78,7 @@ class ALS private (
* Constructs an ALS instance with default parameters: {numBlocks: -1, rank: 10, iterations: 10,
* lambda: 0.01, implicitPrefs: false, alpha: 1.0}.
*/
+ @Since("0.8.0")
def this() = this(-1, -1, 10, 10, 0.01, false, 1.0)
/** If true, do alternating nonnegative least squares. */
@@ -90,6 +95,7 @@ class ALS private (
* Set the number of blocks for both user blocks and product blocks to parallelize the computation
* into; pass -1 for an auto-configured number of blocks. Default: -1.
*/
+ @Since("0.8.0")
def setBlocks(numBlocks: Int): this.type = {
this.numUserBlocks = numBlocks
this.numProductBlocks = numBlocks
@@ -99,6 +105,7 @@ class ALS private (
/**
* Set the number of user blocks to parallelize the computation.
*/
+ @Since("1.1.0")
def setUserBlocks(numUserBlocks: Int): this.type = {
this.numUserBlocks = numUserBlocks
this
@@ -107,30 +114,35 @@ class ALS private (
/**
* Set the number of product blocks to parallelize the computation.
*/
+ @Since("1.1.0")
def setProductBlocks(numProductBlocks: Int): this.type = {
this.numProductBlocks = numProductBlocks
this
}
/** Set the rank of the feature matrices computed (number of features). Default: 10. */
+ @Since("0.8.0")
def setRank(rank: Int): this.type = {
this.rank = rank
this
}
/** Set the number of iterations to run. Default: 10. */
+ @Since("0.8.0")
def setIterations(iterations: Int): this.type = {
this.iterations = iterations
this
}
/** Set the regularization parameter, lambda. Default: 0.01. */
+ @Since("0.8.0")
def setLambda(lambda: Double): this.type = {
this.lambda = lambda
this
}
/** Sets whether to use implicit preference. Default: false. */
+ @Since("0.8.1")
def setImplicitPrefs(implicitPrefs: Boolean): this.type = {
this.implicitPrefs = implicitPrefs
this
@@ -139,12 +151,14 @@ class ALS private (
/**
* Sets the constant used in computing confidence in implicit ALS. Default: 1.0.
*/
+ @Since("0.8.1")
def setAlpha(alpha: Double): this.type = {
this.alpha = alpha
this
}
/** Sets a random seed to have deterministic results. */
+ @Since("1.0.0")
def setSeed(seed: Long): this.type = {
this.seed = seed
this
@@ -154,6 +168,7 @@ class ALS private (
* Set whether the least-squares problems solved at each iteration should have
* nonnegativity constraints.
*/
+ @Since("1.1.0")
def setNonnegative(b: Boolean): this.type = {
this.nonnegative = b
this
@@ -166,6 +181,7 @@ class ALS private (
* set `spark.rdd.compress` to `true` to reduce the space requirement, at the cost of speed.
*/
@DeveloperApi
+ @Since("1.1.0")
def setIntermediateRDDStorageLevel(storageLevel: StorageLevel): this.type = {
require(storageLevel != StorageLevel.NONE,
"ALS is not designed to run without persisting intermediate RDDs.")
@@ -181,6 +197,7 @@ class ALS private (
* at the cost of speed.
*/
@DeveloperApi
+ @Since("1.3.0")
def setFinalRDDStorageLevel(storageLevel: StorageLevel): this.type = {
this.finalRDDStorageLevel = storageLevel
this
@@ -194,6 +211,7 @@ class ALS private (
* this setting is ignored.
*/
@DeveloperApi
+ @Since("1.4.0")
def setCheckpointInterval(checkpointInterval: Int): this.type = {
this.checkpointInterval = checkpointInterval
this
@@ -203,6 +221,7 @@ class ALS private (
* Run ALS with the configured parameters on an input RDD of (user, product, rating) triples.
* Returns a MatrixFactorizationModel with feature vectors for each user and product.
*/
+ @Since("0.8.0")
def run(ratings: RDD[Rating]): MatrixFactorizationModel = {
val sc = ratings.context
@@ -250,6 +269,7 @@ class ALS private (
/**
* Java-friendly version of [[ALS.run]].
*/
+ @Since("1.3.0")
def run(ratings: JavaRDD[Rating]): MatrixFactorizationModel = run(ratings.rdd)
}
diff --git a/mllib/src/main/scala/org/apache/spark/mllib/recommendation/MatrixFactorizationModel.scala b/mllib/src/main/scala/org/apache/spark/mllib/recommendation/MatrixFactorizationModel.scala
index ba4cfdcd9f..46562eb2ad 100644
--- a/mllib/src/main/scala/org/apache/spark/mllib/recommendation/MatrixFactorizationModel.scala
+++ b/mllib/src/main/scala/org/apache/spark/mllib/recommendation/MatrixFactorizationModel.scala
@@ -52,10 +52,10 @@ import org.apache.spark.storage.StorageLevel
* and the features computed for this product.
*/
@Since("0.8.0")
-class MatrixFactorizationModel(
- val rank: Int,
- val userFeatures: RDD[(Int, Array[Double])],
- val productFeatures: RDD[(Int, Array[Double])])
+class MatrixFactorizationModel @Since("0.8.0") (
+ @Since("0.8.0") val rank: Int,
+ @Since("0.8.0") val userFeatures: RDD[(Int, Array[Double])],
+ @Since("0.8.0") val productFeatures: RDD[(Int, Array[Double])])
extends Saveable with Serializable with Logging {
require(rank > 0)