... | ... | @@ -25,14 +25,13 @@ hoeffding_tree_classify(TestData, 3, PredicList, ProbsList). |
|
|
|
|
|
[links/resources](/PrologMethods/Classification/linear_svm#connected-linksresources)
|
|
|
|
|
|
## **_initModelWithTrain/10_**
|
|
|
## **_linear_SVM_initModelWithTrain/8_**
|
|
|
|
|
|
Initializes the linear_svm model with the given data and trains it.
|
|
|
|
|
|
```prolog
|
|
|
%% predicate definition
|
|
|
linear_SVM_initModelWithTrain(
|
|
|
DataList, DataRows, LabelsList, NumClasses, Lambda, Delta, FitIntercept, Optimizer) :-
|
|
|
linear_SVM_initModelWithTrain(DataList, DataRows, LabelsList, NumClasses, Lambda, Delta, FitIntercept, Optimizer) :-
|
|
|
NumClasses >= 0,
|
|
|
Lambda >= 0.0,
|
|
|
Delta >= 0.0,
|
... | ... | @@ -61,14 +60,21 @@ foreign(initModelWithTrain, c, initModelWithTrainI( +pointer(float_array), +inte |
|
|
|
|
|
---
|
|
|
|
|
|
## **_initModelNoTrain/4_**
|
|
|
## **_linear_SVM_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).
|
|
|
%% predicate definition
|
|
|
inear_SVM_initModelNoTrain(NumClasses, Lambda, Delta, FitIntercept) :-
|
|
|
NumClasses >= 0,
|
|
|
Lambda >= 0.0,
|
|
|
Delta >= 0.0,
|
|
|
initModelNoTrainI(NumClasses, Lambda, Delta, FitIntercept).
|
|
|
|
|
|
%% foreign c++ predicate definition
|
|
|
foreign(initModelNoTrain, c, initModelNoTrainI( +integer, +float32, +float32,
|
|
|
+integer)).
|
|
|
```
|
|
|
|
|
|
### Parameters
|
... | ... | @@ -81,15 +87,22 @@ initModelNoTrain( +integer, +float32, +float32, |
|
|
|
|
|
---
|
|
|
|
|
|
## **_classify/8_**
|
|
|
## **_linear_SVM_classify/5_**
|
|
|
|
|
|
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,
|
|
|
%% predicate definition
|
|
|
linear_SVM_classify(DataList, DataRows, LabelsList, ScoresList, ZCols) :-
|
|
|
convert_list_to_float_array(DataList, DataRows, array(Xsize, Xrows, X)),
|
|
|
classifyI(X, Xsize, Xrows, Y, Ysize, Z, ZCols, ZRows),
|
|
|
convert_float_array_to_list(Y, Ysize, LabelsList),
|
|
|
convert_float_array_to_2d_list(Z, ZCols, ZRows, ScoresList).
|
|
|
|
|
|
%% foreign c++ predicate definition
|
|
|
foreign(classify, c, classifyI( +pointer(float_array), +integer, +integer,
|
|
|
-pointer(float_array), -integer,
|
|
|
-pointer(float_array), -integer, -integer).
|
|
|
-pointer(float_array), -integer, -integer)).
|
|
|
```
|
|
|
|
|
|
### Parameters
|
... | ... | @@ -101,14 +114,19 @@ classify( +pointer(float_array), +integer, +integer, |
|
|
|
|
|
---
|
|
|
|
|
|
## **_classifyPoint/3_**
|
|
|
## **_linear_SVM_classifyPoint/2_**
|
|
|
|
|
|
Classify the given point.
|
|
|
|
|
|
```prolog
|
|
|
%% part of the predicate definition
|
|
|
classifyPoint( +pointer(float_array), +integer,
|
|
|
[-integer]).
|
|
|
%% predicate definition
|
|
|
linear_SVM_classifyPoint(DataList, Prediction) :-
|
|
|
convert_list_to_float_array(DataList, array(Xsize, X)),
|
|
|
classifyPointI(X, Xsize, Prediction).
|
|
|
|
|
|
%% foreign c++ predicate definition
|
|
|
foreign(classifyPoint, c, classifyPointI( +pointer(float_array), +integer,
|
|
|
[-integer])).
|
|
|
```
|
|
|
|
|
|
### Parameters
|
... | ... | @@ -119,17 +137,23 @@ classifyPoint( +pointer(float_array), +integer, |
|
|
|
|
|
---
|
|
|
|
|
|
## **_computeAccuracy/6_**
|
|
|
## **_linear_SVM_computeAccuracy/4_**
|
|
|
|
|
|
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,
|
|
|
%% predicate definition
|
|
|
linear_SVM_computeAccuracy(DataList, DataRows, LabelsList, Accuracy) :-
|
|
|
convert_list_to_float_array(DataList, DataRows, array(Xsize, Xrownum, X)),
|
|
|
convert_list_to_float_array(LabelsList, array(Ysize, Y)),
|
|
|
computeAccuracyI(X, Xsize, Xrownum, Y, Ysize, Accuracy).
|
|
|
|
|
|
%% foreign c++ predicate definition
|
|
|
foreign(computeAccuracy, c, computeAccuracyI( +pointer(float_array), +integer, +integer,
|
|
|
+pointer(float_array), +integer,
|
|
|
[-float32]).
|
|
|
[-float32])).
|
|
|
```
|
|
|
|
|
|
### Parameters
|
... | ... | @@ -141,17 +165,24 @@ computeAccuracy( +pointer(float_array), +integer, +integer, |
|
|
|
|
|
---
|
|
|
|
|
|
## **_train/8_**
|
|
|
## **_linear_SVM_train/6_**
|
|
|
|
|
|
Train the Linear_svm model with the given training data.
|
|
|
|
|
|
```prolog
|
|
|
%% part of the predicate definition
|
|
|
train( +pointer(float_array), +integer, +integer,
|
|
|
%% predicate definition
|
|
|
linear_SVM_train(DataList, DataRows, LabelsList, NumClasses, Optimizer, ObjValue) :-
|
|
|
NumClasses >= 0,
|
|
|
convert_list_to_float_array(DataList, DataRows, array(Xsize, Xrownum, X)),
|
|
|
convert_list_to_float_array(LabelsList, array(Ysize, Y)),
|
|
|
trainI(X, Xsize, Xrownum, Y, Ysize, NumClasses, Optimizer, ObjValue).
|
|
|
|
|
|
%% foreign c++ predicate definition
|
|
|
foreign(train, c, trainI( +pointer(float_array), +integer, +integer,
|
|
|
+pointer(float_array), +integer,
|
|
|
+integer,
|
|
|
+string,
|
|
|
[-float32]).
|
|
|
[-float32])).
|
|
|
```
|
|
|
|
|
|
### Parameters
|
... | ... | @@ -169,8 +200,8 @@ train( +pointer(float_array), +integer, +integer, |
|
|
|
|
|
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**](https://www.mlpack.org/doc/stable/doxygen/classmlpack_1_1svm_1_1LinearSVM.html)
|
|
|
* [**MLpack::linear_svm_Python_documentation**](https://www.mlpack.org/doc/stable/python_documentation.html#linear_svm)
|
|
|
* [**MLpack::linear_svm_C++\_documentation**](https://www.mlpack.org/doc/mlpack-3.4.2/doxygen/classmlpack_1_1svm_1_1LinearSVM.html)
|
|
|
* [**MLpack::linear_svm_Python_documentation**](https://www.mlpack.org/doc/mlpack-3.4.2/python_documentation.html#linear_svm)
|
|
|
|
|
|
added some of the links from the python documentation
|
|
|
|
... | ... | |