Skip to content

Instantly share code, notes, and snippets.

@AlexanderSavochkin
Created December 9, 2015 07:19
Show Gist options
  • Save AlexanderSavochkin/2a18c29f390263c18009 to your computer and use it in GitHub Desktop.
Save AlexanderSavochkin/2a18c29f390263c18009 to your computer and use it in GitHub Desktop.
//Logistic regression example from Saprk documentation
val points = spark.textFile(...).map(parsePoint).cache()
var w = Vector.random(D) // current separating plane
for (i <- 1 to ITERATIONS) {
val gradient = points.map(p =>
(1 / (1 + exp(-p.y*(w dot p.x))) - 1) * p.y * p.x
).reduce(_ + _)
w -= gradient
}
println("Final separating plane: " + w)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment