|
|
# Softmax Regression
|
|
|
|
|
|
An implementation of softmax regression for classification, which is a multiclass generalization of logistic regression.
|
|
|
|
|
|
# Available Predicates
|
|
|
|
|
|
* [initModelNoTrain/3](/PrologMethods/Classification/softmax_regression#initmodelnotrain3)
|
|
|
* [initModelWithTrain/8](/PrologMethods/Classification/softmax_regression#initmodelwithtrain8)
|
|
|
* [classifyPoint/3](/PrologMethods/Classification/softmax_regression#classifypoint3)
|
|
|
* [classifyMatrix/8](/PrologMethods/Classification/softmax_regression#classifymatrix8)
|
|
|
* [computeAccuracy/6](/PrologMethods/Classification/softmax_regression#computeaccuracy6)
|
|
|
* [featureSize/1](/PrologMethods/Classification/softmax_regression#featuresize1)
|
|
|
* [parameters/3](/PrologMethods/Classification/softmax_regression#parameters3)
|
|
|
* [train/7](/PrologMethods/Classification/softmax_regression#train7)
|
|
|
|
|
|
---
|
|
|
|
|
|
[links/resources](/PrologMethods/Classification/softmax_regression#connected-linksresources)
|
|
|
|
|
|
## **_initModelNoTrain/3_**
|
|
|
|
|
|
Initializes the softmax_regression model without training.
|
|
|
|
|
|
Be sure to use Train before calling Classif or ComputeAccuracy, otherwise the results may be meaningless.
|
|
|
|
|
|
```prolog
|
|
|
%% part of the predicate definition
|
|
|
initModelNoTrain( +integer, +integer,
|
|
|
+integer).
|
|
|
```
|
|
|
|
|
|
### Parameters
|
|
|
| Name | Type | Description | Default |
|
|
|
|------|------|-------------|---------|
|
|
|
| inputSize | +integer | Size of the input feature vector. | 0 |
|
|
|
| numClasses | +integer | Number of classes for classification. | 0 |
|
|
|
| fitIntercept | +integer(bool) | add intercept term or not. | (0)false |
|
|
|
|
|
|
---
|
|
|
|
|
|
## **_initModelWithTrain/8_**
|
|
|
|
|
|
Initializes the softmax_regression model and trains it.
|
|
|
|
|
|
```prolog
|
|
|
%% part of the predicate definition
|
|
|
initModelWithTrain( +pointer(float_array), +integer, +integer,
|
|
|
+pointer(float_array), +integer,
|
|
|
+integer, +float32,
|
|
|
+integer).
|
|
|
```
|
|
|
|
|
|
### 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. | 0 |
|
|
|
| lambda | +float | L2-regularization constant. | 0.0001 |
|
|
|
| fitIntercept | +integer(bool) | add intercept term or not. | (0)false |
|
|
|
|
|
|
---
|
|
|
|
|
|
## **_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. | - |
|
|
|
|
|
|
---
|
|
|
|
|
|
## **_classifyMatrix/8_**
|
|
|
|
|
|
Classify the given points, returning class probabilities and predicted class label for each point.
|
|
|
|
|
|
```prolog
|
|
|
%% part of the predicate definition
|
|
|
classifyMatrix( +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. | - |
|
|
|
| predictedLabels | -vector | Predicted labels for each point. | - |
|
|
|
| probabilities | -matrix | Class probabilities for each 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 |
|
|
|
|------|------|-------------|---------|
|
|
|
| data | +matrix | Matrix of data points using which predictions are made. | - |
|
|
|
| predictedLabels | -vector | Vector of labels associated with the data. | - |
|
|
|
| accuracy | -float | - | - |
|
|
|
|
|
|
---
|
|
|
|
|
|
## **_featureSize/1_**
|
|
|
|
|
|
Gets the features size of the training data.
|
|
|
|
|
|
```prolog
|
|
|
%% part of the predicate definition
|
|
|
featureSize([-integer]).
|
|
|
```
|
|
|
|
|
|
### Parameters
|
|
|
| Name | Type | Description | Default |
|
|
|
|------|------|-------------|---------|
|
|
|
| featureSize | -integer | Get the features size of the training data. | - |
|
|
|
|
|
|
---
|
|
|
|
|
|
## **_parameters/3_**
|
|
|
|
|
|
Get the model parameters.
|
|
|
|
|
|
```prolog
|
|
|
%% part of the predicate definition
|
|
|
parameters(-pointer(float_array), -integer, -integer).
|
|
|
```
|
|
|
|
|
|
### Parameters
|
|
|
| Name | Type | Description | Default |
|
|
|
|------|------|-------------|---------|
|
|
|
| parameters | -matrix | Get the model parameters. | - |
|
|
|
|
|
|
---
|
|
|
|
|
|
## **_train/7_**
|
|
|
|
|
|
Trains the softmax regression model with the given training data.
|
|
|
|
|
|
```prolog
|
|
|
%% part of the predicate definition
|
|
|
train( +pointer(float_array), +integer, +integer,
|
|
|
+pointer(float_array), +integer,
|
|
|
+integer,
|
|
|
[-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. | 0 |
|
|
|
| finalPointValue | -float | Objective value of 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::softmax_regression_C++\_documentation](https://www.mlpack.org/doc/stable/doxygen/classmlpack_1_1regression_1_1SoftmaxRegression.html)
|
|
|
* [MLpack::softmax_regression_Python_documentation](https://www.mlpack.org/doc/stable/python_documentation.html#softmax_regression)
|
|
|
|
|
|
added some of the links from the python documentation
|
|
|
|
|
|
* logistic_regression
|
|
|
* random_forest
|
|
|
* [Multinomial logistic regression (softmax regression) on Wikipedia](https://en.wikipedia.org/wiki/Multinomial_logistic_regression) |
|
|
\ No newline at end of file |