Class cv::ml::LogisticRegression#

Implements Logistic Regression classifier. View details

#include <opencv2/ml.hpp>

Collaboration diagram for cv::ml::LogisticRegression:

Public Types#

Training methods.

enum Methods {
    BATCH = 0,
    MINI_BATCH = 1
}

Regularization kinds.

enum RegKinds {
    REG_DISABLE = -1,
    REG_L1 = 0,
    REG_L2 = 1
}
Public Types inherited from cv::ml::StatModel

Return

Name

Description

Flags

Public Member Functions#

Public Member Functions inherited from cv::ml::StatModel

Return

Name

Description

float

calcError(
    const Ptr< TrainData > & data,
    bool test,
    OutputArray resp )

Computes error on the training or test dataset.

bool

empty()

Returns true if the Algorithm is empty (e.g. in the very beginning or after unsuccessful read.

int

getVarCount()

Returns the number of variables in training samples.

bool

isClassifier()

Returns true if the model is classifier.

bool

isTrained()

Returns true if the model is trained.

float

predict(
    InputArray samples,
    OutputArray results = noArray(),
    int flags = 0 )

Predicts response(s) for the provided sample(s)

bool

train(
    const Ptr< TrainData > & trainData,
    int flags = 0 )

Trains the statistical model.

bool

train(
    InputArray samples,
    int layout,
    InputArray responses )

Trains the statistical model.

Public Member Functions inherited from cv::Algorithm

Return

Name

Description

Algorithm()

~Algorithm()

void

clear()

Clears the algorithm state.

bool

empty()

Returns true if the Algorithm is empty (e.g. in the very beginning or after unsuccessful read.

String

getDefaultName()

void

read(const FileNode & fn)

Reads algorithm parameters from a file storage.

void

save(const String & filename)

void

write(
    const Ptr< FileStorage > & fs,
    const String & name = String() )

void

write(FileStorage & fs)

Stores algorithm parameters in a file storage.

void

write(
    FileStorage & fs,
    const String & name )

Static Public Member Functions#

Static Public Member Functions inherited from cv::ml::StatModel

Return

Name

Description

static Ptr< _Tp >

train(
    const Ptr< TrainData > & data,
    int flags = 0 )

Create and train model with default parameters.

Static Public Member Functions inherited from cv::Algorithm

Return

Name

Description

static Ptr< _Tp >

load(
    const String & filename,
    const String & objname = String() )

Loads algorithm from the file.

static Ptr< _Tp >

loadFromString(
    const String & strModel,
    const String & objname = String() )

Loads algorithm from a String.

static Ptr< _Tp >

read(const FileNode & fn)

Reads algorithm from the file node.

Additional Inherited Members#

Protected Member Functions inherited from cv::Algorithm

Return

Name

Description

void

writeFormat(FileStorage & fs)

Detailed Description#

Implements Logistic Regression classifier.

See also

ml_intro_lr

Member Enumeration Documentation#

enum Methods

Training methods.

BATCH
Python: cv.ml.LogisticRegression_BATCH

MINI_BATCH
Python: cv.ml.LogisticRegression_MINI_BATCH

Set MiniBatchSize to a positive integer when using this method.

enum RegKinds

Regularization kinds.

REG_DISABLE
Python: cv.ml.LogisticRegression_REG_DISABLE

Regularization disabled.

REG_L1
Python: cv.ml.LogisticRegression_REG_L1

L1 norm

REG_L2
Python: cv.ml.LogisticRegression_REG_L2

L2 norm

Member Function Documentation#

get_learnt_thetas()#

Mat cv::ml::LogisticRegression::get_learnt_thetas()

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()#

int cv::ml::LogisticRegression::getIterations()

Python:

cv.ml.LogisticRegression.getIterations() -> retval

Number of iterations.

See also

setIterations

getLearningRate()#

double cv::ml::LogisticRegression::getLearningRate()

Python:

cv.ml.LogisticRegression.getLearningRate() -> retval

Learning rate.

See also

setLearningRate

getMiniBatchSize()#

int cv::ml::LogisticRegression::getMiniBatchSize()

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()#

int cv::ml::LogisticRegression::getRegularization()

Python:

cv.ml.LogisticRegression.getRegularization() -> retval

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

getTermCriteria()#

TermCriteria cv::ml::LogisticRegression::getTermCriteria()

Python:

cv.ml.LogisticRegression.getTermCriteria() -> retval

Termination criteria of the algorithm.

See also

setTermCriteria

getTrainMethod()#

int cv::ml::LogisticRegression::getTrainMethod()

Python:

cv.ml.LogisticRegression.getTrainMethod() -> retval

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

See also

setTrainMethod

predict()#

float cv::ml::LogisticRegression::predict(
InputArray samples,
OutputArray results = noArray(),
int flags = 0 )

Python:

cv.ml.LogisticRegression.predict(samples[, results[, flags]]) -> retval, results

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.

Here is the call graph for this function:

cv::ml::LogisticRegression::predict Node1 cv::ml::LogisticRegression ::predict Node2 cv::noArray Node1->Node2

cv::ml::LogisticRegression::predict Node1 cv::ml::LogisticRegression ::predict Node2 cv::noArray Node1->Node2

setIterations()#

void cv::ml::LogisticRegression::setIterations(int val)

Python:

cv.ml.LogisticRegression.setIterations(val)

See also

getIterations

setLearningRate()#

void cv::ml::LogisticRegression::setLearningRate(double val)

Python:

cv.ml.LogisticRegression.setLearningRate(val)

See also

getLearningRate

setMiniBatchSize()#

void cv::ml::LogisticRegression::setMiniBatchSize(int val)

Python:

cv.ml.LogisticRegression.setMiniBatchSize(val)

See also

getMiniBatchSize

setRegularization()#

void cv::ml::LogisticRegression::setRegularization(int val)

Python:

cv.ml.LogisticRegression.setRegularization(val)

setTermCriteria()#

void cv::ml::LogisticRegression::setTermCriteria(TermCriteria val)

Python:

cv.ml.LogisticRegression.setTermCriteria(val)

See also

getTermCriteria

setTrainMethod()#

void cv::ml::LogisticRegression::setTrainMethod(int val)

Python:

cv.ml.LogisticRegression.setTrainMethod(val)

See also

getTrainMethod

create()#

static Ptr< LogisticRegression > cv::ml::LogisticRegression::create()

Python:

cv.ml.LogisticRegression.create() -> retval
cv.ml.LogisticRegression_create() -> retval

Creates empty model.

Creates Logistic Regression model with parameters given.

load()#

static Ptr< LogisticRegression > cv::ml::LogisticRegression::load(
const String & filepath,
const String & nodeName = String() )

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

  • filepath — path to serialized LogisticRegression

  • nodeName — name of node containing the classifier

Source file#

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