![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
opencv on mbed
LogisticRegression Class Reference
[Machine Learning]
Implements Logistic Regression classifier. More...
#include <ml.hpp>
Inherits cv::ml::StatModel.
Public Types | |
enum | RegKinds { REG_DISABLE = -1, REG_L1 = 0, REG_L2 = 1 } |
Regularization kinds. More... | |
enum | Methods { , MINI_BATCH = 1 } |
Training methods. More... | |
enum | Flags { , RAW_OUTPUT = 1 } |
Predict options. More... | |
Public Member Functions | |
virtual CV_WRAP double | getLearningRate () const =0 |
Learning rate. | |
virtual CV_WRAP void | setLearningRate (double val)=0 |
Learning rate. | |
virtual CV_WRAP int | getIterations () const =0 |
Number of iterations. | |
virtual CV_WRAP void | setIterations (int val)=0 |
Number of iterations. | |
virtual CV_WRAP int | getRegularization () const =0 |
Kind of regularization to be applied. | |
virtual CV_WRAP void | setRegularization (int val)=0 |
Kind of regularization to be applied. | |
virtual CV_WRAP int | getTrainMethod () const =0 |
Kind of training method used. | |
virtual CV_WRAP void | setTrainMethod (int val)=0 |
Kind of training method used. | |
virtual CV_WRAP int | getMiniBatchSize () const =0 |
Specifies the number of training samples taken in each step of Mini-Batch Gradient Descent. | |
virtual CV_WRAP void | setMiniBatchSize (int val)=0 |
Specifies the number of training samples taken in each step of Mini-Batch Gradient Descent. | |
virtual CV_WRAP TermCriteria | getTermCriteria () const =0 |
Termination criteria of the algorithm. | |
virtual CV_WRAP void | setTermCriteria (TermCriteria val)=0 |
Termination criteria of the algorithm. | |
virtual CV_WRAP float | predict (InputArray samples, OutputArray results=noArray(), int flags=0) const =0 |
Predicts responses for input samples and returns a float type. | |
virtual CV_WRAP Mat | get_learnt_thetas () const =0 |
This function returns the trained paramters arranged across rows. | |
virtual CV_WRAP int | getVarCount () const =0 |
Returns the number of variables in training samples. | |
virtual CV_WRAP bool | empty () const |
Returns true if the Algorithm is empty (e.g. | |
virtual CV_WRAP bool | isTrained () const =0 |
Returns true if the model is trained. | |
virtual CV_WRAP bool | isClassifier () const =0 |
Returns true if the model is classifier. | |
virtual CV_WRAP bool | train (const Ptr< TrainData > &trainData, int flags=0) |
Trains the statistical model. | |
virtual CV_WRAP bool | train (InputArray samples, int layout, InputArray responses) |
Trains the statistical model. | |
virtual CV_WRAP float | calcError (const Ptr< TrainData > &data, bool test, OutputArray resp) const |
Computes error on the training or test dataset. | |
virtual CV_WRAP void | clear () |
Clears the algorithm state. | |
virtual void | write (FileStorage &fs) const |
Stores algorithm parameters in a file storage. | |
virtual void | read (const FileNode &fn) |
Reads algorithm parameters from a file storage. | |
virtual CV_WRAP void | save (const String &filename) const |
Saves the algorithm to a file. | |
virtual CV_WRAP String | getDefaultName () const |
Returns the algorithm string identifier. | |
Static Public Member Functions | |
static CV_WRAP Ptr < LogisticRegression > | create () |
Creates empty model. | |
template<typename _Tp > | |
static Ptr< _Tp > | train (const Ptr< TrainData > &data, int flags=0) |
Create and train model with default parameters. | |
template<typename _Tp > | |
static Ptr< _Tp > | read (const FileNode &fn) |
Reads algorithm from the file node. | |
template<typename _Tp > | |
static Ptr< _Tp > | load (const String &filename, const String &objname=String()) |
Loads algorithm from the file. | |
template<typename _Tp > | |
static Ptr< _Tp > | loadFromString (const String &strModel, const String &objname=String()) |
Loads algorithm from a String. |
Detailed Description
Implements Logistic Regression classifier.
- See also:
- ml_intro_lr
Definition at line 1402 of file ml.hpp.
Member Enumeration Documentation
enum Flags [inherited] |
enum Methods |
enum RegKinds |
Member Function Documentation
virtual CV_WRAP float calcError | ( | const Ptr< TrainData > & | data, |
bool | test, | ||
OutputArray | resp | ||
) | const [virtual, inherited] |
Computes error on the training or test dataset.
- Parameters:
-
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%).
virtual CV_WRAP void clear | ( | ) | [virtual, inherited] |
Clears the algorithm state.
Reimplemented in DescriptorMatcher, and FlannBasedMatcher.
static CV_WRAP Ptr<LogisticRegression> create | ( | ) | [static] |
Creates empty model.
Creates Logistic Regression model with parameters given.
virtual CV_WRAP bool empty | ( | ) | const [virtual, inherited] |
virtual CV_WRAP Mat get_learnt_thetas | ( | ) | const [pure virtual] |
This function returns the trained paramters arranged across rows.
For a two class classifcation problem, it returns a row matrix. It returns learnt paramters of the Logistic Regression as a matrix of type CV_32F.
virtual CV_WRAP String getDefaultName | ( | ) | const [virtual, inherited] |
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.
virtual CV_WRAP int getIterations | ( | ) | const [pure virtual] |
Number of iterations.
- See also:
- setIterations
virtual CV_WRAP double getLearningRate | ( | ) | const [pure virtual] |
Learning rate.
- See also:
- setLearningRate
virtual CV_WRAP int getMiniBatchSize | ( | ) | const [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.
- See also:
- setMiniBatchSize
virtual CV_WRAP int getRegularization | ( | ) | const [pure virtual] |
virtual CV_WRAP TermCriteria getTermCriteria | ( | ) | const [pure virtual] |
Termination criteria of the algorithm.
- See also:
- setTermCriteria
virtual CV_WRAP int getTrainMethod | ( | ) | const [pure virtual] |
virtual CV_WRAP int getVarCount | ( | ) | const [pure virtual, inherited] |
Returns the number of variables in training samples.
virtual CV_WRAP bool isClassifier | ( | ) | const [pure virtual, inherited] |
Returns true if the model is classifier.
virtual CV_WRAP bool isTrained | ( | ) | const [pure virtual, inherited] |
Returns true if the model is trained.
static Ptr<_Tp> load | ( | const String & | filename, |
const String & | objname = String() |
||
) | [static, inherited] |
Loads algorithm from the file.
- Parameters:
-
filename Name of the file to read. 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):
Ptr<SVM> svm = Algorithm::load<SVM>("my_svm_model.xml");
In order to make this method work, the derived class must overwrite Algorithm::read(const FileNode& fn).
static Ptr<_Tp> loadFromString | ( | const String & | strModel, |
const String & | objname = String() |
||
) | [static, inherited] |
Loads algorithm from a String.
- Parameters:
-
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):
Ptr<SVM> svm = Algorithm::loadFromString<SVM>(myStringModel);
virtual CV_WRAP float predict | ( | InputArray | samples, |
OutputArray | results = noArray() , |
||
int | flags = 0 |
||
) | const [pure virtual] |
Predicts responses for input samples and returns a float type.
- Parameters:
-
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 StatModel.
virtual void read | ( | const FileNode & | fn ) | [virtual, inherited] |
Reads algorithm parameters from a file storage.
Reimplemented in DescriptorMatcher, and FlannBasedMatcher.
Reads algorithm from the file node.
This is static template method of Algorithm. It's usage is following (in the case of SVM):
Ptr<SVM> svm = Algorithm::read<SVM>(fn);
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)
Reimplemented in DescriptorMatcher, and FlannBasedMatcher.
virtual CV_WRAP void save | ( | const String & | filename ) | const [virtual, inherited] |
Saves the algorithm to a file.
In order to make this method work, the derived class must implement Algorithm::write(FileStorage& fs).
virtual CV_WRAP void setIterations | ( | int | val ) | [pure virtual] |
Number of iterations.
- See also:
- getIterations
virtual CV_WRAP void setLearningRate | ( | double | val ) | [pure virtual] |
Learning rate.
- See also:
- getLearningRate
virtual CV_WRAP void setMiniBatchSize | ( | int | val ) | [pure virtual] |
Specifies the number of training samples taken in each step of Mini-Batch Gradient Descent.
- See also:
- getMiniBatchSize
virtual CV_WRAP void setRegularization | ( | int | val ) | [pure virtual] |
Kind of regularization to be applied.
- See also:
- getRegularization
virtual CV_WRAP void setTermCriteria | ( | TermCriteria | val ) | [pure virtual] |
Termination criteria of the algorithm.
- See also:
- getTermCriteria
virtual CV_WRAP void setTrainMethod | ( | int | val ) | [pure virtual] |
Kind of training method used.
- See also:
- getTrainMethod
virtual CV_WRAP bool train | ( | InputArray | samples, |
int | layout, | ||
InputArray | responses | ||
) | [virtual, inherited] |
Trains the statistical model.
- Parameters:
-
samples training samples layout See ml::SampleTypes. responses vector of responses associated with the training samples.
virtual CV_WRAP bool train | ( | const Ptr< TrainData > & | trainData, |
int | flags = 0 |
||
) | [virtual, inherited] |
Trains the statistical model.
- Parameters:
-
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).
virtual void write | ( | FileStorage & | fs ) | const [virtual, inherited] |
Stores algorithm parameters in a file storage.
Reimplemented in DescriptorMatcher, and FlannBasedMatcher.
Generated on Tue Jul 12 2022 16:42:45 by
![doxygen](doxygen.png)