Class: Spark::Mllib::RegressionModel
- Inherits:
-
Object
- Object
- Spark::Mllib::RegressionModel
- Defined in:
- lib/spark/mllib/regression/common.rb
Overview
RegressionModel
A linear model that has a vector of coefficients and an intercept.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#intercept ⇒ Object
readonly
Returns the value of attribute intercept.
-
#weights ⇒ Object
readonly
Returns the value of attribute weights.
Instance Method Summary collapse
-
#initialize(weights, intercept) ⇒ RegressionModel
constructor
A new instance of RegressionModel.
-
#predict(data) ⇒ Object
Predict the value of the dependent variable given a vector data containing values for the independent variables.
Constructor Details
#initialize(weights, intercept) ⇒ RegressionModel
Returns a new instance of RegressionModel.
12 13 14 15 |
# 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 |
Instance Attribute Details
#intercept ⇒ Object (readonly)
Returns the value of attribute intercept.
10 11 12 |
# File 'lib/spark/mllib/regression/common.rb', line 10 def intercept @intercept end |
#weights ⇒ Object (readonly)
Returns the value of attribute weights.
10 11 12 |
# File 'lib/spark/mllib/regression/common.rb', line 10 def weights @weights end |
Instance Method Details
#predict(data) ⇒ Object
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
29 30 31 32 |
# File 'lib/spark/mllib/regression/common.rb', line 29 def predict(data) data = Spark::Mllib::Vectors.to_vector(data) @weights.dot(data) + @intercept end |