|
|
|
# L2-regularized Logistic Regression and Prediction
|
|
|
|
|
|
|
|
An implementation of L2-regularized logistic regression for two-class classification.
|
|
|
|
|
|
|
|
# Available Predicates
|
|
|
|
|
|
|
|
* [initModelNoOptimizer/6](/PrologMethods/Classification/logistic_regression#initmodelnooptimizer6)
|
|
|
|
* [initModelWithOptimizer/7](/PrologMethods/Classification/logistic_regression#initmodelwithoptimizer7)
|
|
|
|
* [classifyPoint/4](/PrologMethods/Classification/logistic_regression#classifypoint4)
|
|
|
|
* [classifyLabels/6](/PrologMethods/Classification/logistic_regression#classifylabels6)
|
|
|
|
* [classifyProbs/6](/PrologMethods/Classification/logistic_regression#classifyprobs6)
|
|
|
|
* [computeAccuracy/7](/PrologMethods/Classification/logistic_regression#computeaccuracy7)
|
|
|
|
* [computeError/6](/PrologMethods/Classification/logistic_regression#computeerror6)
|
|
|
|
* [train/6](/PrologMethods/Classification/logistic_regression#train6)
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
[links/resources](/PrologMethods/Classification/logistic_regression#connected-linksresources)
|
|
|
|
|
|
|
|
## **_initModelNoOptimizer/6_**
|
|
|
|
|
|
|
|
Initialize the logistic_regression model without specifing a optimizer.
|
|
|
|
|
|
|
|
```prolog
|
|
|
|
%% part of the predicate definition
|
|
|
|
initModelNoOptimizer( +pointer(float_array), +integer, +integer,
|
|
|
|
+pointer(float_array), +integer,
|
|
|
|
+float32).
|
|
|
|
```
|
|
|
|
|
|
|
|
### Parameters
|
|
|
|
| Name | Type | Description | Default |
|
|
|
|
|------|------|-------------|---------|
|
|
|
|
| data | +matrix | Input training variables. | - |
|
|
|
|
| responses | +vector | Outputs results from input training variables. | - |
|
|
|
|
| lambda | +float | L2-regularization parameter. | 0.0 |
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
## **_initModelWithOptimizer/7_**
|
|
|
|
|
|
|
|
Initialize the logistic_regression model and specify the optimizer.
|
|
|
|
|
|
|
|
```prolog
|
|
|
|
%% part of the predicate definition
|
|
|
|
initModelWithOptimizer( +pointer(float_array), +integer, +integer,
|
|
|
|
+pointer(float_array), +integer,
|
|
|
|
+string,
|
|
|
|
+float32).
|
|
|
|
```
|
|
|
|
|
|
|
|
### Parameters
|
|
|
|
| Name | Type | Description | Default |
|
|
|
|
|------|------|-------------|---------|
|
|
|
|
| data | +matrix | Input training variables. | - |
|
|
|
|
| responses | +vector | Outputs results from input training variables. | - |
|
|
|
|
| optimizer | +string | The optimizer to use: "lbfgs", "psgd" | lbfgs |
|
|
|
|
| lambda | +float | L2-regularization parameter. | 0.0 |
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
## **_classifyPoint/4_**
|
|
|
|
|
|
|
|
Classify the given point.
|
|
|
|
|
|
|
|
```prolog
|
|
|
|
%% part of the predicate definition
|
|
|
|
classifyPoint( +pointer(float_array), +integer,
|
|
|
|
+float32,
|
|
|
|
[-integer]).
|
|
|
|
```
|
|
|
|
|
|
|
|
### Parameters
|
|
|
|
| Name | Type | Description | Default |
|
|
|
|
|------|------|-------------|---------|
|
|
|
|
| point | +vector | Point to classify. | - |
|
|
|
|
| decisionBoundary | +float | Decision boundary (default 0.5). | 0.5 |
|
|
|
|
| predicLabel | -integer | Predicted label of point. | - |
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
## **_classifyLabels/6_**
|
|
|
|
|
|
|
|
Classify the given points, returning the predicted labels for each point.
|
|
|
|
|
|
|
|
```prolog
|
|
|
|
%% part of the predicate definition
|
|
|
|
classifyLabels( +pointer(float_array), +integer, +integer,
|
|
|
|
-pointer(float_array), -integer,
|
|
|
|
+float32).
|
|
|
|
```
|
|
|
|
|
|
|
|
### Parameters
|
|
|
|
| Name | Type | Description | Default |
|
|
|
|
|------|------|-------------|---------|
|
|
|
|
| data | +matrix | Set of points to classify. | - |
|
|
|
|
| predicLabels | -vector | Predicted labels for each point. | - |
|
|
|
|
| decisionBoundary | +float | Decision boundary (default 0.5). | 0.5 |
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
## **_classifyProbs/6_**
|
|
|
|
|
|
|
|
Classify the given points, returning class probabilities for each point.
|
|
|
|
|
|
|
|
```prolog
|
|
|
|
%% part of the predicate definition
|
|
|
|
classifyProbs( +pointer(float_array), +integer, +integer,
|
|
|
|
-pointer(float_array), -integer, -integer).
|
|
|
|
```
|
|
|
|
|
|
|
|
### Parameters
|
|
|
|
| Name | Type | Description | Default |
|
|
|
|
|------|------|-------------|---------|
|
|
|
|
| data | +matrix | Set of points to classify. | - |
|
|
|
|
| probabilities | -matrix | Class probabilities for each point (output). | - |
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
## **_computeAccuracy/7_**
|
|
|
|
|
|
|
|
Compute the accuracy of the model on the given predictors and responses, using the given decision boundary.
|
|
|
|
|
|
|
|
```prolog
|
|
|
|
%% part of the predicate definition
|
|
|
|
computeAccuracy( +pointer(float_array), +integer, +integer,
|
|
|
|
+pointer(float_array), +integer,
|
|
|
|
+float32,
|
|
|
|
[-float32]).
|
|
|
|
```
|
|
|
|
|
|
|
|
### Parameters
|
|
|
|
| Name | Type | Description | Default |
|
|
|
|
|------|------|-------------|---------|
|
|
|
|
| data | +matrix | Input predictors. | - |
|
|
|
|
| responses | +vector | Vector of responses. | - |
|
|
|
|
| decisionBoundary | +float | Decision boundary (default 0.5). | 0.5 |
|
|
|
|
| accuracy | -float | Percentage of responses that are predicted correctly. | - |
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
## **_computeError/6_**
|
|
|
|
|
|
|
|
Compute the error of the model.
|
|
|
|
|
|
|
|
```prolog
|
|
|
|
%% part of the predicate definition
|
|
|
|
computeError( +pointer(float_array), +integer, +integer,
|
|
|
|
+pointer(float_array), +integer,
|
|
|
|
[-float32]).
|
|
|
|
```
|
|
|
|
|
|
|
|
### Parameters
|
|
|
|
| Name | Type | Description | Default |
|
|
|
|
|------|------|-------------|---------|
|
|
|
|
| data | +matrix | Input predictors. | - |
|
|
|
|
| responses | +vector | Vector of responses. | - |
|
|
|
|
| error | -float | returns the negative objective function of the logistic regression log-likelihood function. | - |
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
## **_train/6_**
|
|
|
|
|
|
|
|
Train the logistic_regression model on the given input data.
|
|
|
|
|
|
|
|
```prolog
|
|
|
|
%% part of the predicate definition
|
|
|
|
train( +pointer(float_array), +integer, +integer,
|
|
|
|
+pointer(float_array), +integer,
|
|
|
|
+string).
|
|
|
|
```
|
|
|
|
|
|
|
|
### Parameters
|
|
|
|
| Name | Type | Description | Default |
|
|
|
|
|------|------|-------------|---------|
|
|
|
|
| data | +matrix | Input training variables. | - |
|
|
|
|
| responses | +vector | Outputs results from input training variables. | - |
|
|
|
|
| optimizer | +string | The optimizer to use: "lbfgs", "psgd" | lbfgs |
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
# 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::logistic_regression_C++\_documentation](https://www.mlpack.org/doc/stable/doxygen/classmlpack_1_1regression_1_1LogisticRegression.html)
|
|
|
|
* [MLpack::logistic_regression_Python_documentation](https://www.mlpack.org/doc/stable/python_documentation.html#logistic_regression)
|
|
|
|
|
|
|
|
added some of the links from the python documentation
|
|
|
|
|
|
|
|
* [softmax_regression](https://gitlab.cs.uni-duesseldorf.de/stups/abschlussarbeiten/prolog-mlpack-libary/-/wikis/PrologMethods/Classification/softmax_regression)
|
|
|
|
* [random_forest](https://gitlab.cs.uni-duesseldorf.de/stups/abschlussarbeiten/prolog-mlpack-libary/-/wikis/PrologMethods/Classification/random_forest)
|
|
|
|
* [Logistic regression on Wikipedia](https://en.wikipedia.org/wiki/Logistic_regression) |
|
|
|
\ No newline at end of file |