Skip to content

Instantly share code, notes, and snippets.

@lakshay-arora
Last active October 22, 2019 12:20
Show Gist options
  • Save lakshay-arora/dd70bb710151775e42b65bad8ecaf762 to your computer and use it in GitHub Desktop.
Save lakshay-arora/dd70bb710151775e42b65bad8ecaf762 to your computer and use it in GitHub Desktop.
# define a labeled point
point_2 = LabeledPoint(1,Vectors.sparse(10, [0,1,6], [2,4,5]))
# features of labeled point
print(point_2.features)
# >> SparseVector(10, {0: 2.0, 1: 4.0, 6: 5.0})
# label
print(point_2.label)
# >> 1.0
# a classification problem data might look like this, one label against a set of features
data = [
LabeledPoint(1, Vectors.sparse(5, [0,1,3], [3,1,3])),
LabeledPoint(1, Vectors.sparse(5, [0,2,4], [2,3,4])),
LabeledPoint(0, Vectors.sparse(5, [1,3,4], [2,2,1])),
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment