Skip to content

Instantly share code, notes, and snippets.

@earino
Created February 4, 2014 03:30
Show Gist options
  • Save earino/8797738 to your computer and use it in GitHub Desktop.
Save earino/8797738 to your computer and use it in GitHub Desktop.
Logistic Regression Example from http://spark.incubator.apache.org/examples.html
points = spark.textFile(...).map(parsePoint).cache()
w = numpy.random.ranf(size = D) # current separating plane
for i in range(ITERATIONS):
gradient = points.map(
lambda p: (1 / (1 + exp(-p.y*(w.dot(p.x)))) - 1) * p.y * p.x
).reduce(lambda a, b: a + b)
w -= gradient
print "Final separating plane: %s" % w
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment