Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import org.apache.spark.rdd.RDD
*
* @param weights Weights computed for every feature.
* @param intercept Intercept computed for this model. (Only used in Binary Logistic Regression.
* In Multinomial Logistic Regression, the intercepts will not be a single values,
* In Multinomial Logistic Regression, the intercepts will not be a single value,
* so the intercepts will be part of the weights.)
* @param numFeatures the dimension of the features.
* @param numClasses the number of possible outcomes for k classes classification problem in
Expand Down Expand Up @@ -107,7 +107,7 @@ class LogisticRegressionModel (
// If dataMatrix and weightMatrix have the same dimension, it's binary logistic regression.
if (numClasses == 2) {
require(numFeatures == weightMatrix.size)
val margin = dot(weights, dataMatrix) + intercept
val margin = dot(weightMatrix, dataMatrix) + intercept
val score = 1.0 / (1.0 + math.exp(-margin))
threshold match {
case Some(t) => if (score > t) 1.0 else 0.0
Expand All @@ -116,11 +116,11 @@ class LogisticRegressionModel (
} else {
val dataWithBiasSize = weightMatrix.size / (numClasses - 1)

val weightsArray = weights match {
val weightsArray = weightMatrix match {
case dv: DenseVector => dv.values
case _ =>
throw new IllegalArgumentException(
s"weights only supports dense vector but got type ${weights.getClass}.")
s"weights only supports dense vector but got type ${weightMatrix.getClass}.")
}

val margins = (0 until numClasses - 1).map { i =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void logisticRegressionWithSetters() {
.setThreshold(0.6)
.setProbabilityCol("myProbability");
LogisticRegressionModel model = lr.fit(dataset);
assert(model.fittingParamMap().apply(lr.maxIter()) == 10);
assert(model.fittingParamMap().apply(lr.maxIter()).equals(10));
assert(model.fittingParamMap().apply(lr.regParam()).equals(1.0));
assert(model.fittingParamMap().apply(lr.threshold()).equals(0.6));
assert(model.getThreshold() == 0.6);
Expand All @@ -109,7 +109,7 @@ public void logisticRegressionWithSetters() {
// Call fit() with new params, and check as many params as we can.
LogisticRegressionModel model2 = lr.fit(dataset, lr.maxIter().w(5), lr.regParam().w(0.1),
lr.threshold().w(0.4), lr.probabilityCol().w("theProb"));
assert(model2.fittingParamMap().apply(lr.maxIter()) == 5);
assert(model2.fittingParamMap().apply(lr.maxIter()).equals(5));
assert(model2.fittingParamMap().apply(lr.regParam()).equals(0.1));
assert(model2.fittingParamMap().apply(lr.threshold()).equals(0.4));
assert(model2.getThreshold() == 0.4);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ public void linearRegressionWithSetters() {
.setMaxIter(10)
.setRegParam(1.0);
LinearRegressionModel model = lr.fit(dataset);
assert(model.fittingParamMap().apply(lr.maxIter()) == 10);
assert(model.fittingParamMap().apply(lr.maxIter()).equals(10));
assert(model.fittingParamMap().apply(lr.regParam()).equals(1.0));

// Call fit() with new params, and check as many params as we can.
LinearRegressionModel model2 =
lr.fit(dataset, lr.maxIter().w(5), lr.regParam().w(0.1), lr.predictionCol().w("thePred"));
assert(model2.fittingParamMap().apply(lr.maxIter()) == 5);
assert(model2.fittingParamMap().apply(lr.maxIter()).equals(5));
assert(model2.fittingParamMap().apply(lr.regParam()).equals(0.1));
assert(model2.getPredictionCol().equals("thePred"));
}
Expand Down