Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ The function accepts the following `options`:

- `hinge`: hinge loss function. Corresponds to a soft-margin linear Support Vector Machine (SVM), which can handle non-linearly separable data.
- `log`: logistic loss function. Corresponds to Logistic Regression.
- `modifiedHuber`: Huber loss function [variant][@zhang:2004a] for classification.
- `modified-huber`: Huber loss function [variant][@zhang:2004a] for classification.
- `perceptron`: hinge loss function without a margin. Corresponds to the original perceptron by Rosenblatt (1957).
- `squaredHinge`: squared hinge loss function SVM (L2-SVM).
- `squared-hinge`: squared hinge loss function SVM (L2-SVM).

Default: `'log'`.

Expand Down Expand Up @@ -140,7 +140,7 @@ var label = acc.predict( array( [ 0.5, 2.0 ] ) );

Provided an [`ndarray`][@stdlib/ndarray/ctor] having shape `(..., N)`, where `N` is the number of features, the returned [`ndarray`][@stdlib/ndarray/ctor] has shape `(...)` (i.e., the number of dimensions is reduced by one) and data type `float64`. For example, if provided a one-dimensional [`ndarray`][@stdlib/ndarray/ctor], the method returns a zero-dimensional [`ndarray`][@stdlib/ndarray/ctor] whose only element is the predicted response value.

By default, the method returns the predict label (`type='label'`). In order to return a prediction probability of a `+1` response value given either the logistic (`log`) or modified Huber (`modifiedHuber`) loss functions, set the second argument to `'probability'`.
By default, the method returns the predict label (`type='label'`). In order to return a prediction probability of a `+1` response value given either the logistic (`log`) or modified Huber (`modified-huber`) loss functions, set the second argument to `'probability'`.

```javascript
var array = require( '@stdlib/ndarray/array' );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@

- log: logistic loss function. Corresponds to Logistic Regression.

- modifiedHuber: Huber loss function variant for classification.
- modified-huber: Huber loss function variant for classification.

- perceptron: hinge loss function without a margin. Corresponds to the
original Perceptron by Rosenblatt.

- squaredHinge: squared hinge loss function SVM (L2-SVM).
- squared-hinge: squared hinge loss function SVM (L2-SVM).

Default: 'log'.

Expand All @@ -88,7 +88,7 @@
following: 'label', 'probability', or 'linear'. Default: 'label'.

Note that the probability prediction type is only compatible with 'log'
and 'modifiedHuber' loss functions.
and 'modified-huber' loss functions.

Examples
--------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ interface Options {
*
* - `hinge`: hinge loss function. Corresponds to a soft-margin linear Support Vector Machine (SVM), which can handle non-linearly separable data.
* - `log`: logistic loss function. Corresponds to Logistic Regression.
* - `modifiedHuber`: Huber loss function variant for classification.
* - `modified-huber`: Huber loss function variant for classification.
* - `perceptron`: hinge loss function without a margin. Corresponds to the original Perceptron by Rosenblatt.
* - `squaredHinge`: squared hinge loss function SVM (L2-SVM).
* - `squared-hinge`: squared hinge loss function SVM (L2-SVM).
*/
loss?: 'hinge' | 'log' | 'modifiedHuber' | 'perceptron' | 'squaredHinge';
loss?: 'hinge' | 'log' | 'modified-huber' | 'perceptron' | 'squared-hinge';

/**
* Boolean indicating whether to include an intercept (default: `true`).
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[
"hinge",
"log",
"modifiedHuber",
"modified-huber",
"perceptron",
"squaredHinge"
]
"squared-hinge"
]
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ var validate = require( './validate.js' );
* @param {Options} [options] - options object
* @param {PositiveNumber} [options.lambda=1.0e-3] - regularization parameter
* @param {ArrayLikeObject} [options.learningRate=['basic']] - learning rate function and associated parameters (one of `basic`, `constant`, or `pegasos`)
* @param {string} [options.loss='log'] - loss function (one of `hinge`, `log`, `modifiedHuber`, `perceptron`, or `squaredHinge`)
* @param {string} [options.loss='log'] - loss function (one of `hinge`, `log`, `modified-huber`, `perceptron`, or `squared-hinge`)
* @param {boolean} [options.intercept=true] - boolean indicating whether to include an intercept
* @throws {TypeError} first argument must be a positive integer
* @throws {TypeError} options argument must be an object
Expand Down Expand Up @@ -190,8 +190,8 @@ function incrBinaryClassification( N, options ) {
t = 'label';
if ( arguments.length > 1 ) {
if ( type === 'probability' ) {
if ( opts.loss !== 'log' && opts.loss !== 'modifiedHuber' ) {
throw new Error( format( 'invalid argument. Second argument is incompatible with model loss function. Probability predictions are only supported when the loss function is one of the following: "%s". Model loss function: `%s`.', [ 'log', 'modifiedHuber' ].join( '", "' ), opts.loss ) );
if ( opts.loss !== 'log' && opts.loss !== 'modified-huber' ) {
throw new Error( format( 'invalid argument. Second argument is incompatible with model loss function. Probability predictions are only supported when the loss function is one of the following: "%s". Model loss function: `%s`.', [ 'log', 'modified-huber' ].join( '", "' ), opts.loss ) );
}
} else if ( type !== 'label' && type !== 'linear' ) {
throw new TypeError( format( 'invalid argument. Second argument must be a string value equal to either "label", "probability", or "linear". Value: `%s`.', type ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ var LEARNING_RATE_METHODS = {
var LOSS_METHODS = {
'hinge': '_hingeLoss',
'log': '_logLoss',
'modifiedHuber': '_modifiedHuberLoss',
'modified-huber': '_modifiedHuberLoss',
'perceptron': '_perceptronLoss',
'squaredHinge': '_squaredHingeLoss'
'squared-hinge': '_squaredHingeLoss'
};


Expand Down
2 changes: 1 addition & 1 deletion lib/node_modules/@stdlib/ml/incr/docs/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ interface Namespace {
* @param options.eta0 - constant learning rate (default: 0.02)
* @param options.lambda - regularization parameter (default: 1e-3)
* @param options.learningRate - string denoting the learning rate to use. Can be `constant`, `pegasos`, or `basic` (default: 'basic')
* @param options.loss - string denoting the loss function to use. Can be `squaredError`, `epsilonInsensitive`, or `huber` (default: 'squaredError')
* @param options.loss - string denoting the loss function to use. Can be `squared-error`, `epsilon-insensitive`, or `huber` (default: 'squared-error')
* @param options.intercept - boolean indicating whether to include an intercept (default: true)
* @throws must provide valid options
* @returns regression model
Expand Down
10 changes: 5 additions & 5 deletions lib/node_modules/@stdlib/ml/incr/sgd-regression/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ for ( i = 0; i < 100000; i++ ) {
The function accepts the following `options`:

- **learningRate**: `string` denoting the learning rate to use. Can be `constant`, `pegasos` or `basic`. Default: `basic`.
- **loss**: `string` denoting the loss function to use. Can be `squaredError`, `epsilonInsensitive` or `huber`. Default: `squaredError`.
- **loss**: `string` denoting the loss function to use. Can be `squared-error`, `epsilon-insensitive` or `huber`. Default: `squared-error`.
- **epsilon**: insensitivity parameter. Default: `0.1`.
- **lambda**: regularization parameter. Default: `1e-3`.
- **eta0**: constant learning rate. Default: `0.02`.
Expand All @@ -66,7 +66,7 @@ The function accepts the following `options`:

```javascript
var accumulator = incrSGDRegression({
'loss': 'squaredError',
'loss': 'squared-error',
'lambda': 1e-4
});
```
Expand All @@ -81,9 +81,9 @@ The `learningRate` decides how fast or slow the weights will be updated towards

The used loss function is specified via the `loss` option. The available options are:

- **epsilonInsensitive**: Penalty is the absolute value of the error whenever the absolute error exceeds epsilon and zero otherwise.
- **epsilon-insensitive**: Penalty is the absolute value of the error whenever the absolute error exceeds epsilon and zero otherwise.
- **huber**: Squared-error loss for observations with error smaller than epsilon in magnitude, linear loss otherwise. Should be used in order to decrease the influence of outliers on the model fit.
- **squaredError**: Squared error loss, i.e. the squared difference of the observed and fitted values.
- **squared-error**: Squared error loss, i.e. the squared difference of the observed and fitted values.

The `lambda` parameter determines the amount of shrinkage inflicted on the model coefficients:

Expand Down Expand Up @@ -232,7 +232,7 @@ rnorm = normal.factory( 0.0, 1.0 );
// Create model:
accumulator = incrSGDRegression({
'lambda': 1e-7,
'loss': 'squaredError',
'loss': 'squared-error',
'intercept': true
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ interface Options {
learningRate?: 'constant' | 'pegasos' | 'basic';

/**
* String denoting the loss function to use. Can be `squaredError`, `epsilonInsensitive`, or `huber` (default: 'squaredError').
* String denoting the loss function to use. Can be `squared-error`, `epsilon-insensitive`, or `huber` (default: 'squared-error').
*/
loss?: 'squaredError' | 'epsilonInsensitive' | 'huber';
loss?: 'squared-error' | 'epsilon-insensitive' | 'huber';

/**
* Boolean indicating whether to include an intercept (default: true).
Expand Down Expand Up @@ -113,7 +113,7 @@ interface Model {
* @param options.eta0 - constant learning rate (default: 0.02)
* @param options.lambda - regularization parameter (default: 1e-3)
* @param options.learningRate - string denoting the learning rate to use. Can be `constant`, `pegasos`, or `basic` (default: 'basic')
* @param options.loss - string denoting the loss function to use. Can be `squaredError`, `epsilonInsensitive`, or `huber` (default: 'squaredError')
* @param options.loss - string denoting the loss function to use. Can be `squared-error`, `epsilon-insensitive`, or `huber` (default: 'squared-error')
* @param options.intercept - boolean indicating whether to include an intercept (default: true)
* @throws must provide valid options
* @returns regression model
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ rnorm = normal.factory( 0.0, 1.0 );
// Create model:
accumulator = incrSGDRegression({
'lambda': 1e-7,
'loss': 'squaredError',
'loss': 'squared-error',
'intercept': true
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
"intercept": true,
"lambda": 1e-3,
"learningRate": "basic",
"loss": "squaredError"
"loss": "squared-error"
}
8 changes: 4 additions & 4 deletions lib/node_modules/@stdlib/ml/incr/sgd-regression/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ var validate = require( './validate.js' );
* @param {PositiveNumber} [options.eta0=0.02] - constant learning rate
* @param {NonNegativeNumber} [options.lambda=1e-3] - regularization parameter
* @param {string} [options.learningRate='basic'] - string denoting the learning rate to use. Can be `constant`, `pegasos`, or `basic`
* @param {string} [options.loss='squaredError'] - string denoting the loss function to use. Can be `squaredError`, `epsilonInsensitive`, or `huber`
* @param {string} [options.loss='squared-error'] - string denoting the loss function to use. Can be `squared-error`, `epsilon-insensitive`, or `huber`
* @param {boolean} [options.intercept=true] - boolean indicating whether to include an intercept
* @throws {TypeError} options argument must be an object
* @throws {TypeError} must provide valid options
Expand Down Expand Up @@ -96,17 +96,17 @@ function incrSGDRegression( options ) {

// Set loss function:
switch ( opts.loss ) {
case 'epsilonInsensitive':
case 'epsilon-insensitive':
_lossfun = epsilonInsensitiveLoss;
break;
case 'huber':
_lossfun = huberLoss;
break;
case 'squaredError':
case 'squared-error':
_lossfun = squaredErrorLoss;
break;
default:
throw Error( format( 'invalid option. `%s` option must be one of the following: "%s". Option: `%s`.', 'loss', [ 'epsilonInsensitive', 'huber', 'squaredError' ].join( '", "' ), opts.loss ) );
throw Error( format( 'invalid option. `%s` option must be one of the following: "%s". Option: `%s`.', 'loss', [ 'epsilon-insensitive', 'huber', 'squared-error' ].join( '", "' ), opts.loss ) );
}

// Set learning rate:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ tape( 'the `loss` option of the function specifies the used loss function', func
var i;

values = [
'epsilonInsensitive',
'epsilon-insensitive',
'huber',
'squaredError'
'squared-error'
];
len = values.length;

Expand Down