OpenCV 5.0.0-pre
Open Source Computer Vision
Loading...
Searching...
No Matches
cv::ml::LogisticRegression Class Referenceabstract

Implements Logistic Regression classifier. More...

#include <opencv2/ml.hpp>

Collaboration diagram for cv::ml::LogisticRegression:

Public Types

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 Types inherited from cv::ml::StatModel
enum  Flags {
  UPDATE_MODEL = 1 ,
  RAW_OUTPUT =1 ,
  COMPRESSED_INPUT =2 ,
  PREPROCESSED_INPUT =4
}
 

Public Member Functions

virtual Mat get_learnt_thetas () const =0
 This function returns the trained parameters arranged across rows.
 
virtual int getIterations () const =0
 
virtual double getLearningRate () const =0
 
virtual int getMiniBatchSize () const =0
 
virtual int getRegularization () const =0
 
virtual TermCriteria getTermCriteria () const =0
 
virtual int getTrainMethod () const =0
 
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.
 
virtual void setIterations (int val)=0
 
virtual void setLearningRate (double val)=0
 
virtual void setMiniBatchSize (int val)=0
 
virtual void setRegularization (int val)=0
 
virtual void setTermCriteria (TermCriteria val)=0
 
virtual void setTrainMethod (int val)=0
 
- Public Member Functions inherited from cv::ml::StatModel
virtual float calcError (const Ptr< TrainData > &data, bool test, OutputArray resp) const
 Computes error on the training or test dataset.
 
virtual bool empty () const CV_OVERRIDE
 Returns true if the Algorithm is empty (e.g. in the very beginning or after unsuccessful read.
 
virtual int getVarCount () const =0
 Returns the number of variables in training samples.
 
virtual bool isClassifier () const =0
 Returns true if the model is classifier.
 
virtual bool isTrained () const =0
 Returns true if the model is trained.
 
virtual bool train (const Ptr< TrainData > &trainData, int flags=0)
 Trains the statistical model.
 
virtual bool train (InputArray samples, int layout, InputArray responses)
 Trains the statistical model.
 
- Public Member Functions inherited from cv::Algorithm
 Algorithm ()
 
virtual ~Algorithm ()
 
virtual void clear ()
 Clears the algorithm state.
 
virtual String getDefaultName () const
 
virtual void read (const FileNode &fn)
 Reads algorithm parameters from a file storage.
 
virtual void save (const String &filename) const
 
virtual void write (FileStorage &fs) const
 Stores algorithm parameters in a file storage.
 
void write (FileStorage &fs, const String &name) const
 

Static Public Member Functions

static Ptr< LogisticRegressioncreate ()
 Creates empty model.
 
static Ptr< LogisticRegressionload (const String &filepath, const String &nodeName=String())
 Loads and creates a serialized LogisticRegression from a file.
 
- Static Public Member Functions inherited from cv::ml::StatModel
template<typename _Tp >
static Ptr< _Tptrain (const Ptr< TrainData > &data, int flags=0)
 Create and train model with default parameters.
 
- Static Public Member Functions inherited from cv::Algorithm
template<typename _Tp >
static Ptr< _Tpload (const String &filename, const String &objname=String())
 Loads algorithm from the file.
 
template<typename _Tp >
static Ptr< _TploadFromString (const String &strModel, const String &objname=String())
 Loads algorithm from a String.
 
template<typename _Tp >
static Ptr< _Tpread (const FileNode &fn)
 Reads algorithm from the file node.
 

Additional Inherited Members

- Protected Member Functions inherited from cv::Algorithm
void writeFormat (FileStorage &fs) const
 

Detailed Description

Implements Logistic Regression classifier.

See also
Logistic Regression

Member Enumeration Documentation

◆ Methods

Training methods.

Enumerator
BATCH 
MINI_BATCH 

Set MiniBatchSize to a positive integer when using this method.

◆ RegKinds

Regularization kinds.

Enumerator
REG_DISABLE 

Regularization disabled.

REG_L1 

L1 norm

REG_L2 

L2 norm

Member Function Documentation

◆ create()

static Ptr< LogisticRegression > cv::ml::LogisticRegression::create ( )
static
Python:
cv.ml.LogisticRegression.create() -> retval
cv.ml.LogisticRegression_create() -> retval

Creates empty model.

Creates Logistic Regression model with parameters given.

◆ get_learnt_thetas()

virtual Mat cv::ml::LogisticRegression::get_learnt_thetas ( ) const
pure virtual
Python:
cv.ml.LogisticRegression.get_learnt_thetas() -> retval

This function returns the trained parameters arranged across rows.

For a two class classification problem, it returns a row matrix. It returns learnt parameters of the Logistic Regression as a matrix of type CV_32F.

◆ getIterations()

virtual int cv::ml::LogisticRegression::getIterations ( ) const
pure virtual
Python:
cv.ml.LogisticRegression.getIterations() -> retval

Number of iterations.

See also
setIterations

◆ getLearningRate()

virtual double cv::ml::LogisticRegression::getLearningRate ( ) const
pure virtual
Python:
cv.ml.LogisticRegression.getLearningRate() -> retval

Learning rate.

See also
setLearningRate

◆ getMiniBatchSize()

virtual int cv::ml::LogisticRegression::getMiniBatchSize ( ) const
pure virtual
Python:
cv.ml.LogisticRegression.getMiniBatchSize() -> retval

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

◆ getRegularization()

virtual int cv::ml::LogisticRegression::getRegularization ( ) const
pure virtual
Python:
cv.ml.LogisticRegression.getRegularization() -> retval

Kind of regularization to be applied. See LogisticRegression::RegKinds.

See also
setRegularization

◆ getTermCriteria()

virtual TermCriteria cv::ml::LogisticRegression::getTermCriteria ( ) const
pure virtual
Python:
cv.ml.LogisticRegression.getTermCriteria() -> retval

Termination criteria of the algorithm.

See also
setTermCriteria

◆ getTrainMethod()

virtual int cv::ml::LogisticRegression::getTrainMethod ( ) const
pure virtual
Python:
cv.ml.LogisticRegression.getTrainMethod() -> retval

Kind of training method used. See LogisticRegression::Methods.

See also
setTrainMethod

◆ load()

static Ptr< LogisticRegression > cv::ml::LogisticRegression::load ( const String & filepath,
const String & nodeName = String() )
static
Python:
cv.ml.LogisticRegression.load(filepath[, nodeName]) -> retval
cv.ml.LogisticRegression_load(filepath[, nodeName]) -> retval

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

Parameters
filepathpath to serialized LogisticRegression
nodeNamename of node containing the classifier

◆ predict()

virtual float cv::ml::LogisticRegression::predict ( InputArray samples,
OutputArray results = noArray(),
int flags = 0 ) const
pure virtual
Python:
cv.ml.LogisticRegression.predict(samples[, results[, flags]]) -> retval, results

Predicts responses for input samples and returns a float type.

Parameters
samplesThe 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.
resultsPredicted labels as a column matrix of type CV_32S.
flagsNot used.

Implements cv::ml::StatModel.

Here is the call graph for this function:

◆ setIterations()

virtual void cv::ml::LogisticRegression::setIterations ( int val)
pure virtual
Python:
cv.ml.LogisticRegression.setIterations(val) -> None

See also
getIterations

◆ setLearningRate()

virtual void cv::ml::LogisticRegression::setLearningRate ( double val)
pure virtual
Python:
cv.ml.LogisticRegression.setLearningRate(val) -> None

See also
getLearningRate

◆ setMiniBatchSize()

virtual void cv::ml::LogisticRegression::setMiniBatchSize ( int val)
pure virtual
Python:
cv.ml.LogisticRegression.setMiniBatchSize(val) -> None

◆ setRegularization()

virtual void cv::ml::LogisticRegression::setRegularization ( int val)
pure virtual
Python:
cv.ml.LogisticRegression.setRegularization(val) -> None

◆ setTermCriteria()

virtual void cv::ml::LogisticRegression::setTermCriteria ( TermCriteria val)
pure virtual
Python:
cv.ml.LogisticRegression.setTermCriteria(val) -> None

See also
getTermCriteria

◆ setTrainMethod()

virtual void cv::ml::LogisticRegression::setTrainMethod ( int val)
pure virtual
Python:
cv.ml.LogisticRegression.setTrainMethod(val) -> None

See also
getTrainMethod

The documentation for this class was generated from the following file: