Skip to content
Snippets Groups Projects
Commit b24c12d7 authored by Yanbo Liang's avatar Yanbo Liang Committed by Joseph K. Bradley
Browse files

[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.
parent bc1ff9f4
No related branches found
No related tags found
No related merge requests found
......@@ -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());
}
}
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment