class cv::ml::LogisticRegression

Overview

Implements Logistic Regression classifier. Moreā€¦

#include <ml.hpp>

class LogisticRegression: public cv::ml::StatModel
{
public:
    // enums

    enum Methods;
    enum RegKinds;

    // methods

    virtual
    Mat
    get_learnt_thetas() const = 0;

    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 = 0;

    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;

    static
    Ptr<LogisticRegression>
    create();

    static
    Ptr<LogisticRegression>
    load(
        const String& filepath,
        const String& nodeName = String()
        );
};

Inherited Members

public:
    // enums

    enum Flags;

    // methods

    virtual
    void
    clear();

    virtual
    bool
    empty() const;

    virtual
    String
    getDefaultName() const;

    virtual
    void
    read(const FileNode& fn);

    virtual
    void
    save(const String& filename) const;

    virtual
    void
    write(FileStorage& fs) const;

    template <typename _Tp>
    static
    Ptr<_Tp>
    load(
        const String& filename,
        const String& objname = String()
        );

    template <typename _Tp>
    static
    Ptr<_Tp>
    loadFromString(
        const String& strModel,
        const String& objname = String()
        );

    template <typename _Tp>
    static
    Ptr<_Tp>
    read(const FileNode& fn);

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

    virtual
    bool
    empty() const;

    virtual
    int
    getVarCount() const = 0;

    virtual
    bool
    isClassifier() const = 0;

    virtual
    bool
    isTrained() const = 0;

    virtual
    float
    predict(
        InputArray samples,
        OutputArray results = noArray(),
        int flags = 0
        ) const = 0;

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

    virtual
    bool
    train(
        InputArray samples,
        int layout,
        InputArray responses
        );

    template <typename _Tp>
    static
    Ptr<_Tp>
    train(
        const Ptr<TrainData>& data,
        int flags = 0
        );

protected:
    // methods

    void
    writeFormat(FileStorage& fs) const;

Detailed Documentation

Implements Logistic Regression classifier.

See also:

Logistic Regression

Methods

virtual
Mat
get_learnt_thetas() const = 0

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
int
getIterations() const = 0

Number of iterations.

See also:

setIterations

virtual
double
getLearningRate() const = 0

Learning rate.

See also:

setLearningRate

virtual
int
getMiniBatchSize() const = 0

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
int
getRegularization() const = 0

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

See also:

setRegularization

virtual
TermCriteria
getTermCriteria() const = 0

Termination criteria of the algorithm.

See also:

setTermCriteria

virtual
int
getTrainMethod() const = 0

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

See also:

setTrainMethod

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

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.
virtual
void
setIterations(int val) = 0

See also:

getIterations

virtual
void
setLearningRate(double val) = 0

See also:

getLearningRate

virtual
void
setMiniBatchSize(int val) = 0

See also:

getMiniBatchSize

virtual
void
setRegularization(int val) = 0

See also:

getRegularization

virtual
void
setTermCriteria(TermCriteria val) = 0

See also:

getTermCriteria

virtual
void
setTrainMethod(int val) = 0

See also:

getTrainMethod

static
Ptr<LogisticRegression>
create()

Creates empty model.

Creates Logistic Regression model with parameters given.

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

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