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
iterationCount
The number of iterations for gradient descent, default to
1000
.learningRate
The learning rate for gardient descent, default to
0.1
fitIntercept
Whether 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
data
Training data with shape
[sample count, feature count]
.labels
Target value with shape
[sample count, 1]
. -
Returns the prediction for a single sample.
Declaration
Swift
public func predictSingleSample(_ data: Tensor<Float>) -> Tensor<Int32>
Parameters
data
Single 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
data
Smaple 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>) -> Float
Parameters
data
Sample data with shape `[sample count, feature count].
labels
Target label with shape
[sample count, 1]
.Return Value
Returns the mean accuracy on the given test data and labels.