Module: Rumale::Base::Regressor
- Included in:
- Ensemble::AdaBoostRegressor, Ensemble::GradientBoostingRegressor, Ensemble::RandomForestRegressor, Ensemble::StackingRegressor, Ensemble::VotingRegressor, KernelMachine::KernelRidge, LinearModel::ElasticNet, LinearModel::Lasso, LinearModel::LinearRegression, LinearModel::NNLS, LinearModel::Ridge, LinearModel::SGDRegressor, LinearModel::SVR, NearestNeighbors::KNeighborsRegressor, NeuralNetwork::MLPRegressor, NeuralNetwork::RBFRegressor, NeuralNetwork::RVFLRegressor, Tree::DecisionTreeRegressor, Tree::GradientTreeRegressor
- Defined in:
- rumale-core/lib/rumale/base/regressor.rb
Overview
Module for all regressors in Rumale.
Instance Method Summary collapse
-
#fit ⇒ Object
An abstract method for fitting a model.
-
#predict ⇒ Object
An abstract method for predicting labels.
-
#score(x, y) ⇒ Float
Calculate the coefficient of determination for the given testing data.
Instance Method Details
#fit ⇒ Object
An abstract method for fitting a model.
10 11 12 |
# File 'rumale-core/lib/rumale/base/regressor.rb', line 10 def fit raise NotImplementedError, "#{__method__} has to be implemented in #{self.class}." end |
#predict ⇒ Object
An abstract method for predicting labels.
15 16 17 |
# File 'rumale-core/lib/rumale/base/regressor.rb', line 15 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.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'rumale-core/lib/rumale/base/regressor.rb', line 24 def score(x, y) x = ::Rumale::Validation.check_convert_sample_array(x) y = ::Rumale::Validation.check_convert_target_value_array(y) ::Rumale::Validation.check_sample_size(x, y) predicted = predict(x) n_samples, n_outputs = y.shape numerator = ((y - predicted)**2).sum(axis: 0) yt_mean = y.sum(axis: 0) / n_samples denominator = ((y - yt_mean)**2).sum(axis: 0) if n_outputs.nil? denominator.zero? ? 0.0 : 1.0 - numerator.fdiv(denominator) else scores = 1.0 - numerator / denominator scores[denominator.eq(0)] = 0.0 scores.sum.fdiv(scores.size) end end |