LogisticRegression
public class LogisticRegression
A Logistic regression classifier.
In the multiclass classification, the training algorithm uses the one-vs-rest (OvR) scheme.
-
The linear rate for gradient descent.
Declaration
Swift
var learningRate: Float -
The number of iterations for gradient descent.
Declaration
Swift
var iterationCount: Int -
Whether to calculate the intercept for this model.
Declaration
Swift
var fitIntercept: Bool -
The tensor of unique classes.
Declaration
Swift
var classes: Tensor<Int32> -
The tensor contains the index to unique classes.
Declaration
Swift
var indices: Tensor<Int32> -
The weights array for the model contains weights of each class agains the rest.
Declaration
Swift
public var weights: <<error type>> -
Creates a logistic regression model.
Declaration
Swift
public init( iterationCount: Int = 1000, learningRate: Float = 0.1, fitIntercept: Bool = true )Parameters
iterationCountThe number of iterations for gradient descent, default to
1000.learningRateThe learning rate for gardient descent, default to
0.1fitInterceptWhether to calculate the intercept for this model. If set to
false, no intercept will be used in calculations, default set totrue. -
Fit a logistic regression model.
Declaration
Swift
public func fit(data: Tensor<Float>, labels: Tensor<Int32>)Parameters
dataTraining data with shape
[sample count, feature count].labelsTarget value with shape
[sample count, 1]. -
Returns the prediction for a single sample.
Declaration
Swift
public func predictSingleSample(_ data: Tensor<Float>) -> Tensor<Int32>Parameters
dataSingle sample data with shape
[1, feature count].Return Value
Predicted class label.
-
Returns prediction using logistic regression classifier.
Declaration
Swift
public func prediction(for data: Tensor<Float>) -> Tensor<Int32>Parameters
dataSmaple data with shape
[sample count, feature count].Return Value
Predicted class label of target values.
-
Returns mean accuracy on the given test data and labels.
Declaration
Swift
public func score(data: Tensor<Float>, labels: Tensor<Int32>) -> FloatParameters
dataSample data with shape `[sample count, feature count].
labelsTarget label with shape
[sample count, 1].Return Value
Returns the mean accuracy on the given test data and labels.
LogisticRegression Class Reference