Class: Spark::Mllib::RidgeRegressionModel

Inherits:
RegressionModel show all
Defined in:
lib/spark/mllib/regression/ridge.rb

Overview

RidgeRegressionModel

Train a regression model with L2-regularization using Stochastic Gradient Descent. This solves the l1-regularized least squares regression formulation

f(weights) = 1/2n ||A weights-y||^2^  + regParam/2 ||weights||^2^

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

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 = RidgeRegressionWithSGD.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

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

Instance Attribute Summary

Attributes inherited from RegressionModel

#intercept, #weights

Method Summary

Methods inherited from RegressionModel

#initialize, #predict

Constructor Details

This class inherits a constructor from Spark::Mllib::RegressionModel