class Spark::Mllib::RegressionModel
A linear model that has a vector of coefficients and an intercept.
Attributes
intercept[R]
weights[R]
Public Class Methods
new(weights, intercept)
click to toggle source
# File lib/spark/mllib/regression/common.rb, line 12 def initialize(weights, intercept) @weights = Spark::Mllib::Vectors.to_vector(weights) @intercept = intercept.to_f end
Public Instance Methods
predict(data)
click to toggle source
Predict the value of the dependent variable given a vector data containing values for the independent variables.
Examples:¶ ↑
lm = RegressionModel.new([1.0, 2.0], 0.1) lm.predict([-1.03, 7.777]) - 14.624 < 1e-6 # => true lm.predict(SparseVector.new(2, {0 => -1.03, 1 => 7.777})) - 14.624 < 1e-6 # => true
# File lib/spark/mllib/regression/common.rb, line 29 def predict(data) data = Spark::Mllib::Vectors.to_vector(data) @weights.dot(data) + @intercept end