Implements Logistic Regression classifier. More...
#include <opencv2/ml.hpp>
Public Types | |
enum | Flags { UPDATE_MODEL = 1, RAW_OUTPUT =1, COMPRESSED_INPUT =2, PREPROCESSED_INPUT =4 } |
Predict options. More... | |
enum | Methods { BATCH = 0, MINI_BATCH = 1 } |
Training methods. More... | |
enum | RegKinds { REG_DISABLE = -1, REG_L1 = 0, REG_L2 = 1 } |
Regularization kinds. More... | |
Public Member Functions | |
virtual float | calcError (const Ptr< TrainData > &data, bool test, OutputArray resp) const |
Computes error on the training or test dataset. More... | |
virtual void | clear () |
Clears the algorithm state. More... | |
virtual bool | empty () const CV_OVERRIDE |
Returns true if the Algorithm is empty (e.g. More... | |
virtual Mat | get_learnt_thetas () const =0 |
This function returns the trained parameters arranged across rows. More... | |
virtual String | getDefaultName () const |
Returns the algorithm string identifier. More... | |
virtual int | getIterations () const =0 |
Number of iterations. More... | |
virtual double | getLearningRate () const =0 |
Learning rate. More... | |
virtual int | getMiniBatchSize () const =0 |
Specifies the number of training samples taken in each step of Mini-Batch Gradient Descent. More... | |
virtual int | getRegularization () const =0 |
Kind of regularization to be applied. More... | |
virtual TermCriteria | getTermCriteria () const =0 |
Termination criteria of the algorithm. More... | |
virtual int | getTrainMethod () const =0 |
Kind of training method used. More... | |
virtual int | getVarCount () const =0 |
Returns the number of variables in training samples. More... | |
virtual bool | isClassifier () const =0 |
Returns true if the model is classifier. More... | |
virtual bool | isTrained () const =0 |
Returns true if the model is trained. More... | |
virtual float | predict (InputArray samples, OutputArray results=noArray(), int flags=0) const CV_OVERRIDE=0 |
Predicts responses for input samples and returns a float type. More... | |
virtual void | read (const FileNode &fn) |
Reads algorithm parameters from a file storage. More... | |
virtual void | save (const String &filename) const |
Saves the algorithm to a file. More... | |
virtual void | setIterations (int val)=0 |
Number of iterations. More... | |
virtual void | setLearningRate (double val)=0 |
Learning rate. More... | |
virtual void | setMiniBatchSize (int val)=0 |
Specifies the number of training samples taken in each step of Mini-Batch Gradient Descent. More... | |
virtual void | setRegularization (int val)=0 |
Kind of regularization to be applied. More... | |
virtual void | setTermCriteria (TermCriteria val)=0 |
Termination criteria of the algorithm. More... | |
virtual void | setTrainMethod (int val)=0 |
Kind of training method used. More... | |
virtual bool | train (const Ptr< TrainData > &trainData, int flags=0) |
Trains the statistical model. More... | |
virtual bool | train (InputArray samples, int layout, InputArray responses) |
Trains the statistical model. More... | |
virtual void | write (FileStorage &fs) const |
Stores algorithm parameters in a file storage. More... | |
void | write (const Ptr< FileStorage > &fs, const String &name=String()) const |
simplified API for language bindings This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More... | |
Static Public Member Functions | |
static Ptr< LogisticRegression > | create () |
Creates empty model. More... | |
static Ptr< LogisticRegression > | load (const String &filepath, const String &nodeName=String()) |
Loads and creates a serialized LogisticRegression from a file. More... | |
template<typename _Tp > | |
static Ptr< _Tp > | loadFromString (const String &strModel, const String &objname=String()) |
Loads algorithm from a String. More... | |
template<typename _Tp > | |
static Ptr< _Tp > | read (const FileNode &fn) |
Reads algorithm from the file node. More... | |
template<typename _Tp > | |
static Ptr< _Tp > | train (const Ptr< TrainData > &data, int flags=0) |
Create and train model with default parameters. More... | |
Protected Member Functions | |
void | writeFormat (FileStorage &fs) const |
Implements Logistic Regression classifier.
|
inherited |
|
virtualinherited |
Computes error on the training or test dataset.
data | the training data |
test | if true, the error is computed over the test subset of the data, otherwise it's computed over the training subset of the data. Please note that if you loaded a completely different dataset to evaluate already trained classifier, you will probably want not to set the test subset at all with TrainData::setTrainTestSplitRatio and specify test=false, so that the error is computed for the whole new set. Yes, this sounds a bit confusing. |
resp | the optional output responses. |
The method uses StatModel::predict to compute the error. For regression models the error is computed as RMS, for classifiers - as a percent of missclassified samples (0%-100%).
|
inlinevirtualinherited |
Clears the algorithm state.
Reimplemented in cv::FlannBasedMatcher, and cv::DescriptorMatcher.
|
static |
Creates empty model.
Creates Logistic Regression model with parameters given.
|
virtualinherited |
Returns true if the Algorithm is empty (e.g.
in the very beginning or after unsuccessful read
Reimplemented from cv::Algorithm.
|
pure virtual |
This function returns the trained parameters arranged across rows.
For a two class classifcation problem, it returns a row matrix. It returns learnt parameters of the Logistic Regression as a matrix of type CV_32F.
|
virtualinherited |
Returns the algorithm string identifier.
This string is used as top level xml/yml node tag when the object is saved to a file or string.
Reimplemented in cv::AKAZE, cv::KAZE, cv::SimpleBlobDetector, cv::GFTTDetector, cv::AgastFeatureDetector, cv::FastFeatureDetector, cv::MSER, cv::ORB, cv::BRISK, and cv::Feature2D.
|
pure virtual |
Number of iterations.
|
pure virtual |
Learning rate.
|
pure virtual |
Specifies the number of training samples taken in each step of Mini-Batch Gradient Descent.
Will only be used if using LogisticRegression::MINI_BATCH training algorithm. It has to take values less than the total number of training samples.
|
pure virtual |
|
pure virtual |
Termination criteria of the algorithm.
|
pure virtual |
|
pure virtualinherited |
Returns the number of variables in training samples.
|
pure virtualinherited |
Returns true if the model is classifier.
|
pure virtualinherited |
Returns true if the model is trained.
|
static |
Loads and creates a serialized LogisticRegression from a file.
Use LogisticRegression::save to serialize and store an LogisticRegression to disk. Load the LogisticRegression from this file again, by calling this function with the path to the file. Optionally specify the node for the file containing the classifier
filepath | path to serialized LogisticRegression |
nodeName | name of node containing the classifier |
|
inlinestaticinherited |
Loads algorithm from a String.
strModel | The string variable containing the model you want to load. |
objname | The optional name of the node to read (if empty, the first top-level node will be used) |
This is static template method of Algorithm. It's usage is following (in the case of SVM):
References CV_WRAP, cv::FileNode::empty(), cv::FileStorage::getFirstTopLevelNode(), cv::FileStorage::MEMORY, and cv::FileStorage::READ.
|
pure virtual |
Predicts responses for input samples and returns a float type.
samples | The input data for the prediction algorithm. Matrix [m x n], where each row contains variables (features) of one object being classified. Should have data type CV_32F. |
results | Predicted labels as a column matrix of type CV_32S. |
flags | Not used. |
Implements cv::ml::StatModel.
|
inlinevirtualinherited |
Reads algorithm parameters from a file storage.
Reimplemented in cv::FlannBasedMatcher, cv::DescriptorMatcher, and cv::Feature2D.
|
inlinestaticinherited |
Reads algorithm from the file node.
This is static template method of Algorithm. It's usage is following (in the case of SVM):
In order to make this method work, the derived class must overwrite Algorithm::read(const FileNode& fn) and also have static create() method without parameters (or with all the optional parameters)
|
virtualinherited |
Saves the algorithm to a file.
In order to make this method work, the derived class must implement Algorithm::write(FileStorage& fs).
|
pure virtual |
Number of iterations.
|
pure virtual |
Learning rate.
|
pure virtual |
Specifies the number of training samples taken in each step of Mini-Batch Gradient Descent.
|
pure virtual |
Kind of regularization to be applied.
|
pure virtual |
Termination criteria of the algorithm.
|
pure virtual |
Kind of training method used.
|
virtualinherited |
Trains the statistical model.
trainData | training data that can be loaded from file using TrainData::loadFromCSV or created with TrainData::create. |
flags | optional flags, depending on the model. Some of the models can be updated with the new training samples, not completely overwritten (such as NormalBayesClassifier or ANN_MLP). |
|
virtualinherited |
Trains the statistical model.
samples | training samples |
layout | See ml::SampleTypes. |
responses | vector of responses associated with the training samples. |
|
inlinestaticinherited |
Create and train model with default parameters.
The class must implement static create()
method with no parameters or with all default parameter values
|
inlinevirtualinherited |
Stores algorithm parameters in a file storage.
Reimplemented in cv::FlannBasedMatcher, cv::DescriptorMatcher, and cv::Feature2D.
References CV_WRAP.
Referenced by cv::Feature2D::write(), and cv::DescriptorMatcher::write().
|
inherited |
simplified API for language bindings This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
|
protectedinherited |