Module: Rumale::Base::Regressor

Overview

Module for all regressors in Rumale.

Instance Method Summary collapse

Instance Method Details

#fitObject

An abstract method for fitting a model.

Raises:

  • (NotImplementedError)


13
14
15
# File 'lib/rumale/base/regressor.rb', line 13

def fit
  raise NotImplementedError, "#{__method__} has to be implemented in #{self.class}."
end

#predictObject

An abstract method for predicting labels.

Raises:

  • (NotImplementedError)


18
19
20
# File 'lib/rumale/base/regressor.rb', line 18

def predict
  raise NotImplementedError, "#{__method__} has to be implemented in #{self.class}."
end

#score(x, y) ⇒ Float

Calculate the coefficient of determination for the given testing data.

Parameters:

  • x (Numo::DFloat)

    (shape: [n_samples, n_features]) Testing data.

  • y (Numo::DFloat)

    (shape: [n_samples, n_outputs]) Target values for testing data.

Returns:

  • (Float)

    Coefficient of determination



27
28
29
30
31
32
33
# File 'lib/rumale/base/regressor.rb', line 27

def score(x, y)
  check_sample_array(x)
  check_tvalue_array(y)
  check_sample_tvalue_size(x, y)
  evaluator = Rumale::EvaluationMeasure::R2Score.new
  evaluator.score(y, predict(x))
end