You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by jk...@apache.org on 2015/12/16 01:29:44 UTC

spark git commit: [MINOR][ML] Rename weights to coefficients for examples/DeveloperApiExample

Repository: spark
Updated Branches:
  refs/heads/master bc1ff9f4a -> b24c12d73


[MINOR][ML] Rename weights to coefficients for examples/DeveloperApiExample

Rename ```weights``` to ```coefficients``` for examples/DeveloperApiExample.

cc mengxr jkbradley

Author: Yanbo Liang <yb...@gmail.com>

Closes #10280 from yanboliang/spark-coefficients.


Project: http://git-wip-us.apache.org/repos/asf/spark/repo
Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/b24c12d7
Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/b24c12d7
Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/b24c12d7

Branch: refs/heads/master
Commit: b24c12d7338b47b637698e7458ba90f34cba28c0
Parents: bc1ff9f
Author: Yanbo Liang <yb...@gmail.com>
Authored: Tue Dec 15 16:29:39 2015 -0800
Committer: Joseph K. Bradley <jo...@databricks.com>
Committed: Tue Dec 15 16:29:39 2015 -0800

----------------------------------------------------------------------
 .../examples/ml/JavaDeveloperApiExample.java    | 22 ++++++++++----------
 .../spark/examples/ml/DeveloperApiExample.scala | 16 +++++++-------
 2 files changed, 19 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/spark/blob/b24c12d7/examples/src/main/java/org/apache/spark/examples/ml/JavaDeveloperApiExample.java
----------------------------------------------------------------------
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 0b4c0d9..b9dd3ad 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());
   }
 }

http://git-wip-us.apache.org/repos/asf/spark/blob/b24c12d7/examples/src/main/scala/org/apache/spark/examples/ml/DeveloperApiExample.scala
----------------------------------------------------------------------
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 3758edc..c1f63c6 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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org