Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
bfade12
Added lots of classes for new ML API:
jkbradley Nov 24, 2014
d35bb5d
fixed compilation issues, but have not added tests yet
jkbradley Nov 24, 2014
52f4fde
removing everything except for simple class hierarchy for classification
jkbradley Dec 1, 2014
d705e87
Added LinearRegression and Regressor back from ml-api branch
jkbradley Dec 4, 2014
601e792
Modified ParamMap to sort parameters in toString. Cleaned up classes…
jkbradley Dec 5, 2014
0617d61
Fixed bug from last commit (sorting paramMap by parameter names in to…
jkbradley Dec 5, 2014
54b7b31
Fixed issue with logreg threshold being set correctly
jkbradley Dec 5, 2014
e433872
Updated docs. Added LabeledPointSuite to spark.ml
jkbradley Dec 5, 2014
57d54ab
* Changed semantics of Predictor.train() to merge the given paramMap …
jkbradley Dec 5, 2014
58802e3
added train() to Predictor subclasses which does not take a ParamMap.
jkbradley Dec 6, 2014
adbe50a
* fixed LinearRegression train() to use embedded paramMap
jkbradley Dec 6, 2014
1680905
Added JavaLabeledPointSuite.java for spark.ml, and added constructor …
jkbradley Dec 6, 2014
8d13233
Added methods:
jkbradley Dec 8, 2014
bc654e1
Added spark.ml LinearRegressionSuite
jkbradley Dec 8, 2014
4e2f711
rat fix
jkbradley Dec 8, 2014
1c61723
* Made ProbabilisticClassificationModel into a subclass of Classifica…
jkbradley Dec 30, 2014
934f97b
Fixed bugs from previous commit.
jkbradley Dec 30, 2014
c3c8da5
small cleanup
jkbradley Dec 30, 2014
0a16da9
Fixed Linear/Logistic RegressionSuites
jkbradley Dec 31, 2014
82f340b
Fixed bug in LogisticRegression (introduced in this PR). Fixed Java …
jkbradley Dec 31, 2014
343e7bd
added blanket mima exclude for ml package
jkbradley Dec 31, 2014
f549e34
Updates based on code review. Major ones are:
jkbradley Jan 15, 2015
216d199
fixed after sql datatypes PR got merged
jkbradley Jan 15, 2015
f542997
Added MIMA excludes for VectorUDT (now public), and added DeveloperAp…
jkbradley Jan 19, 2015
9872424
fixed JavaLinearRegressionSuite.java Java sql api
jkbradley Jan 19, 2015
bcb9549
Fixed issues after rebasing from master (after move from SchemaRDD to…
jkbradley Jan 30, 2015
fc62406
fixed test suites after last commit
jkbradley Jan 30, 2015
8316d5e
fixes after rebasing on master
jkbradley Feb 5, 2015
fec348a
Added JavaDeveloperApiExample.java and fixed other issues: Made devel…
jkbradley Feb 6, 2015
405bfb8
Last edits based on code review. Small cleanups
jkbradley Feb 6, 2015
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
Prev Previous commit
Next Next commit
Fixed bug from last commit (sorting paramMap by parameter names in to…
…String). Fixed bug in persisting logreg data. Added threshold_internal to logreg for faster test-time prediction (avoiding map lookup).
  • Loading branch information
jkbradley committed Feb 5, 2015
commit 0617d61a9b4f6927e4341564c2c274ba5844fec1
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ private[classification] trait LogisticRegressionParams extends ClassifierParams

/**
* Logistic regression.
* Currently, this class only supports binary classification.
*/
class LogisticRegression extends Classifier[LogisticRegression, LogisticRegressionModel]
with LogisticRegressionParams {
Expand All @@ -71,7 +72,8 @@ class LogisticRegression extends Classifier[LogisticRegression, LogisticRegressi
val oldDataset = dataset.map { case LabeledPoint(label: Double, features: Vector, weight) =>
org.apache.spark.mllib.regression.LabeledPoint(label, features)
}
val handlePersistence = oldDataset.getStorageLevel == StorageLevel.NONE
// If dataset is persisted, do not persist oldDataset.
val handlePersistence = dataset.getStorageLevel == StorageLevel.NONE
if (handlePersistence) {
oldDataset.persist(StorageLevel.MEMORY_AND_DISK)
}
Expand All @@ -84,6 +86,7 @@ class LogisticRegression extends Classifier[LogisticRegression, LogisticRegressi
if (handlePersistence) {
oldDataset.unpersist()
}
lrm.setThreshold(paramMap(threshold))
lrm
}
}
Expand All @@ -103,9 +106,15 @@ class LogisticRegressionModel private[ml] (
with ProbabilisticClassificationModel
with LogisticRegressionParams {

def setThreshold(value: Double): this.type = set(threshold, value)
def setThreshold(value: Double): this.type = {
this.threshold_internal = value
set(threshold, value)
}
def setScoreCol(value: String): this.type = set(scoreCol, value)

/** Store for faster test-time prediction. */
private var threshold_internal: Double = this.getThreshold

private val margin: Vector => Double = (features) => {
BLAS.dot(features, weights) + intercept
}
Expand All @@ -121,11 +130,8 @@ class LogisticRegressionModel private[ml] (
val scoreFunction = udf { v: Vector =>
val margin = BLAS.dot(v, weights)
1.0 / (1.0 + math.exp(-margin))
}
val t = map(threshold)
val predictFunction = udf { score: Double =>
if (score > t) 1.0 else 0.0
}
val t = threshold_internal
val predictFunction: Double => Double = (score) => { if (score > t) 1.0 else 0.0 }
dataset
.select($"*", scoreFunction(col(map(featuresCol))).as(map(scoreCol)))
.select($"*", predictFunction(col(map(scoreCol))).as(map(predictionCol)))
Expand All @@ -138,7 +144,7 @@ class LogisticRegressionModel private[ml] (
* The behavior of this can be adjusted using [[threshold]].
*/
override def predict(features: Vector): Double = {
if (score(features) > paramMap(threshold)) 1 else 0
if (score(features) > threshold_internal) 1 else 0
}

override def predictProbabilities(features: Vector): Vector = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ class ParamMap private[ml] (private val map: mutable.Map[Param[Any], Any]) exten
def copy: ParamMap = new ParamMap(map.clone())

override def toString: String = {
map.toSeq.sorted.map { case (param, value) =>
map.toSeq.sortBy(_._1.name).map { case (param, value) =>
s"\t${param.parent.uid}-${param.name}: $value"
}.mkString("{\n", ",\n", "\n}")
}
Expand Down