class Spark::Mllib::LassoModel
Train a regression model with L1-regularization using Stochastic Gradient Descent. This solves the l1-regularized least squares regression formulation
f(weights) = 1/2n ||A weights-y||^2^ + regParam ||weights||_1
Here the data matrix has n rows, and the input RDD holds the set of rows of A, each with its corresponding right hand side label y. See also the documentation for the precise formulation.
Examples:¶ ↑
Spark::Mllib.import # Dense vectors data = [ LabeledPoint.new(0.0, [0.0]), LabeledPoint.new(1.0, [1.0]), LabeledPoint.new(3.0, [2.0]), LabeledPoint.new(2.0, [3.0]) ] lrm = LassoWithSGD.train($sc.parallelize(data), initial_weights: [1.0]) lrm.predict([0.0]) - 0 < 0.5 # => true lrm.predict([1.0]) - 1 < 0.5 # => true lrm.predict(SparseVector.new(1, {0 => 1.0})) - 1 < 0.5 # => true # Sparse vectors data = [ LabeledPoint.new(0.0, SparseVector.new(1, {0 => 0.0})), LabeledPoint.new(1.0, SparseVector.new(1, {0 => 1.0})), LabeledPoint.new(3.0, SparseVector.new(1, {0 => 2.0})), LabeledPoint.new(2.0, SparseVector.new(1, {0 => 3.0})) ] lrm = LinearRegressionWithSGD.train($sc.parallelize(data), initial_weights: [1.0]) lrm.predict([0.0]) - 0 < 0.5 # => true lrm.predict(SparseVector.new(1, {0 => 1.0})) - 1 < 0.5 # => true