[SPARK-10264][DOCUMENTATION] Added @Since to ml.recomendation

I create new pr since original pr long time no update.
Please help to review.

srowen

Author: Tommy YU <tummyyu@163.com>

Closes #10756 from Wenpei/add_since_to_recomm.
This commit is contained in:
Tommy YU 2016-01-18 13:46:14 +00:00 committed by Sean Owen
parent bc36b0f1a1
commit 233d6cee96

View file

@ -180,22 +180,27 @@ private[recommendation] trait ALSParams extends ALSModelParams with HasMaxIter w
* @param itemFactors a DataFrame that stores item factors in two columns: `id` and `features` * @param itemFactors a DataFrame that stores item factors in two columns: `id` and `features`
*/ */
@Experimental @Experimental
@Since("1.3.0")
class ALSModel private[ml] ( class ALSModel private[ml] (
override val uid: String, @Since("1.4.0") override val uid: String,
val rank: Int, @Since("1.4.0") val rank: Int,
@transient val userFactors: DataFrame, @transient val userFactors: DataFrame,
@transient val itemFactors: DataFrame) @transient val itemFactors: DataFrame)
extends Model[ALSModel] with ALSModelParams with MLWritable { extends Model[ALSModel] with ALSModelParams with MLWritable {
/** @group setParam */ /** @group setParam */
@Since("1.4.0")
def setUserCol(value: String): this.type = set(userCol, value) def setUserCol(value: String): this.type = set(userCol, value)
/** @group setParam */ /** @group setParam */
@Since("1.4.0")
def setItemCol(value: String): this.type = set(itemCol, value) def setItemCol(value: String): this.type = set(itemCol, value)
/** @group setParam */ /** @group setParam */
@Since("1.3.0")
def setPredictionCol(value: String): this.type = set(predictionCol, value) def setPredictionCol(value: String): this.type = set(predictionCol, value)
@Since("1.3.0")
override def transform(dataset: DataFrame): DataFrame = { override def transform(dataset: DataFrame): DataFrame = {
// Register a UDF for DataFrame, and then // Register a UDF for DataFrame, and then
// create a new column named map(predictionCol) by running the predict UDF. // create a new column named map(predictionCol) by running the predict UDF.
@ -213,6 +218,7 @@ class ALSModel private[ml] (
predict(userFactors("features"), itemFactors("features")).as($(predictionCol))) predict(userFactors("features"), itemFactors("features")).as($(predictionCol)))
} }
@Since("1.3.0")
override def transformSchema(schema: StructType): StructType = { override def transformSchema(schema: StructType): StructType = {
validateParams() validateParams()
SchemaUtils.checkColumnType(schema, $(userCol), IntegerType) SchemaUtils.checkColumnType(schema, $(userCol), IntegerType)
@ -220,6 +226,7 @@ class ALSModel private[ml] (
SchemaUtils.appendColumn(schema, $(predictionCol), FloatType) SchemaUtils.appendColumn(schema, $(predictionCol), FloatType)
} }
@Since("1.5.0")
override def copy(extra: ParamMap): ALSModel = { override def copy(extra: ParamMap): ALSModel = {
val copied = new ALSModel(uid, rank, userFactors, itemFactors) val copied = new ALSModel(uid, rank, userFactors, itemFactors)
copyValues(copied, extra).setParent(parent) copyValues(copied, extra).setParent(parent)
@ -303,65 +310,83 @@ object ALSModel extends MLReadable[ALSModel] {
* preferences rather than explicit ratings given to items. * preferences rather than explicit ratings given to items.
*/ */
@Experimental @Experimental
class ALS(override val uid: String) extends Estimator[ALSModel] with ALSParams @Since("1.3.0")
class ALS(@Since("1.4.0") override val uid: String) extends Estimator[ALSModel] with ALSParams
with DefaultParamsWritable { with DefaultParamsWritable {
import org.apache.spark.ml.recommendation.ALS.Rating import org.apache.spark.ml.recommendation.ALS.Rating
@Since("1.4.0")
def this() = this(Identifiable.randomUID("als")) def this() = this(Identifiable.randomUID("als"))
/** @group setParam */ /** @group setParam */
@Since("1.3.0")
def setRank(value: Int): this.type = set(rank, value) def setRank(value: Int): this.type = set(rank, value)
/** @group setParam */ /** @group setParam */
@Since("1.3.0")
def setNumUserBlocks(value: Int): this.type = set(numUserBlocks, value) def setNumUserBlocks(value: Int): this.type = set(numUserBlocks, value)
/** @group setParam */ /** @group setParam */
@Since("1.3.0")
def setNumItemBlocks(value: Int): this.type = set(numItemBlocks, value) def setNumItemBlocks(value: Int): this.type = set(numItemBlocks, value)
/** @group setParam */ /** @group setParam */
@Since("1.3.0")
def setImplicitPrefs(value: Boolean): this.type = set(implicitPrefs, value) def setImplicitPrefs(value: Boolean): this.type = set(implicitPrefs, value)
/** @group setParam */ /** @group setParam */
@Since("1.3.0")
def setAlpha(value: Double): this.type = set(alpha, value) def setAlpha(value: Double): this.type = set(alpha, value)
/** @group setParam */ /** @group setParam */
@Since("1.3.0")
def setUserCol(value: String): this.type = set(userCol, value) def setUserCol(value: String): this.type = set(userCol, value)
/** @group setParam */ /** @group setParam */
@Since("1.3.0")
def setItemCol(value: String): this.type = set(itemCol, value) def setItemCol(value: String): this.type = set(itemCol, value)
/** @group setParam */ /** @group setParam */
@Since("1.3.0")
def setRatingCol(value: String): this.type = set(ratingCol, value) def setRatingCol(value: String): this.type = set(ratingCol, value)
/** @group setParam */ /** @group setParam */
@Since("1.3.0")
def setPredictionCol(value: String): this.type = set(predictionCol, value) def setPredictionCol(value: String): this.type = set(predictionCol, value)
/** @group setParam */ /** @group setParam */
@Since("1.3.0")
def setMaxIter(value: Int): this.type = set(maxIter, value) def setMaxIter(value: Int): this.type = set(maxIter, value)
/** @group setParam */ /** @group setParam */
@Since("1.3.0")
def setRegParam(value: Double): this.type = set(regParam, value) def setRegParam(value: Double): this.type = set(regParam, value)
/** @group setParam */ /** @group setParam */
@Since("1.3.0")
def setNonnegative(value: Boolean): this.type = set(nonnegative, value) def setNonnegative(value: Boolean): this.type = set(nonnegative, value)
/** @group setParam */ /** @group setParam */
@Since("1.4.0")
def setCheckpointInterval(value: Int): this.type = set(checkpointInterval, value) def setCheckpointInterval(value: Int): this.type = set(checkpointInterval, value)
/** @group setParam */ /** @group setParam */
@Since("1.3.0")
def setSeed(value: Long): this.type = set(seed, value) def setSeed(value: Long): this.type = set(seed, value)
/** /**
* Sets both numUserBlocks and numItemBlocks to the specific value. * Sets both numUserBlocks and numItemBlocks to the specific value.
* @group setParam * @group setParam
*/ */
@Since("1.3.0")
def setNumBlocks(value: Int): this.type = { def setNumBlocks(value: Int): this.type = {
setNumUserBlocks(value) setNumUserBlocks(value)
setNumItemBlocks(value) setNumItemBlocks(value)
this this
} }
@Since("1.3.0")
override def fit(dataset: DataFrame): ALSModel = { override def fit(dataset: DataFrame): ALSModel = {
import dataset.sqlContext.implicits._ import dataset.sqlContext.implicits._
val r = if ($(ratingCol) != "") col($(ratingCol)).cast(FloatType) else lit(1.0f) val r = if ($(ratingCol) != "") col($(ratingCol)).cast(FloatType) else lit(1.0f)
@ -381,10 +406,12 @@ class ALS(override val uid: String) extends Estimator[ALSModel] with ALSParams
copyValues(model) copyValues(model)
} }
@Since("1.3.0")
override def transformSchema(schema: StructType): StructType = { override def transformSchema(schema: StructType): StructType = {
validateAndTransformSchema(schema) validateAndTransformSchema(schema)
} }
@Since("1.5.0")
override def copy(extra: ParamMap): ALS = defaultCopy(extra) override def copy(extra: ParamMap): ALS = defaultCopy(extra)
} }