LinearRegression is a supervised machine learning model that predicts continuous values (e.g. 1.2, -32, 90, -1.2 and etc. ).
Code Sample
local featureMatrix = {
{ 0, 0},
{10, 10},
{-3, -3},
{-2, -2},
{ 2, 2},
{ 1, 1},
{-1, -1},
{ 3, 3},
{-8, -8},
}
local labelVectorRegression = {
{ 0},
{10},
{-3},
{-2},
{ 2},
{ 1},
{-1},
{ 3},
{-8},
}
local testFeatureMatrix = {
{-3, -3},
}
local modelParameters, cost = MachineLL.LinearRegression:train(featureMatrix, labelVectorRegression, nil, nil, nil, 0.1)
local result = MachineLL.LinearRegression:predict(testFeatureMatrix , modelParameters)
Functions
:train()
train(featureMatrix: matrix, labelVector: matrix, maxNumberOfIterations: integer, learningRate: number, lossFunction: string, targetCost: number, suppressOutput: boolean): matrix, number
Arguments:
featureMatrix
: The matrix containing values for the model to train onlabelVector
: The vector containing actual values that are as a result of relationship with featureMatrixmaxNumberOfIterations
: Maximum number of iterationslearningRate
: The learning rate for the model (values between 0 and 1 is recommended)lossFunction
: The function that the model will use to train. lossFunction available are “L1” and “L2”targetCost
: The target cost for the model to stop trainingsuppressOutput
: An option whether or not to display the number of iterations and the cost
:predict()
predict(featureMatrix: matrix, modelParameters: matrix): number
Arguments:
featureMatrix
: The matrix containing values for the model to predict onmodelParameters
: The matrix generated from training the model