aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorYanbo Liang <ybliang8@gmail.com>2015-12-15 16:29:39 -0800
committerJoseph K. Bradley <joseph@databricks.com>2015-12-15 16:29:39 -0800
commitb24c12d7338b47b637698e7458ba90f34cba28c0 (patch)
tree2e88d1f095ebb49790401947ab611c6ace265fe7 /examples
parentbc1ff9f4a41401599d3a87fb3c23a2078228a29b (diff)
downloadspark-b24c12d7338b47b637698e7458ba90f34cba28c0.tar.gz
spark-b24c12d7338b47b637698e7458ba90f34cba28c0.tar.bz2
spark-b24c12d7338b47b637698e7458ba90f34cba28c0.zip
[MINOR][ML] Rename weights to coefficients for examples/DeveloperApiExample
Rename ```weights``` to ```coefficients``` for examples/DeveloperApiExample. cc mengxr jkbradley Author: Yanbo Liang <ybliang8@gmail.com> Closes #10280 from yanboliang/spark-coefficients.
Diffstat (limited to 'examples')
-rw-r--r--examples/src/main/java/org/apache/spark/examples/ml/JavaDeveloperApiExample.java22
-rw-r--r--examples/src/main/scala/org/apache/spark/examples/ml/DeveloperApiExample.scala16
2 files changed, 19 insertions, 19 deletions
diff --git a/examples/src/main/java/org/apache/spark/examples/ml/JavaDeveloperApiExample.java b/examples/src/main/java/org/apache/spark/examples/ml/JavaDeveloperApiExample.java
index 0b4c0d9ba9..b9dd3ad957 100644
--- a/examples/src/main/java/org/apache/spark/examples/ml/JavaDeveloperApiExample.java
+++ b/examples/src/main/java/org/apache/spark/examples/ml/JavaDeveloperApiExample.java
@@ -89,7 +89,7 @@ public class JavaDeveloperApiExample {
}
if (sumPredictions != 0.0) {
throw new Exception("MyJavaLogisticRegression predicted something other than 0," +
- " even though all weights are 0!");
+ " even though all coefficients are 0!");
}
jsc.stop();
@@ -149,12 +149,12 @@ class MyJavaLogisticRegression
// Extract columns from data using helper method.
JavaRDD<LabeledPoint> oldDataset = extractLabeledPoints(dataset).toJavaRDD();
- // Do learning to estimate the weight vector.
+ // Do learning to estimate the coefficients vector.
int numFeatures = oldDataset.take(1).get(0).features().size();
- Vector weights = Vectors.zeros(numFeatures); // Learning would happen here.
+ Vector coefficients = Vectors.zeros(numFeatures); // Learning would happen here.
// Create a model, and return it.
- return new MyJavaLogisticRegressionModel(uid(), weights).setParent(this);
+ return new MyJavaLogisticRegressionModel(uid(), coefficients).setParent(this);
}
@Override
@@ -173,12 +173,12 @@ class MyJavaLogisticRegression
class MyJavaLogisticRegressionModel
extends ClassificationModel<Vector, MyJavaLogisticRegressionModel> {
- private Vector weights_;
- public Vector weights() { return weights_; }
+ private Vector coefficients_;
+ public Vector coefficients() { return coefficients_; }
- public MyJavaLogisticRegressionModel(String uid, Vector weights) {
+ public MyJavaLogisticRegressionModel(String uid, Vector coefficients) {
this.uid_ = uid;
- this.weights_ = weights;
+ this.coefficients_ = coefficients;
}
private String uid_ = Identifiable$.MODULE$.randomUID("myJavaLogReg");
@@ -208,7 +208,7 @@ class MyJavaLogisticRegressionModel
* modifier.
*/
public Vector predictRaw(Vector features) {
- double margin = BLAS.dot(features, weights_);
+ double margin = BLAS.dot(features, coefficients_);
// There are 2 classes (binary classification), so we return a length-2 vector,
// where index i corresponds to class i (i = 0, 1).
return Vectors.dense(-margin, margin);
@@ -222,7 +222,7 @@ class MyJavaLogisticRegressionModel
/**
* Number of features the model was trained on.
*/
- public int numFeatures() { return weights_.size(); }
+ public int numFeatures() { return coefficients_.size(); }
/**
* Create a copy of the model.
@@ -235,7 +235,7 @@ class MyJavaLogisticRegressionModel
*/
@Override
public MyJavaLogisticRegressionModel copy(ParamMap extra) {
- return copyValues(new MyJavaLogisticRegressionModel(uid(), weights_), extra)
+ return copyValues(new MyJavaLogisticRegressionModel(uid(), coefficients_), extra)
.setParent(parent());
}
}
diff --git a/examples/src/main/scala/org/apache/spark/examples/ml/DeveloperApiExample.scala b/examples/src/main/scala/org/apache/spark/examples/ml/DeveloperApiExample.scala
index 3758edc561..c1f63c6a1d 100644
--- a/examples/src/main/scala/org/apache/spark/examples/ml/DeveloperApiExample.scala
+++ b/examples/src/main/scala/org/apache/spark/examples/ml/DeveloperApiExample.scala
@@ -75,7 +75,7 @@ object DeveloperApiExample {
prediction
}.sum
assert(sumPredictions == 0.0,
- "MyLogisticRegression predicted something other than 0, even though all weights are 0!")
+ "MyLogisticRegression predicted something other than 0, even though all coefficients are 0!")
sc.stop()
}
@@ -124,12 +124,12 @@ private class MyLogisticRegression(override val uid: String)
// Extract columns from data using helper method.
val oldDataset = extractLabeledPoints(dataset)
- // Do learning to estimate the weight vector.
+ // Do learning to estimate the coefficients vector.
val numFeatures = oldDataset.take(1)(0).features.size
- val weights = Vectors.zeros(numFeatures) // Learning would happen here.
+ val coefficients = Vectors.zeros(numFeatures) // Learning would happen here.
// Create a model, and return it.
- new MyLogisticRegressionModel(uid, weights).setParent(this)
+ new MyLogisticRegressionModel(uid, coefficients).setParent(this)
}
override def copy(extra: ParamMap): MyLogisticRegression = defaultCopy(extra)
@@ -142,7 +142,7 @@ private class MyLogisticRegression(override val uid: String)
*/
private class MyLogisticRegressionModel(
override val uid: String,
- val weights: Vector)
+ val coefficients: Vector)
extends ClassificationModel[Vector, MyLogisticRegressionModel]
with MyLogisticRegressionParams {
@@ -163,7 +163,7 @@ private class MyLogisticRegressionModel(
* confidence for that label.
*/
override protected def predictRaw(features: Vector): Vector = {
- val margin = BLAS.dot(features, weights)
+ val margin = BLAS.dot(features, coefficients)
// There are 2 classes (binary classification), so we return a length-2 vector,
// where index i corresponds to class i (i = 0, 1).
Vectors.dense(-margin, margin)
@@ -173,7 +173,7 @@ private class MyLogisticRegressionModel(
override val numClasses: Int = 2
/** Number of features the model was trained on. */
- override val numFeatures: Int = weights.size
+ override val numFeatures: Int = coefficients.size
/**
* Create a copy of the model.
@@ -182,7 +182,7 @@ private class MyLogisticRegressionModel(
* This is used for the default implementation of [[transform()]].
*/
override def copy(extra: ParamMap): MyLogisticRegressionModel = {
- copyValues(new MyLogisticRegressionModel(uid, weights), extra).setParent(parent)
+ copyValues(new MyLogisticRegressionModel(uid, coefficients), extra).setParent(parent)
}
}
// scalastyle:on println