Class: Eps::LinearRegression

Inherits:
BaseEstimator show all
Defined in:
lib/eps/linear_regression.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseEstimator

#evaluate, extract_text_features, #initialize, #predict, #summary, #to_pmml

Constructor Details

This class inherits a constructor from Eps::BaseEstimator

Class Method Details

.load_pmml(data) ⇒ Object

pmml


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/eps/linear_regression.rb', line 5

def self.load_pmml(data)
  super do |data|
    # TODO more validation
    node = data.css("RegressionTable")

    coefficients = {
      "_intercept" => node.attribute("intercept").value.to_f
    }

    features = {}

    text_features, derived_fields = extract_text_features(data, features)

    node.css("NumericPredictor").each do |n|
      name = n.attribute("name").value
      if derived_fields[name]
        name = derived_fields[name]
      else
        features[name] = "numeric"
      end
      coefficients[name] = n.attribute("coefficient").value.to_f
    end

    node.css("CategoricalPredictor").each do |n|
      name = n.attribute("name").value
      coefficients[[name, n.attribute("value").value]] = n.attribute("coefficient").value.to_f
      features[name] = "categorical"
    end

    Evaluators::LinearRegression.new(coefficients: coefficients, features: features, text_features: text_features)
  end
end

Instance Method Details

#adjusted_r2Object


46
47
48
# File 'lib/eps/linear_regression.rb', line 46

def adjusted_r2
  @adjusted_r2 ||= (mst - mse) / mst
end

#coefficientsObject


38
39
40
# File 'lib/eps/linear_regression.rb', line 38

def coefficients
  @evaluator.coefficients
end

#r2Object


42
43
44
# File 'lib/eps/linear_regression.rb', line 42

def r2
  @r2 ||= (sst - sse) / sst
end