Skip to content

Commit 934f97b

Browse files
committed
Fixed bugs from previous commit.
1 parent 1c61723 commit 934f97b

File tree

15 files changed

+43
-172
lines changed

15 files changed

+43
-172
lines changed

examples/src/main/java/org/apache/spark/examples/ml/JavaSimpleParamsExample.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public static void main(String[] args) {
102102
// 'probability' column since we renamed the lr.probabilityCol parameter previously.
103103
model2.transform(test).registerTempTable("results");
104104
DataFrame results =
105-
jsql.sql("SELECT features, label, probability, prediction FROM results");
105+
jsql.sql("SELECT features, label, myProbability, prediction FROM results");
106106
for (Row r: results.collect()) {
107107
System.out.println("(" + r.get(0) + ", " + r.get(1) + ") -> prob=" + r.get(2)
108108
+ ", prediction=" + r.get(3));

examples/src/main/scala/org/apache/spark/examples/ml/DeveloperApiExample.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ object DeveloperApiExample {
4343
import sqlContext._
4444

4545
// Prepare training data.
46-
// We use LabeledPoint, which is a case class. Spark SQL can convert RDDs of Java Beans
47-
// into SchemaRDDs, where it uses the bean metadata to infer the schema.
4846
val training = sparkContext.parallelize(Seq(
4947
LabeledPoint(1.0, Vectors.dense(0.0, 1.1, 0.1)),
5048
LabeledPoint(0.0, Vectors.dense(2.0, 1.0, -1.0)),

examples/src/main/scala/org/apache/spark/examples/ml/SimpleParamsExample.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ object SimpleParamsExample {
9393
model2.transform(test)
9494
.select('features, 'label, 'myProbability, 'prediction)
9595
.collect()
96-
.foreach { case Row(features: Vector, label: Double, prob: Double, prediction: Double) =>
96+
.foreach { case Row(features: Vector, label: Double, prob: Vector, prediction: Double) =>
9797
println("(" + features + ", " + label + ") -> prob=" + prob + ", prediction=" + prediction)
9898
}
9999

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717

1818
package org.apache.spark.ml.classification
1919

20-
import scala.reflect.runtime.universe._
21-
2220
import org.apache.spark.annotation.{DeveloperApi, AlphaComponent}
2321
import org.apache.spark.ml.impl.estimator.{PredictionModel, Predictor, PredictorParams}
2422
import org.apache.spark.ml.param.{Params, ParamMap, HasRawPredictionCol}
@@ -62,8 +60,6 @@ abstract class Classifier[
6260
extends Predictor[FeaturesType, Learner, M]
6361
with ClassifierParams {
6462

65-
setRawPredictionCol("") // Do not output by default
66-
6763
def setRawPredictionCol(value: String): Learner =
6864
set(rawPredictionCol, value).asInstanceOf[Learner]
6965

@@ -82,8 +78,6 @@ abstract class Classifier[
8278
abstract class ClassificationModel[FeaturesType, M <: ClassificationModel[FeaturesType, M]]
8379
extends PredictionModel[FeaturesType, M] with ClassifierParams {
8480

85-
setRawPredictionCol("") // Do not output by default
86-
8781
def setRawPredictionCol(value: String): M = set(rawPredictionCol, value).asInstanceOf[M]
8882

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

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ package org.apache.spark.ml.classification
2020
import org.apache.spark.annotation.AlphaComponent
2121
import org.apache.spark.ml.param._
2222
import org.apache.spark.mllib.classification.LogisticRegressionWithLBFGS
23-
import org.apache.spark.mllib.linalg.{VectorUDT, Vectors, BLAS, Vector}
23+
import org.apache.spark.mllib.linalg.{BLAS, Vector, VectorUDT, Vectors}
2424
import org.apache.spark.sql._
2525
import org.apache.spark.sql.Dsl._
2626
import org.apache.spark.sql.types.{DoubleType, StructField, StructType}
@@ -35,6 +35,7 @@ private[classification] trait LogisticRegressionParams extends ProbabilisticClas
3535

3636
/**
3737
* :: AlphaComponent ::
38+
*
3839
* Logistic regression.
3940
* Currently, this class only supports binary classification.
4041
*/
@@ -86,6 +87,7 @@ class LogisticRegression
8687

8788
/**
8889
* :: AlphaComponent ::
90+
*
8991
* Model produced by [[LogisticRegression]].
9092
*/
9193
@AlphaComponent

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717

1818
package org.apache.spark.ml.classification
1919

20-
import scala.reflect.runtime.universe._
21-
2220
import org.apache.spark.annotation.{AlphaComponent, DeveloperApi}
2321
import org.apache.spark.ml.param.{HasProbabilityCol, ParamMap, Params}
2422
import org.apache.spark.mllib.linalg.{Vector, VectorUDT}
@@ -42,8 +40,10 @@ private[classification] trait ProbabilisticClassifierParams
4240
}
4341
}
4442

43+
4544
/**
4645
* :: AlphaComponent ::
46+
*
4747
* Single-label binary or multiclass classifier which can output class conditional probabilities.
4848
*
4949
* @tparam FeaturesType Type of input features. E.g., [[Vector]]
@@ -57,13 +57,13 @@ abstract class ProbabilisticClassifier[
5757
M <: ProbabilisticClassificationModel[FeaturesType, M]]
5858
extends Classifier[FeaturesType, Learner, M] with ProbabilisticClassifierParams {
5959

60-
setProbabilityCol("") // Do not output by default
61-
6260
def setProbabilityCol(value: String): Learner = set(probabilityCol, value).asInstanceOf[Learner]
6361
}
6462

63+
6564
/**
6665
* :: AlphaComponent ::
66+
*
6767
* Model produced by a [[ProbabilisticClassifier]].
6868
* Classes are indexed {0, 1, ..., numClasses - 1}.
6969
*
@@ -76,8 +76,6 @@ abstract class ProbabilisticClassificationModel[
7676
M <: ProbabilisticClassificationModel[FeaturesType, M]]
7777
extends ClassificationModel[FeaturesType, M] with ProbabilisticClassifierParams {
7878

79-
setProbabilityCol("") // Do not output by default
80-
8179
def setProbabilityCol(value: String): M = set(probabilityCol, value).asInstanceOf[M]
8280

8381
/**

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import org.apache.spark.sql.types.DoubleType
2727

2828
/**
2929
* :: AlphaComponent ::
30+
*
3031
* Evaluator for binary classification, which expects two input columns: score and label.
3132
*/
3233
@AlphaComponent

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

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

1818
package org.apache.spark.ml.impl.estimator
1919

20-
import org.apache.spark.annotation.DeveloperApi
20+
import org.apache.spark.annotation.{AlphaComponent, DeveloperApi}
2121
import org.apache.spark.ml.{Estimator, Model}
2222
import org.apache.spark.ml.param._
2323
import org.apache.spark.mllib.linalg.Vector
@@ -62,6 +62,8 @@ trait PredictorParams extends Params
6262
}
6363

6464
/**
65+
* :: AlphaComponent ::
66+
*
6567
* Abstraction for prediction problems (regression and classification).
6668
*
6769
* @tparam FeaturesType Type of features.
@@ -71,7 +73,7 @@ trait PredictorParams extends Params
7173
* @tparam M Specialization of [[PredictionModel]]. If you subclass this type, use this type
7274
* parameter to specify the concrete type for the corresponding model.
7375
*/
74-
@DeveloperApi
76+
@AlphaComponent
7577
abstract class Predictor[
7678
FeaturesType,
7779
Learner <: Predictor[FeaturesType, Learner, M],
@@ -124,7 +126,18 @@ abstract class Predictor[
124126
}
125127
}
126128

127-
private[ml] abstract class PredictionModel[FeaturesType, M <: PredictionModel[FeaturesType, M]]
129+
/**
130+
* :: AlphaComponent ::
131+
*
132+
* Abstraction for a model for prediction tasks (regression and classification).
133+
*
134+
* @tparam FeaturesType Type of features.
135+
* E.g., [[org.apache.spark.mllib.linalg.VectorUDT]] for vector features.
136+
* @tparam M Specialization of [[PredictionModel]]. If you subclass this type, use this type
137+
* parameter to specify the concrete type for the corresponding model.
138+
*/
139+
@AlphaComponent
140+
abstract class PredictionModel[FeaturesType, M <: PredictionModel[FeaturesType, M]]
128141
extends Model[M] with PredictorParams {
129142

130143
def setFeaturesCol(value: String): M = set(featuresCol, value).asInstanceOf[M]

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,12 @@ package org.apache.spark.ml.param
1919

2020
import scala.annotation.varargs
2121
import scala.collection.mutable
22-
import scala.reflect.runtime.universe._
2322

2423
import java.lang.reflect.Modifier
2524

26-
import org.apache.spark.annotation.{DeveloperApi, AlphaComponent}
25+
import org.apache.spark.annotation.{AlphaComponent, DeveloperApi}
2726
import org.apache.spark.ml.Identifiable
2827
import org.apache.spark.sql._
29-
import org.apache.spark.sql.catalyst.ScalaReflection
3028

3129
/**
3230
* :: AlphaComponent ::

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ private[regression] trait LinearRegressionParams extends RegressorParams
3232

3333
/**
3434
* :: AlphaComponent ::
35-
* Logistic regression.
35+
*
36+
* Linear regression.
3637
*/
3738
@AlphaComponent
3839
class LinearRegression extends Regressor[Vector, LinearRegression, LinearRegressionModel]
@@ -78,6 +79,7 @@ class LinearRegression extends Regressor[Vector, LinearRegression, LinearRegress
7879

7980
/**
8081
* :: AlphaComponent ::
82+
*
8183
* Model produced by [[LinearRegression]].
8284
*/
8385
@AlphaComponent

0 commit comments

Comments
 (0)