|
|
# Linear SVM a L2-regularized support vector machine.
|
|
|
|
|
|
An implementation of linear SVM for multiclass classification.
|
|
|
|
|
|
# Available Predicates
|
|
|
|
|
|
* [initModelWithTrain/10](/PrologMethods/Classification/linear_svm#initmodelwithtrain10)
|
|
|
* [initModelNoTrain/4](/PrologMethods/Classification/linear_svm#initmodelnotrain4)
|
|
|
* [classify/8](/PrologMethods/Classification/linear_svm#classify8)
|
|
|
* [classifyPoint/3](/PrologMethods/Classification/linear_svm#classifypoint3)
|
|
|
* [computeAccuracy/6](/PrologMethods/Classification/linear_svm#computeaccuracy6)
|
|
|
* [train/8](/PrologMethods/Classification/linear_svm#train8)
|
|
|
|
|
|
---
|
|
|
|
|
|
[links/resources](/PrologMethods/Classification/linear_svm#connected-linksresources)
|
|
|
|
|
|
## **_initModelWithTrain/10_**
|
|
|
|
|
|
Initializes the linear_svm model with the given data and trains it.
|
|
|
|
|
|
```prolog
|
|
|
%% part of the predicate definition
|
|
|
initModelWithTrain( +pointer(float_array), +integer, +integer,
|
|
|
+pointer(float_array), +integer,
|
|
|
+integer, +float32, +float32,
|
|
|
+integer,
|
|
|
+string).
|
|
|
```
|
|
|
|
|
|
### Parameters
|
|
|
| Name | Type | Description | Default |
|
|
|
|------|------|-------------|---------|
|
|
|
| data | +matrix | Input training features. Each column associate with one sample | - |
|
|
|
| labels | +vector | Labels associated with the feature data. | - |
|
|
|
| numClasses | +integer | Number of classes for classification. | 2 |
|
|
|
| lambda | +float | L2-regularization constant. | 0.0001 |
|
|
|
| delta | +float | Margin of difference between correct class and other classes. | 1.0 |
|
|
|
| fitIntercept | +integer(bool) | add intercept term or not. | (0)false |
|
|
|
| optimizer | +string | Desired optimizer: "lbfgs", "psgd" | lbfgs |
|
|
|
|
|
|
---
|
|
|
|
|
|
## **_initModelNoTrain/4_**
|
|
|
|
|
|
Initializes the linear_svm model with the given data but doesnt train it.
|
|
|
|
|
|
```prolog
|
|
|
%% part of the predicate definition
|
|
|
initModelNoTrain( +integer, +float32, +float32,
|
|
|
+integer).
|
|
|
```
|
|
|
|
|
|
### Parameters
|
|
|
| Name | Type | Description | Default |
|
|
|
|------|------|-------------|---------|
|
|
|
| numClasses | +integer | Number of classes for classification. | 2 |
|
|
|
| lambda | +float | L2-regularization constant. | 0.0001 |
|
|
|
| delta | +float | Margin of difference between correct class and other classes. | 1.0 |
|
|
|
| fitIntercept | +integer(bool) | add intercept term or not. | (0)false |
|
|
|
|
|
|
---
|
|
|
|
|
|
## **_classify/8_**
|
|
|
|
|
|
Classify the given points, returning class scores and predicted class label for each point.
|
|
|
|
|
|
```prolog
|
|
|
%% part of the predicate definition
|
|
|
classify( +pointer(float_array), +integer, +integer,
|
|
|
-pointer(float_array), -integer,
|
|
|
-pointer(float_array), -integer, -integer).
|
|
|
```
|
|
|
|
|
|
### Parameters
|
|
|
| Name | Type | Description | Default |
|
|
|
|------|------|-------------|---------|
|
|
|
| data | +matrix | Matrix of data points to be classified. | - |
|
|
|
| labels | -vector | Predicted labels for each point. | - |
|
|
|
| scores | -matrix | Class probabilities for each point. | - |
|
|
|
|
|
|
---
|
|
|
|
|
|
## **_classifyPoint/3_**
|
|
|
|
|
|
Classify the given point.
|
|
|
|
|
|
```prolog
|
|
|
%% part of the predicate definition
|
|
|
classifyPoint( +pointer(float_array), +integer,
|
|
|
[-integer]).
|
|
|
```
|
|
|
|
|
|
### Parameters
|
|
|
| Name | Type | Description | Default |
|
|
|
|------|------|-------------|---------|
|
|
|
| point | +vector | Point to be classified. | |
|
|
|
| - | | | |
|
|
|
| predictedLabel | -integer | Predicted class label of the point. | - |
|
|
|
|
|
|
---
|
|
|
|
|
|
## **_computeAccuracy/6_**
|
|
|
|
|
|
Computes accuracy of the learned model given the feature data and the labels associated with each data point.
|
|
|
|
|
|
Predictions are made using the provided data and are compared with the actual labels.
|
|
|
|
|
|
```prolog
|
|
|
%% part of the predicate definition
|
|
|
computeAccuracy( +pointer(float_array), +integer, +integer,
|
|
|
+pointer(float_array), +integer,
|
|
|
[-float32]).
|
|
|
```
|
|
|
|
|
|
### Parameters
|
|
|
| Name | Type | Description | Default |
|
|
|
|------|------|-------------|---------|
|
|
|
| testData | +matrix | Matrix of data points using which predictions are made. | - |
|
|
|
| testLabels | +vector | Vector of labels associated with the data. | - |
|
|
|
| accuracy | -float | Accuracy of the model. | - |
|
|
|
|
|
|
---
|
|
|
|
|
|
## **_train/8_**
|
|
|
|
|
|
Train the Linear_svm model with the given training data.
|
|
|
|
|
|
```prolog
|
|
|
%% part of the predicate definition
|
|
|
train( +pointer(float_array), +integer, +integer,
|
|
|
+pointer(float_array), +integer,
|
|
|
+integer,
|
|
|
+string,
|
|
|
[-float32]).
|
|
|
```
|
|
|
|
|
|
### Parameters
|
|
|
| Name | Type | Description | Default |
|
|
|
|------|------|-------------|---------|
|
|
|
| data | +matrix | Input training features. Each column associate with one sample | - |
|
|
|
| labels | +vector | Labels associated with the feature data. | - |
|
|
|
| numClasses | +integer | Number of classes for classification. | 2 |
|
|
|
| optimizer | +string | Desired optimizer: "lbfgs", "psgd" | lbfgs |
|
|
|
| finalPointValue | -float | Objective value of the final point | - |
|
|
|
|
|
|
---
|
|
|
|
|
|
# Connected Links/Resources
|
|
|
|
|
|
If you want a more detailed explanation, then go to the python documentation. There is most of the time a good explanation on how the methods work and what the parameters do.
|
|
|
|
|
|
* MLpack::linear_svm_C++\_documentation
|
|
|
* [MLpack::linear_svm_Python_documentation](https://www.mlpack.org/doc/stable/python_documentation.html#linear_svm)
|
|
|
|
|
|
added some of the links from the python documentation
|
|
|
|
|
|
* [random_forest](https://gitlab.cs.uni-duesseldorf.de/stups/abschlussarbeiten/prolog-mlpack-libary/-/wikis/PrologMethods/Classification/random_forest)
|
|
|
* logistic_regression
|
|
|
* [LinearSVM on Wikipedia](https://en.wikipedia.org/wiki/Support-vector_machine) |
|
|
\ No newline at end of file |