Skip to content

Commit fccd38d

Browse files
committed
[SPARK-5730][ML] add doc groups to spark.ml components
This PR adds three groups to the ScalaDoc: `param`, `setParam`, and `getParam`. Params will show up in the generated Scala API doc as the top group. Setters/getters will be at the bottom. Preview: ![screen shot 2015-02-13 at 2 47 49 pm](https://cloud.githubusercontent.com/assets/829644/6196657/5740c240-b38f-11e4-94bb-bd8ef5a796c5.png) Author: Xiangrui Meng <meng@databricks.com> Closes #4600 from mengxr/SPARK-5730 and squashes the following commits: febed9a [Xiangrui Meng] add doc groups to spark.ml components (cherry picked from commit 4f4c6d5) Signed-off-by: Xiangrui Meng <meng@databricks.com>
1 parent 356b798 commit fccd38d

File tree

13 files changed

+235
-26
lines changed

13 files changed

+235
-26
lines changed

mllib/src/main/scala/org/apache/spark/ml/Transformer.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@ abstract class Transformer extends PipelineStage with Params {
6262
private[ml] abstract class UnaryTransformer[IN, OUT, T <: UnaryTransformer[IN, OUT, T]]
6363
extends Transformer with HasInputCol with HasOutputCol with Logging {
6464

65+
/** @group setParam */
6566
def setInputCol(value: String): T = set(inputCol, value).asInstanceOf[T]
67+
68+
/** @group setParam */
6669
def setOutputCol(value: String): T = set(outputCol, value).asInstanceOf[T]
6770

6871
/**

mllib/src/main/scala/org/apache/spark/ml/classification/Classifier.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ private[spark] abstract class Classifier[
6666
extends Predictor[FeaturesType, E, M]
6767
with ClassifierParams {
6868

69+
/** @group setParam */
6970
def setRawPredictionCol(value: String): E =
7071
set(rawPredictionCol, value).asInstanceOf[E]
7172

@@ -87,6 +88,7 @@ private[spark]
8788
abstract class ClassificationModel[FeaturesType, M <: ClassificationModel[FeaturesType, M]]
8889
extends PredictionModel[FeaturesType, M] with ClassifierParams {
8990

91+
/** @group setParam */
9092
def setRawPredictionCol(value: String): M = set(rawPredictionCol, value).asInstanceOf[M]
9193

9294
/** Number of classes (values which the label can take). */

mllib/src/main/scala/org/apache/spark/ml/classification/LogisticRegression.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,13 @@ class LogisticRegression
4949
setMaxIter(100)
5050
setThreshold(0.5)
5151

52+
/** @group setParam */
5253
def setRegParam(value: Double): this.type = set(regParam, value)
54+
55+
/** @group setParam */
5356
def setMaxIter(value: Int): this.type = set(maxIter, value)
57+
58+
/** @group setParam */
5459
def setThreshold(value: Double): this.type = set(threshold, value)
5560

5661
override protected def train(dataset: DataFrame, paramMap: ParamMap): LogisticRegressionModel = {
@@ -93,6 +98,7 @@ class LogisticRegressionModel private[ml] (
9398

9499
setThreshold(0.5)
95100

101+
/** @group setParam */
96102
def setThreshold(value: Double): this.type = set(threshold, value)
97103

98104
private val margin: Vector => Double = (features) => {

mllib/src/main/scala/org/apache/spark/ml/classification/ProbabilisticClassifier.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ private[spark] abstract class ProbabilisticClassifier[
6161
M <: ProbabilisticClassificationModel[FeaturesType, M]]
6262
extends Classifier[FeaturesType, E, M] with ProbabilisticClassifierParams {
6363

64+
/** @group setParam */
6465
def setProbabilityCol(value: String): E = set(probabilityCol, value).asInstanceOf[E]
6566
}
6667

@@ -82,6 +83,7 @@ private[spark] abstract class ProbabilisticClassificationModel[
8283
M <: ProbabilisticClassificationModel[FeaturesType, M]]
8384
extends ClassificationModel[FeaturesType, M] with ProbabilisticClassifierParams {
8485

86+
/** @group setParam */
8587
def setProbabilityCol(value: String): M = set(probabilityCol, value).asInstanceOf[M]
8688

8789
/**

mllib/src/main/scala/org/apache/spark/ml/evaluation/BinaryClassificationEvaluator.scala

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,23 @@ import org.apache.spark.sql.types.DoubleType
3535
class BinaryClassificationEvaluator extends Evaluator with Params
3636
with HasRawPredictionCol with HasLabelCol {
3737

38-
/** param for metric name in evaluation */
38+
/**
39+
* param for metric name in evaluation
40+
* @group param
41+
*/
3942
val metricName: Param[String] = new Param(this, "metricName",
4043
"metric name in evaluation (areaUnderROC|areaUnderPR)", Some("areaUnderROC"))
44+
45+
/** @group getParam */
4146
def getMetricName: String = get(metricName)
47+
48+
/** @group setParam */
4249
def setMetricName(value: String): this.type = set(metricName, value)
4350

51+
/** @group setParam */
4452
def setScoreCol(value: String): this.type = set(rawPredictionCol, value)
53+
54+
/** @group setParam */
4555
def setLabelCol(value: String): this.type = set(labelCol, value)
4656

4757
override def evaluate(dataset: DataFrame, paramMap: ParamMap): Double = {

mllib/src/main/scala/org/apache/spark/ml/feature/HashingTF.scala

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,18 @@ import org.apache.spark.sql.types.DataType
3131
@AlphaComponent
3232
class HashingTF extends UnaryTransformer[Iterable[_], Vector, HashingTF] {
3333

34-
/** number of features */
34+
/**
35+
* number of features
36+
* @group param
37+
*/
3538
val numFeatures = new IntParam(this, "numFeatures", "number of features", Some(1 << 18))
36-
def setNumFeatures(value: Int) = set(numFeatures, value)
39+
40+
/** @group getParam */
3741
def getNumFeatures: Int = get(numFeatures)
3842

43+
/** @group setParam */
44+
def setNumFeatures(value: Int) = set(numFeatures, value)
45+
3946
override protected def createTransformFunc(paramMap: ParamMap): Iterable[_] => Vector = {
4047
val hashingTF = new feature.HashingTF(paramMap(numFeatures))
4148
hashingTF.transform

mllib/src/main/scala/org/apache/spark/ml/feature/StandardScaler.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ private[feature] trait StandardScalerParams extends Params with HasInputCol with
3939
@AlphaComponent
4040
class StandardScaler extends Estimator[StandardScalerModel] with StandardScalerParams {
4141

42+
/** @group setParam */
4243
def setInputCol(value: String): this.type = set(inputCol, value)
44+
45+
/** @group setParam */
4346
def setOutputCol(value: String): this.type = set(outputCol, value)
4447

4548
override def fit(dataset: DataFrame, paramMap: ParamMap): StandardScalerModel = {
@@ -75,7 +78,10 @@ class StandardScalerModel private[ml] (
7578
scaler: feature.StandardScalerModel)
7679
extends Model[StandardScalerModel] with StandardScalerParams {
7780

81+
/** @group setParam */
7882
def setInputCol(value: String): this.type = set(inputCol, value)
83+
84+
/** @group setParam */
7985
def setOutputCol(value: String): this.type = set(outputCol, value)
8086

8187
override def transform(dataset: DataFrame, paramMap: ParamMap): DataFrame = {

mllib/src/main/scala/org/apache/spark/ml/impl/estimator/Predictor.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,13 @@ private[spark] abstract class Predictor[
8585
M <: PredictionModel[FeaturesType, M]]
8686
extends Estimator[M] with PredictorParams {
8787

88+
/** @group setParam */
8889
def setLabelCol(value: String): Learner = set(labelCol, value).asInstanceOf[Learner]
90+
91+
/** @group setParam */
8992
def setFeaturesCol(value: String): Learner = set(featuresCol, value).asInstanceOf[Learner]
93+
94+
/** @group setParam */
9095
def setPredictionCol(value: String): Learner = set(predictionCol, value).asInstanceOf[Learner]
9196

9297
override def fit(dataset: DataFrame, paramMap: ParamMap): M = {
@@ -160,8 +165,10 @@ private[spark] abstract class Predictor[
160165
private[spark] abstract class PredictionModel[FeaturesType, M <: PredictionModel[FeaturesType, M]]
161166
extends Model[M] with PredictorParams {
162167

168+
/** @group setParam */
163169
def setFeaturesCol(value: String): M = set(featuresCol, value).asInstanceOf[M]
164170

171+
/** @group setParam */
165172
def setPredictionCol(value: String): M = set(predictionCol, value).asInstanceOf[M]
166173

167174
/**

mllib/src/main/scala/org/apache/spark/ml/package.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,19 @@ package org.apache.spark
2020
/**
2121
* Spark ML is an ALPHA component that adds a new set of machine learning APIs to let users quickly
2222
* assemble and configure practical machine learning pipelines.
23+
*
24+
* @groupname param Parameters
25+
* @groupdesc param A list of (hyper-)parameter keys this algorithm can take. Users can set and get
26+
* the parameter values through setters and getters, respectively.
27+
* @groupprio param -5
28+
*
29+
* @groupname setParam Parameter setters
30+
* @groupprio setParam 5
31+
*
32+
* @groupname getParam Parameter getters
33+
* @groupprio getParam 6
34+
*
35+
* @groupname Ungrouped Members
36+
* @groupprio Ungrouped 0
2337
*/
2438
package object ml

mllib/src/main/scala/org/apache/spark/ml/param/sharedParams.scala

Lines changed: 60 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,67 +24,117 @@ package org.apache.spark.ml.param
2424
*/
2525

2626
private[ml] trait HasRegParam extends Params {
27-
/** param for regularization parameter */
27+
/**
28+
* param for regularization parameter
29+
* @group param
30+
*/
2831
val regParam: DoubleParam = new DoubleParam(this, "regParam", "regularization parameter")
32+
33+
/** @group getParam */
2934
def getRegParam: Double = get(regParam)
3035
}
3136

3237
private[ml] trait HasMaxIter extends Params {
33-
/** param for max number of iterations */
38+
/**
39+
* param for max number of iterations
40+
* @group param
41+
*/
3442
val maxIter: IntParam = new IntParam(this, "maxIter", "max number of iterations")
43+
44+
/** @group getParam */
3545
def getMaxIter: Int = get(maxIter)
3646
}
3747

3848
private[ml] trait HasFeaturesCol extends Params {
39-
/** param for features column name */
49+
/**
50+
* param for features column name
51+
* @group param
52+
*/
4053
val featuresCol: Param[String] =
4154
new Param(this, "featuresCol", "features column name", Some("features"))
55+
56+
/** @group getParam */
4257
def getFeaturesCol: String = get(featuresCol)
4358
}
4459

4560
private[ml] trait HasLabelCol extends Params {
46-
/** param for label column name */
61+
/**
62+
* param for label column name
63+
* @group param
64+
*/
4765
val labelCol: Param[String] = new Param(this, "labelCol", "label column name", Some("label"))
66+
67+
/** @group getParam */
4868
def getLabelCol: String = get(labelCol)
4969
}
5070

5171
private[ml] trait HasPredictionCol extends Params {
52-
/** param for prediction column name */
72+
/**
73+
* param for prediction column name
74+
* @group param
75+
*/
5376
val predictionCol: Param[String] =
5477
new Param(this, "predictionCol", "prediction column name", Some("prediction"))
78+
79+
/** @group getParam */
5580
def getPredictionCol: String = get(predictionCol)
5681
}
5782

5883
private[ml] trait HasRawPredictionCol extends Params {
59-
/** param for raw prediction column name */
84+
/**
85+
* param for raw prediction column name
86+
* @group param
87+
*/
6088
val rawPredictionCol: Param[String] =
6189
new Param(this, "rawPredictionCol", "raw prediction (a.k.a. confidence) column name",
6290
Some("rawPrediction"))
91+
92+
/** @group getParam */
6393
def getRawPredictionCol: String = get(rawPredictionCol)
6494
}
6595

6696
private[ml] trait HasProbabilityCol extends Params {
67-
/** param for predicted class conditional probabilities column name */
97+
/**
98+
* param for predicted class conditional probabilities column name
99+
* @group param
100+
*/
68101
val probabilityCol: Param[String] =
69102
new Param(this, "probabilityCol", "column name for predicted class conditional probabilities",
70103
Some("probability"))
104+
105+
/** @group getParam */
71106
def getProbabilityCol: String = get(probabilityCol)
72107
}
73108

74109
private[ml] trait HasThreshold extends Params {
75-
/** param for threshold in (binary) prediction */
110+
/**
111+
* param for threshold in (binary) prediction
112+
* @group param
113+
*/
76114
val threshold: DoubleParam = new DoubleParam(this, "threshold", "threshold in prediction")
115+
116+
/** @group getParam */
77117
def getThreshold: Double = get(threshold)
78118
}
79119

80120
private[ml] trait HasInputCol extends Params {
81-
/** param for input column name */
121+
/**
122+
* param for input column name
123+
* @group param
124+
*/
82125
val inputCol: Param[String] = new Param(this, "inputCol", "input column name")
126+
127+
/** @group getParam */
83128
def getInputCol: String = get(inputCol)
84129
}
85130

86131
private[ml] trait HasOutputCol extends Params {
87-
/** param for output column name */
132+
/**
133+
* param for output column name
134+
* @group param
135+
*/
88136
val outputCol: Param[String] = new Param(this, "outputCol", "output column name")
137+
138+
/** @group getParam */
89139
def getOutputCol: String = get(outputCol)
90140
}

0 commit comments

Comments
 (0)