Module: Rumale::Base::Classifier
- Included in:
- Ensemble::AdaBoostClassifier, Ensemble::GradientBoostingClassifier, Ensemble::RandomForestClassifier, Ensemble::StackingClassifier, Ensemble::VotingClassifier, KernelMachine::KernelRidgeClassifier, KernelMachine::KernelSVC, LinearModel::LogisticRegression, LinearModel::SGDClassifier, LinearModel::SVC, NaiveBayes::BaseNaiveBayes, NearestNeighbors::KNeighborsClassifier, NeuralNetwork::MLPClassifier, NeuralNetwork::RBFClassifier, NeuralNetwork::RVFLClassifier, Tree::DecisionTreeClassifier
- Defined in:
- rumale-core/lib/rumale/base/classifier.rb
Overview
Module for all classifiers 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 mean accuracy of the given testing data.
Instance Method Details
#fit ⇒ Object
An abstract method for fitting a model.
12 13 14 |
# File 'rumale-core/lib/rumale/base/classifier.rb', line 12 def fit raise NotImplementedError, "#{__method__} has to be implemented in #{self.class}." end |
#predict ⇒ Object
An abstract method for predicting labels.
17 18 19 |
# File 'rumale-core/lib/rumale/base/classifier.rb', line 17 def predict raise NotImplementedError, "#{__method__} has to be implemented in #{self.class}." end |
#score(x, y) ⇒ Float
Calculate the mean accuracy of the given testing data.
26 27 28 29 30 31 32 33 |
# File 'rumale-core/lib/rumale/base/classifier.rb', line 26 def score(x, y) x = ::Rumale::Validation.check_convert_sample_array(x) y = ::Rumale::Validation.check_convert_label_array(y) ::Rumale::Validation.check_sample_size(x, y) predicted = predict(x) (y.to_a.map.with_index { |label, n| label == predicted[n] ? 1 : 0 }).sum.fdiv(y.size) end |