SupportVectorMachine is a supervised machine learning model that predicts values of -1 and 1 only. It assumes that the data is linearly seperable.
Code Sample
local featureMatrix = {
{ 0, 0},
{10, 10},
{-3, -3},
{-2, -2},
{ 2, 2},
{ 1, 1},
{-1, -1},
{ 3, 3},
{-8, -8},
}
local labelVectorLogistic = {
{ 1},
{ 1},
{-1},
{-1},
{ 1},
{ 1},
{-1},
{ 1},
{-1}
}
local testFeatureMatrix = {
{-3, -3},
}
local modelParameters, cost = MachineLL.SupportVectorMachine:train(featureMatrix, labelVectorLogistic , nil, nil, nil, nil, 0.1)
local result = MachineLL.SupportVectorMachine:predict(testFeatureMatrix, modelParameters)
Functions
:train()
train(featureMatrix: matrix, labelVector: matrix, maxNumberOfIterations: integer, learningRate: number cValue: number, distanceFunction : 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)cValue
: How large the margin the boundary decision should have. The higher thecValue
, the higher the margindistanceFunction
: The function that the model will use to train.distanceFunction
available are “euclidean” and “manhattan“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 mode