Skip to content

Commit 08d390f

Browse files
mengxrDB Tsai
authored andcommitted
[SPARK-10235] [MLLIB] update since versions in mllib.regression
Same as #8421 but for `mllib.regression`. cc freeman-lab dbtsai Author: Xiangrui Meng <[email protected]> Closes #8426 from mengxr/SPARK-10235 and squashes the following commits: 6cd28e4 [Xiangrui Meng] update since versions in mllib.regression (cherry picked from commit 4657fa1) Signed-off-by: DB Tsai <[email protected]>
1 parent 6d8ebc8 commit 08d390f

File tree

8 files changed

+47
-29
lines changed

8 files changed

+47
-29
lines changed

mllib/src/main/scala/org/apache/spark/mllib/regression/GeneralizedLinearAlgorithm.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ import org.apache.spark.storage.StorageLevel
3838
*/
3939
@Since("0.8.0")
4040
@DeveloperApi
41-
abstract class GeneralizedLinearModel(val weights: Vector, val intercept: Double)
41+
abstract class GeneralizedLinearModel @Since("1.0.0") (
42+
@Since("1.0.0") val weights: Vector,
43+
@Since("0.8.0") val intercept: Double)
4244
extends Serializable {
4345

4446
/**
@@ -107,7 +109,7 @@ abstract class GeneralizedLinearAlgorithm[M <: GeneralizedLinearModel]
107109
* The optimizer to solve the problem.
108110
*
109111
*/
110-
@Since("1.0.0")
112+
@Since("0.8.0")
111113
def optimizer: Optimizer
112114

113115
/** Whether to add intercept (default: false). */

mllib/src/main/scala/org/apache/spark/mllib/regression/IsotonicRegression.scala

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ import org.apache.spark.sql.SQLContext
5050
*/
5151
@Since("1.3.0")
5252
@Experimental
53-
class IsotonicRegressionModel (
54-
val boundaries: Array[Double],
55-
val predictions: Array[Double],
56-
val isotonic: Boolean) extends Serializable with Saveable {
53+
class IsotonicRegressionModel @Since("1.3.0") (
54+
@Since("1.3.0") val boundaries: Array[Double],
55+
@Since("1.3.0") val predictions: Array[Double],
56+
@Since("1.3.0") val isotonic: Boolean) extends Serializable with Saveable {
5757

5858
private val predictionOrd = if (isotonic) Ordering[Double] else Ordering[Double].reverse
5959

@@ -63,7 +63,6 @@ class IsotonicRegressionModel (
6363

6464
/**
6565
* A Java-friendly constructor that takes two Iterable parameters and one Boolean parameter.
66-
*
6766
*/
6867
@Since("1.4.0")
6968
def this(boundaries: java.lang.Iterable[Double],
@@ -214,8 +213,6 @@ object IsotonicRegressionModel extends Loader[IsotonicRegressionModel] {
214213
}
215214
}
216215

217-
/**
218-
*/
219216
@Since("1.4.0")
220217
override def load(sc: SparkContext, path: String): IsotonicRegressionModel = {
221218
implicit val formats = DefaultFormats
@@ -256,13 +253,15 @@ object IsotonicRegressionModel extends Loader[IsotonicRegressionModel] {
256253
* @see [[http://en.wikipedia.org/wiki/Isotonic_regression Isotonic regression (Wikipedia)]]
257254
*/
258255
@Experimental
256+
@Since("1.3.0")
259257
class IsotonicRegression private (private var isotonic: Boolean) extends Serializable {
260258

261259
/**
262260
* Constructs IsotonicRegression instance with default parameter isotonic = true.
263261
*
264262
* @return New instance of IsotonicRegression.
265263
*/
264+
@Since("1.3.0")
266265
def this() = this(true)
267266

268267
/**
@@ -271,6 +270,7 @@ class IsotonicRegression private (private var isotonic: Boolean) extends Seriali
271270
* @param isotonic Isotonic (increasing) or antitonic (decreasing) sequence.
272271
* @return This instance of IsotonicRegression.
273272
*/
273+
@Since("1.3.0")
274274
def setIsotonic(isotonic: Boolean): this.type = {
275275
this.isotonic = isotonic
276276
this
@@ -286,6 +286,7 @@ class IsotonicRegression private (private var isotonic: Boolean) extends Seriali
286286
* the algorithm is executed.
287287
* @return Isotonic regression model.
288288
*/
289+
@Since("1.3.0")
289290
def run(input: RDD[(Double, Double, Double)]): IsotonicRegressionModel = {
290291
val preprocessedInput = if (isotonic) {
291292
input
@@ -311,6 +312,7 @@ class IsotonicRegression private (private var isotonic: Boolean) extends Seriali
311312
* the algorithm is executed.
312313
* @return Isotonic regression model.
313314
*/
315+
@Since("1.3.0")
314316
def run(input: JavaRDD[(JDouble, JDouble, JDouble)]): IsotonicRegressionModel = {
315317
run(input.rdd.retag.asInstanceOf[RDD[(Double, Double, Double)]])
316318
}

mllib/src/main/scala/org/apache/spark/mllib/regression/LabeledPoint.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,12 @@ import org.apache.spark.SparkException
2929
*
3030
* @param label Label for this data point.
3131
* @param features List of features for this data point.
32-
*
3332
*/
3433
@Since("0.8.0")
3534
@BeanInfo
36-
case class LabeledPoint(label: Double, features: Vector) {
35+
case class LabeledPoint @Since("1.0.0") (
36+
@Since("0.8.0") label: Double,
37+
@Since("1.0.0") features: Vector) {
3738
override def toString: String = {
3839
s"($label,$features)"
3940
}

mllib/src/main/scala/org/apache/spark/mllib/regression/Lasso.scala

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ import org.apache.spark.rdd.RDD
3434
*
3535
*/
3636
@Since("0.8.0")
37-
class LassoModel (
38-
override val weights: Vector,
39-
override val intercept: Double)
37+
class LassoModel @Since("1.1.0") (
38+
@Since("1.0.0") override val weights: Vector,
39+
@Since("0.8.0") override val intercept: Double)
4040
extends GeneralizedLinearModel(weights, intercept)
4141
with RegressionModel with Serializable with Saveable with PMMLExportable {
4242

@@ -84,6 +84,7 @@ object LassoModel extends Loader[LassoModel] {
8484
* its corresponding right hand side label y.
8585
* See also the documentation for the precise formulation.
8686
*/
87+
@Since("0.8.0")
8788
class LassoWithSGD private (
8889
private var stepSize: Double,
8990
private var numIterations: Int,
@@ -93,6 +94,7 @@ class LassoWithSGD private (
9394

9495
private val gradient = new LeastSquaresGradient()
9596
private val updater = new L1Updater()
97+
@Since("0.8.0")
9698
override val optimizer = new GradientDescent(gradient, updater)
9799
.setStepSize(stepSize)
98100
.setNumIterations(numIterations)
@@ -103,6 +105,7 @@ class LassoWithSGD private (
103105
* Construct a Lasso object with default parameters: {stepSize: 1.0, numIterations: 100,
104106
* regParam: 0.01, miniBatchFraction: 1.0}.
105107
*/
108+
@Since("0.8.0")
106109
def this() = this(1.0, 100, 0.01, 1.0)
107110

108111
override protected def createModel(weights: Vector, intercept: Double) = {

mllib/src/main/scala/org/apache/spark/mllib/regression/LinearRegression.scala

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ import org.apache.spark.rdd.RDD
3434
*
3535
*/
3636
@Since("0.8.0")
37-
class LinearRegressionModel (
38-
override val weights: Vector,
39-
override val intercept: Double)
37+
class LinearRegressionModel @Since("1.1.0") (
38+
@Since("1.0.0") override val weights: Vector,
39+
@Since("0.8.0") override val intercept: Double)
4040
extends GeneralizedLinearModel(weights, intercept) with RegressionModel with Serializable
4141
with Saveable with PMMLExportable {
4242

@@ -85,6 +85,7 @@ object LinearRegressionModel extends Loader[LinearRegressionModel] {
8585
* its corresponding right hand side label y.
8686
* See also the documentation for the precise formulation.
8787
*/
88+
@Since("0.8.0")
8889
class LinearRegressionWithSGD private[mllib] (
8990
private var stepSize: Double,
9091
private var numIterations: Int,
@@ -93,6 +94,7 @@ class LinearRegressionWithSGD private[mllib] (
9394

9495
private val gradient = new LeastSquaresGradient()
9596
private val updater = new SimpleUpdater()
97+
@Since("0.8.0")
9698
override val optimizer = new GradientDescent(gradient, updater)
9799
.setStepSize(stepSize)
98100
.setNumIterations(numIterations)
@@ -102,6 +104,7 @@ class LinearRegressionWithSGD private[mllib] (
102104
* Construct a LinearRegression object with default parameters: {stepSize: 1.0,
103105
* numIterations: 100, miniBatchFraction: 1.0}.
104106
*/
107+
@Since("0.8.0")
105108
def this() = this(1.0, 100, 1.0)
106109

107110
override protected[mllib] def createModel(weights: Vector, intercept: Double) = {

mllib/src/main/scala/org/apache/spark/mllib/regression/RidgeRegression.scala

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ import org.apache.spark.rdd.RDD
3535
*
3636
*/
3737
@Since("0.8.0")
38-
class RidgeRegressionModel (
39-
override val weights: Vector,
40-
override val intercept: Double)
38+
class RidgeRegressionModel @Since("1.1.0") (
39+
@Since("1.0.0") override val weights: Vector,
40+
@Since("0.8.0") override val intercept: Double)
4141
extends GeneralizedLinearModel(weights, intercept)
4242
with RegressionModel with Serializable with Saveable with PMMLExportable {
4343

@@ -85,6 +85,7 @@ object RidgeRegressionModel extends Loader[RidgeRegressionModel] {
8585
* its corresponding right hand side label y.
8686
* See also the documentation for the precise formulation.
8787
*/
88+
@Since("0.8.0")
8889
class RidgeRegressionWithSGD private (
8990
private var stepSize: Double,
9091
private var numIterations: Int,
@@ -94,7 +95,7 @@ class RidgeRegressionWithSGD private (
9495

9596
private val gradient = new LeastSquaresGradient()
9697
private val updater = new SquaredL2Updater()
97-
98+
@Since("0.8.0")
9899
override val optimizer = new GradientDescent(gradient, updater)
99100
.setStepSize(stepSize)
100101
.setNumIterations(numIterations)
@@ -105,6 +106,7 @@ class RidgeRegressionWithSGD private (
105106
* Construct a RidgeRegression object with default parameters: {stepSize: 1.0, numIterations: 100,
106107
* regParam: 0.01, miniBatchFraction: 1.0}.
107108
*/
109+
@Since("0.8.0")
108110
def this() = this(1.0, 100, 0.01, 1.0)
109111

110112
override protected def createModel(weights: Vector, intercept: Double) = {
@@ -134,7 +136,7 @@ object RidgeRegressionWithSGD {
134136
* the number of features in the data.
135137
*
136138
*/
137-
@Since("0.8.0")
139+
@Since("1.0.0")
138140
def train(
139141
input: RDD[LabeledPoint],
140142
numIterations: Int,

mllib/src/main/scala/org/apache/spark/mllib/regression/StreamingLinearAlgorithm.scala

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import scala.reflect.ClassTag
2222
import org.apache.spark.Logging
2323
import org.apache.spark.annotation.{DeveloperApi, Since}
2424
import org.apache.spark.api.java.JavaSparkContext.fakeClassTag
25-
import org.apache.spark.mllib.linalg.{Vector, Vectors}
25+
import org.apache.spark.mllib.linalg.Vector
2626
import org.apache.spark.streaming.api.java.{JavaDStream, JavaPairDStream}
2727
import org.apache.spark.streaming.dstream.DStream
2828

@@ -83,9 +83,8 @@ abstract class StreamingLinearAlgorithm[
8383
* batch of data from the stream.
8484
*
8585
* @param data DStream containing labeled data
86-
*
8786
*/
88-
@Since("1.3.0")
87+
@Since("1.1.0")
8988
def trainOn(data: DStream[LabeledPoint]): Unit = {
9089
if (model.isEmpty) {
9190
throw new IllegalArgumentException("Model must be initialized before starting training.")
@@ -105,7 +104,6 @@ abstract class StreamingLinearAlgorithm[
105104

106105
/**
107106
* Java-friendly version of `trainOn`.
108-
*
109107
*/
110108
@Since("1.3.0")
111109
def trainOn(data: JavaDStream[LabeledPoint]): Unit = trainOn(data.dstream)
@@ -129,7 +127,7 @@ abstract class StreamingLinearAlgorithm[
129127
* Java-friendly version of `predictOn`.
130128
*
131129
*/
132-
@Since("1.1.0")
130+
@Since("1.3.0")
133131
def predictOn(data: JavaDStream[Vector]): JavaDStream[java.lang.Double] = {
134132
JavaDStream.fromDStream(predictOn(data.dstream).asInstanceOf[DStream[java.lang.Double]])
135133
}

mllib/src/main/scala/org/apache/spark/mllib/regression/StreamingLinearRegressionWithSGD.scala

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
package org.apache.spark.mllib.regression
1919

20-
import org.apache.spark.annotation.Experimental
20+
import org.apache.spark.annotation.{Experimental, Since}
2121
import org.apache.spark.mllib.linalg.Vector
2222

2323
/**
@@ -41,6 +41,7 @@ import org.apache.spark.mllib.linalg.Vector
4141
* .trainOn(DStream)
4242
*/
4343
@Experimental
44+
@Since("1.1.0")
4445
class StreamingLinearRegressionWithSGD private[mllib] (
4546
private var stepSize: Double,
4647
private var numIterations: Int,
@@ -54,15 +55,18 @@ class StreamingLinearRegressionWithSGD private[mllib] (
5455
* Initial weights must be set before using trainOn or predictOn
5556
* (see `StreamingLinearAlgorithm`)
5657
*/
58+
@Since("1.1.0")
5759
def this() = this(0.1, 50, 1.0)
5860

61+
@Since("1.1.0")
5962
val algorithm = new LinearRegressionWithSGD(stepSize, numIterations, miniBatchFraction)
6063

6164
protected var model: Option[LinearRegressionModel] = None
6265

6366
/**
6467
* Set the step size for gradient descent. Default: 0.1.
6568
*/
69+
@Since("1.1.0")
6670
def setStepSize(stepSize: Double): this.type = {
6771
this.algorithm.optimizer.setStepSize(stepSize)
6872
this
@@ -71,6 +75,7 @@ class StreamingLinearRegressionWithSGD private[mllib] (
7175
/**
7276
* Set the number of iterations of gradient descent to run per update. Default: 50.
7377
*/
78+
@Since("1.1.0")
7479
def setNumIterations(numIterations: Int): this.type = {
7580
this.algorithm.optimizer.setNumIterations(numIterations)
7681
this
@@ -79,6 +84,7 @@ class StreamingLinearRegressionWithSGD private[mllib] (
7984
/**
8085
* Set the fraction of each batch to use for updates. Default: 1.0.
8186
*/
87+
@Since("1.1.0")
8288
def setMiniBatchFraction(miniBatchFraction: Double): this.type = {
8389
this.algorithm.optimizer.setMiniBatchFraction(miniBatchFraction)
8490
this
@@ -87,6 +93,7 @@ class StreamingLinearRegressionWithSGD private[mllib] (
8793
/**
8894
* Set the initial weights.
8995
*/
96+
@Since("1.1.0")
9097
def setInitialWeights(initialWeights: Vector): this.type = {
9198
this.model = Some(algorithm.createModel(initialWeights, 0.0))
9299
this
@@ -95,9 +102,9 @@ class StreamingLinearRegressionWithSGD private[mllib] (
95102
/**
96103
* Set the convergence tolerance. Default: 0.001.
97104
*/
105+
@Since("1.5.0")
98106
def setConvergenceTol(tolerance: Double): this.type = {
99107
this.algorithm.optimizer.setConvergenceTol(tolerance)
100108
this
101109
}
102-
103110
}

0 commit comments

Comments
 (0)