# incrementalLearner

Convert binary classification support vector machine (SVM) model to incremental learner

## Syntax

IncrementalMdl = incrementalLearner(Mdl)
IncrementalMdl = incrementalLearner(Mdl,Name,Value)

## Description

example

IncrementalMdl = incrementalLearner(Mdl) returns a binary classification linear model for incremental learning, IncrementalMdl, using the hyperparameters and coefficients of the traditionally trained linear SVM model for binary classification, Mdl. Because its property values reflect the knowledge gained from Mdl, IncrementalMdl can predict labels given new observations, and it is warm, meaning that its predictive performance is tracked.

example

IncrementalMdl = incrementalLearner(Mdl,Name,Value) uses additional options specified by one or more name-value pair arguments. Some options require you to train IncrementalMdl before its predictive performance is tracked. For example, 'MetricsWarmupPeriod',50,'MetricsWindowSize',100 specifies a preliminary incremental training period of 50 observations before performance metrics are tracked, and specifies processing 100 observations before updating the performance metrics.

## Examples

collapse all

Train an SVM model by using fitcsvm, and then convert it to an incremental learner.

Load the human activity data set.

load humanactivity

For details on the data set, enter Description at the command line.

Responses can be one of five classes: Sitting, Standing, Walking, Running, or Dancing. Dichotomize the response by identifying whether the subject is moving (actid > 2).

Y = actid > 2;

Train SVM Model

Fit an SVM model to the entire data set. Discard the support vectors (Alpha) from the model so that the software uses the linear coefficients (Beta) for prediction.

TTMdl = fitcsvm(feat,Y); TTMdl = discardSupportVectors(TTMdl)
TTMdl = ClassificationSVM ResponseName: 'Y' CategoricalPredictors: [] ClassNames: [0 1] ScoreTransform: 'none' NumObservations: 24075 Beta: [60x1 double] Bias: -6.4243 KernelParameters: [1x1 struct] BoxConstraints: [24075x1 double] ConvergenceInfo: [1x1 struct] IsSupportVector: [24075x1 logical] Solver: 'SMO' Properties, Methods 

TTMdl is a ClassificationSVM model object representing a traditionally trained SVM model.

Convert Trained Model

Convert the traditionally trained SVM model to a binary classification linear model for incremental learning.

IncrementalMdl = incrementalLearner(TTMdl)
IncrementalMdl = incrementalClassificationLinear IsWarm: 1 Metrics: [1x2 table] ClassNames: [0 1] ScoreTransform: 'none' Beta: [60x1 double] Bias: -6.4243 Learner: 'svm' Properties, Methods 

IncrementalMdl is an incrementalClassificationLinear model object prepared for incremental learning using SVM.

• The incrementalLearner function Initializes the incremental learner by passing learned coefficients to it, along with other information TTMdl extracted from the training data.

• IncrementalMdl is warm (IsWarm is 1), which means that incremental learning functions can start tracking performance metrics.

• The incrementalLearner function specifies to train the model using the adaptive scale-invariant solver, whereas fitcsvm trained TTMdl using the SMO solver.

Predict Responses

An incremental learner created from converting a traditionally trained model can generate predictions without further processing.

Predict classification scores for all observations using both models.

[~,ttscores] = predict(TTMdl,feat); [~,ilcores] = predict(IncrementalMdl,feat); compareScores = norm(ttscores(:,1) - ilcores(:,1))
compareScores = 0 

The difference between the scores generated by the models is 0.

The default solver is the adaptive scale-invariant solver. If you specify this solver, you do not need to tune any parameters for training. However, if you specify either the standard SGD or ASGD solver instead, you can also specify an estimation period, during which the incremental fitting functions tune the learning rate.

Load the human activity data set.

load humanactivity

For details on the data set, enter Description at the command line.

Responses can be one of five classes: Sitting, Standing, Walking, Running, and Dancing. Dichotomize the response by identifying whether the subject is moving (actid > 2).

Y = actid > 2;

Randomly split the data in half: the first half have for training a model traditionally, and the second half for incremental learning.

n = numel(Y); rng(1) % For reproducibility cvp = cvpartition(n,'Holdout',0.5); idxtt = training(cvp); idxil = test(cvp); % First half of data Xtt = feat(idxtt,:); Ytt = Y(idxtt); % Second half of data Xil = feat(idxil,:); Yil = Y(idxil);

Fit an SVM model to the first half of the data. Standardize the predictor data by setting 'Standardize',true.

TTMdl = fitcsvm(Xtt,Ytt,'Standardize',true);

The Mu and Sigma properties of TTMdl contain the predictor data sample means and standard deviations, respectively.

Suppose that the distribution of the predictors is not expected to change in the future. Convert the traditionally trained SVM model to a binary classification linear model for incremental learning. Specify the standard SGD solver and an estimation period of 2000 observations (the default is 1000 when a learning rate is required).

IncrementalMdl = incrementalLearner(TTMdl,'Solver','sgd','EstimationPeriod',2000);

IncrementalMdl is an incrementalClassificationLinear model object. Because the predictor data of TTMdl is standardized (TTMdl.Mu and TTMdl.Sigma are nonempty), incrementalLearner prepares incremental learning functions to standardize supplied predictor data by using the previously learned moments (stored in IncrementalMdl.Mu and IncrementalMdl.Sigma).

Fit the incremental model to the second half of the data by using the fit function. At each iteration:

• Simulate a data stream by processing 10 observations at a time.

• Overwrite the previous incremental model with a new one fitted to the incoming observation.

• Store the learning rate and ${\beta }_{1}$ to see how the coefficients and learning rate evolve during training.

% Preallocation nil = numel(Yil); numObsPerChunk = 10; nchunk = floor(nil/numObsPerChunk); learnrate = [IncrementalMdl.LearnRate; zeros(nchunk,1)]; beta1 = [IncrementalMdl.Beta(1); zeros(nchunk,1)]; % Incremental fitting for j = 1:nchunk ibegin = min(nil,numObsPerChunk*(j-1) + 1); iend = min(nil,numObsPerChunk*j); idx = ibegin:iend; IncrementalMdl = fit(IncrementalMdl,Xil(idx,:),Yil(idx)); beta1(j + 1) = IncrementalMdl.Beta(1); learnrate(j + 1) = IncrementalMdl.LearnRate; end

IncrementalMdl is an incrementalClassificationLinear model object trained on all the data in the stream.

To see how the learning rate and ${\beta }_{1}$ evolved during training, plot them on separate subplots.

subplot(2,1,1) plot(beta1) ylabel('\beta_1') xline(IncrementalMdl.EstimationPeriod/numObsPerChunk,'r-.'); subplot(2,1,2) plot(learnrate) ylabel('Learning Rate') xline(IncrementalMdl.EstimationPeriod/numObsPerChunk,'r-.'); xlabel('Iteration')

The learning rate jumps to its auto-tuned value after the estimation period.

Because fit does not fit the model to the streaming data during the estimation period, ${\beta }_{1}$ is constant for the first 200 iterations (2000 observations). Then, ${\beta }_{1}$ changes during incremental fitting.

Use a trained SVM model to initialize an incremental learner. Prepare the incremental learner by specifying a metrics warm-up period, during which the updateMetricsAndFit function only fits the model. Specify a metrics window size of 500 observations.

Load the human activity data set.

load humanactivity

For details on the data set, enter Description at the command line

Responses can be one of five classes: Sitting, Standing, Walking, Running, and Dancing. Dichotomize the response by identifying whether the subject is moving (actid > 2).

Y = actid > 2;

Because the data set is grouped by activity, shuffle it to reduce bias. Then, randomly split the data in half: the first half for training a model traditionally, and the second half for incremental learning.

n = numel(Y); rng(1) % For reproducibility cvp = cvpartition(n,'Holdout',0.5); idxtt = training(cvp); idxil = test(cvp); shuffidx = randperm(n); X = feat(shuffidx,:); Y = Y(shuffidx); % First half of data Xtt = X(idxtt,:); Ytt = Y(idxtt); % Second half of data Xil = X(idxil,:); Yil = Y(idxil);

Fit an SVM model to the first half of the data.

TTMdl = fitcsvm(Xtt,Ytt);

Convert the traditionally trained SVM model to a binary classification linear model for incremental learning. Specify the following:

• A performance metrics warm-up period of 2000 observations

• A metrics window size of 500 observations

• Use of classification error and hinge loss to measure the performance of the model

IncrementalMdl = incrementalLearner(TTMdl,'MetricsWarmupPeriod',2000,'MetricsWindowSize',500,... 'Metrics',["classiferror" "hinge"]);

Fit the incremental model to the second half of the data by using the updateMetricsAndfit function. At each iteration:

• Simulate a data stream by processing 20 observations at a time.

• Overwrite the previous incremental model with a new one fitted to the incoming observation.

• Store ${\beta }_{1}$, the cumulative metrics, and the window metrics to see how they evolve during incremental learning.

% Preallocation nil = numel(Yil); numObsPerChunk = 20; nchunk = ceil(nil/numObsPerChunk); ce = array2table(zeros(nchunk,2),'VariableNames',["Cumulative" "Window"]); hinge = array2table(zeros(nchunk,2),'VariableNames',["Cumulative" "Window"]); beta1 = zeros(nchunk,1); % Incremental fitting for j = 1:nchunk ibegin = min(nil,numObsPerChunk*(j-1) + 1); iend = min(nil,numObsPerChunk*j); idx = ibegin:iend; IncrementalMdl = updateMetricsAndFit(IncrementalMdl,Xil(idx,:),Yil(idx)); ce{j,:} = IncrementalMdl.Metrics{"ClassificationError",:}; hinge{j,:} = IncrementalMdl.Metrics{"HingeLoss",:}; beta1(j + 1) = IncrementalMdl.Beta(1); end

IncrementalMdl is an incrementalClassificationLinear model object trained on all the data in the stream. During incremental learning and after the model is warmed up, updateMetricsAndFit checks the performance of the model on the incoming observation, and then fits the model to that observation.

To see how the performance metrics and ${\beta }_{1}$ evolved during training, plot them on separate subplots.

figure; subplot(3,1,1) plot(beta1) ylabel('\beta_1') xlim([0 nchunk]); xline(IncrementalMdl.MetricsWarmupPeriod/numObsPerChunk,'r-.'); subplot(3,1,2) h = plot(ce.Variables); xlim([0 nchunk]); ylabel('Classification Error') xline(IncrementalMdl.MetricsWarmupPeriod/numObsPerChunk,'r-.'); legend(h,ce.Properties.VariableNames,'Location','northwest') subplot(3,1,3) h = plot(hinge.Variables); xlim([0 nchunk]); ylabel('Hinge Loss') xline(IncrementalMdl.MetricsWarmupPeriod/numObsPerChunk,'r-.'); legend(h,hinge.Properties.VariableNames,'Location','northwest') xlabel('Iteration')

The plot suggests that updateMetricsAndFit does the following:

• Fit ${\beta }_{1}$ during all incremental learning iterations.

• Compute performance metrics after the metrics warm-up period only.

• Compute the cumulative metrics during each iteration.

• Compute the window metrics after processing 500 observations (25 iterations).

## Input Arguments

collapse all

Traditionally trained linear SVM model for binary classification, specified as a model object returned by its training or processing function.

Note

Incremental learning functions support only numeric input predictor data. If Mdl was fit to categorical data, use dummyvar to convert each categorical variable to a numeric matrix of dummy variables, and concatenate all dummy variable matrices and any other numeric predictors. For more details, see Dummy Variables.

### Name-Value Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: 'Solver','scale-invariant','MetricsWindowSize',100 specifies the adaptive scale-invariant solver for objective optimization, and specifies processing 100 observations before updating the performance metrics.
General Options

collapse all

Objective function minimization technique, specified as the comma-separated pair consisting of 'Solver' and a value in this table.

ValueDescriptionNotes
'scale-invariant'

• This algorithm is parameter free and can adapt to differences in predictor scales. Try this algorithm before using SGD or ASGD.

• To shuffle incoming batches before the fit function fits the model, set Shuffle to true.

'sgd'Stochastic gradient descent (SGD) [3][2]

• To train effectively with SGD, standardize the data and specify adequate values for hyperparameters using options listed in SGD and ASGD Solver Options.

• The fit function always shuffles an incoming batch of data before fitting the model.

'asgd'Average stochastic gradient descent (ASGD) [4]

• To train effectively with ASGD, standardize the data and specify adequate values for hyperparameters using options listed in SGD and ASGD Solver Options.

• The fit function always shuffles an incoming batch of data before fitting the model.

Example: 'Solver','sgd'

Data Types: char | string

Number of observations processed by the incremental model to estimate hyperparameters before training or tracking performance metrics, specified as the comma-separated pair consisting of 'EstimationPeriod' and a nonnegative integer.

Note

• If Mdl is prepared for incremental learning (all hyperparameters required for training are specified), incrementalLearner forces 'EstimationPeriod' to 0.

• If Mdl is not prepared for incremental learning, incrementalLearner sets 'EstimationPeriod' to 1000.

For more details, see Estimation Period.

Example: 'EstimationPeriod',100

Data Types: single | double

Flag to standardize the predictor data, specified as the comma-separated pair consisting of 'Standardize' and a value in this table.

ValueDescription
'auto'incrementalLearner determines whether the predictor variables need to be standardized. See Standardize Data.
trueThe software standardizes the predictor data.
falseThe software does not standardize the predictor data.

Under some conditions, incrementalLearner can override your specification. For more details, see Standardize Data.

Example: 'Standardize',true

Data Types: logical | char | string

SGD and ASGD Solver Options

collapse all

Mini-batch size, specified as the comma-separated pair consisting of 'BatchSize' and a positive integer. At each iteration during training, incrementalLearner uses min(BatchSize,numObs) observations to compute the subgradient, where numObs is the number of observations in the training data passed to fit or updateMetricsAndFit.

Example: 'BatchSize',1

Data Types: single | double

Ridge (L2) regularization term strength, specified as the comma-separated pair consisting of 'Lambda' and a nonnegative scalar.

Example: 'Lambda',0.01

Data Types: single | double

Learning rate, specified as the comma-separated pair consisting of 'LearnRate' and 'auto' or a positive scalar. LearnRate controls the optimization step size by scaling the objective subgradient.

For 'auto':

• If EstimationPeriod is 0, the initial learning rate is 0.7.

• If EstimationPeriod > 0, the initial learning rate is 1/sqrt(1+max(sum(X.^2,obsDim))), where obsDim is 1 if the observations compose the columns of the predictor data, and 2 otherwise. fit and updateMetricsAndFit set the value when you pass the model and training data to either function.

The name-value pair argument 'LearnRateSchedule' determines the learning rate for subsequent learning cycles.

Example: 'LearnRate',0.001

Data Types: single | double | char | string

Learning rate schedule, specified as the comma-separated pair consisting of 'LearnRateSchedule' and a value in this table, where LearnRate specifies the initial learning rate ɣ0.

ValueDescription
'constant'The learning rate is ɣ0 for all learning cycles.
'decaying'

The learning rate at learning cycle t is

${\gamma }_{t}=\frac{{\gamma }_{0}}{{\left(1+\lambda {\gamma }_{0}t\right)}^{c}}.$

Example: 'LearnRateSchedule','constant'

Data Types: char | string

collapse all

Flag for shuffling the observations in the batch at each iteration, specified as the comma-separated pair consisting of 'Shuffle' and a value in this table.

ValueDescription
trueThe software shuffles observations in each incoming batch of data before processing the set. This action reduces bias induced by the sampling scheme.
falseThe software processes the data in the order received.

Example: 'Shuffle',false

Data Types: logical

Performance Metrics Options

collapse all

Model performance metrics to track during incremental learning with the updateMetrics or updateMetricsAndFit function, specified as a built-in loss function name, string vector of names, function handle (@metricName), structure array of function handles, or cell vector of names, function handles, or structure arrays.

The following table lists the built-in loss function names. You can specify more than one by using a string vector.

NameDescription
"binodeviance"Binomial deviance
"classiferror"Classification error
"exponential"Exponential
"hinge"Hinge
"logit"Logistic
"quadratic"Quadratic

For more details on the built-in loss functions, see loss.

Example: 'Metrics',["classiferror" "hinge"]

To specify a custom function that returns a performance metric, use function handle notation. The function must have this form:

metric = customMetric(C,S)

• The output argument metric is an n-by-1 numeric vector, where each element is the loss of the corresponding observation in the data by processing the incremental learning functions during a learning cycle.

• You specify the function name (customMetric).

• C is an n-by-2 logical matrix with rows indicating the class to which the corresponding observation belongs. The column order corresponds to the class order in Mdl.ClassNames. Create C by setting C(p,q) = 1, if observation p is in class q, for each observation in the specified data. Set the other element in row p to 0.

• S is an n-by-2 numeric matrix of predicted classification scores. S is similar to the score output of predict, where rows correspond to observations in the data and the column order corresponds to the class order in Mdl.ClassNames. S(p,q) is the classification score of observation p being classified in class q.

To specify multiple custom metrics and assign a custom name to each, use a structure array. To specify a combination of built-in and custom metrics, use a cell vector.

Example: 'Metrics',struct('Metric1',@customMetric1,'Metric2',@customMetric2)

Example: 'Metrics',{@customMetric1 @customeMetric2 'logit' struct('Metric3',@customMetric3)}

updateMetrics and updateMetricsAndFit store specified metrics in a table in the property IncrementalMdl.Metrics. The data type of Metrics determines the row names of the table.

'Metrics' Value Data TypeDescription of Metrics Property Row NameExample
String or character vectorName of corresponding built-in metricRow name for "classiferror" is "ClassificationError"
Structure arrayField nameRow name for struct('Metric1',@customMetric1) is "Metric1"
Function handle to function stored in a program fileName of functionRow name for @customMetric is "customMetric"
Anonymous functionCustomMetric_j, where j is metric j in MetricsRow name for @(C,S)customMetric(C,S)... is CustomMetric_1

For more details on performance metrics options, see Performance Metrics.

Data Types: char | string | struct | cell | function_handle

Number of observations the incremental model must be fit to before it tracks performance metrics in its Metrics property, specified as the comma-separated pair consisting of 'MetricsWarmupPeriod' and a nonnegative integer. The incremental model is warm after incremental fitting functions fit MetricsWarmupPeriod observations to the incremental model (EstimationPeriod + MetricsWarmupPeriod observations).

For more details on performance metrics options, see Performance Metrics.

Data Types: single | double

Number of observations to use to compute window performance metrics, specified as a positive integer.

For more details on performance metrics options, see Performance Metrics.

Data Types: single | double

## Output Arguments

collapse all

Binary classification linear model for incremental learning, returned as an incrementalClassificationLinear model object. IncrementalMdl is also configured to generate predictions given new data (see predict).

To initialize IncrementalMdl for incremental learning, incrementalLearner passes the values of the Mdl properties in this table to congruent properties of IncrementalMdl.

PropertyDescription
BetaScaled linear model coefficients, Mdl.Beta/Mdl.KernelParameters.Scale, a numeric vector
BiasModel intercept, a numeric scalar
ClassNamesClass labels for binary classification, two-element list
MuPredictor variable means, a numeric vector
PriorPrior class label distribution, a numeric vector
SigmaPredictor variable standard deviations, a numeric vector

collapse all

### Incremental Learning

Incremental learning, or online learning, is a branch of machine learning concerned with processing incoming data from a data stream, possibly given little to no knowledge of the distribution of the predictor variables, aspects of the prediction or objective function (including tuning parameter values), or whether the observations are labeled. Incremental learning differs from traditional machine learning, where enough labeled data is available to fit to a model, perform cross-validation to tune hyperparameters, and infer the predictor distribution.

Given incoming observations, an incremental learning model processes data in any of the following ways, but usually in this order:

• Predict labels.

• Measure the predictive performance.

• Check for structural breaks or drift in the model.

• Fit the model to the incoming observations.

### Adaptive Scale-Invariant Solver for Incremental Learning

The adaptive scale-invariant solver for incremental learning, introduced in [1], is a gradient-descent-based objective solver for training linear predictive models. The solver is hyperparameter free, insensitive to differences in predictor variable scales, and does not require prior knowledge of the distribution of the predictor variables. These characteristics make it well suited to incremental learning.

The standard SGD and ASGD solvers are sensitive to differing scales among the predictor variables, resulting in models that can perform poorly. To achieve better accuracy using SGD and ASGD, you can standardize the predictor data, and tune the regularization and learning rate parameters can require tuning. For traditional machine learning, enough data is available to enable hyperparameter tuning by cross-validation and predictor standardization. However, for incremental learning, enough data might not be available (for example, observations might be available only one at a time) and the distribution of the predictors might be unknown. These characteristics make parameter tuning and predictor standardization difficult or impossible to do during incremental learning.

The incremental fitting functions for classification fit and updateMetricsAndFit use the more aggressive ScInOL2 version of the algorithm.

## Algorithms

collapse all

### Estimation Period

During the estimation period, incremental fitting functions fit and updateMetricsAndFit use the first incoming EstimationPeriod observations to estimate (tune) hyperparameters required for incremental training. This table describes the hyperparameters and when they are estimated or tuned.

HyperparameterModel PropertyUseHyperparameters Estimated
Predictor means and standard deviations

Mu and Sigma

Standardize predictor data

When both these conditions apply:

• When you set 'Standardize',true (see Standardize Data)

• IncrementalMdl.Mu and IncrementalMdl.Sigma are empty arrays [].

Learning rateLearnRateAdjust solver step size

When both of these conditions apply:

The functions fit only the last estimation period observation to the incremental model, and they do not use any of the observations to track the performance of the model. At the end of the estimation period, the functions update the properties that store the hyperparameters.

### Standardize Data

If incremental learning functions are configured to standardize predictor variables, they do so using the means and standard deviations stored in the Mu and Sigma properties of the incremental learning model IncrementalMdl.

• If you standardized the predictor data when you trained the input model Mdl by using fitcsvm, the following conditions apply:

• incrementalLearner passes the means in Mdl.Mu and standard deviations in Mdl.Sigma to the congruent incremental learning model properties.

• Incremental learning functions always standardize the predictor data, regardless of the value of the 'Standardize' name-value pair argument.

• When you set 'Standardize',true, and IncrementalMdl.Mu and IncrementalMdl.Sigma are empty, the following conditions apply:

• If the estimation period is positive (see the EstimationPeriod property of IncrementalMdl), incremental fitting functions estimate means and standard deviations using the estimation period observations.

• If the estimation period is 0, incrementalLearner forces the estimation period to 1000. Consequently, incremental fitting functions estimate new predictor variable means and standard deviations during the forced estimation period.

• When you set 'Standardize','auto' (the default), the following conditions apply.

• If IncrementalMdl.Mu and IncrementalMdl.Sigma are empty, incremental learning functions do not standardize predictor variables.

• Otherwise, incremental learning functions standardize the predictor variables using their means and standard deviations in IncrementalMdl.Mu and IncrementalMdl.Sigma, respectively. Incremental fitting functions do not estimate new means and standard deviations regardless of the length of the estimation period.

• When incremental fitting functions estimate predictor means and standard deviations, the functions compute weighted means and weighted standard deviations using the estimation period observations. Specifically, the functions standardize predictor j (xj) using

${x}_{j}^{\ast }=\frac{{x}_{j}-{\mu }_{j}^{\ast }}{{\sigma }_{j}^{\ast }}.$

where

• xj is predictor j, and xjk is observation k of predictor j in the estimation period.

• ${\mu }_{j}^{\ast }=\frac{1}{\sum _{k}{w}_{k}^{\ast }}\sum _{k}{w}_{k}^{\ast }{x}_{jk}.$

• ${\left({\sigma }_{j}^{\ast }\right)}^{2}=\frac{1}{\sum _{k}{w}_{k}^{\ast }}\sum _{k}{w}_{k}^{\ast }{\left({x}_{jk}-{\mu }_{j}^{\ast }\right)}^{2}.$

• where

• pk is the prior probability of class k (Prior property of the incremental model).

• wj is observation weight j.

### Performance Metrics

• The updateMetrics and updateMetricsAndFit functions are incremental learning functions that track model performance metrics ('Metrics') from new data when the incremental model is warm (IsWarm property). An incremental model is warm after fit or updateMetricsAndFit fit the incremental model to 'MetricsWarmupPeriod' observations, which is the metrics warm-up period.

If 'EstimationPeriod' > 0, the functions estimate hyperparameters before fitting the model to data. Therefore, the functions must process an additional EstimationPeriod observations before the model starts the metrics warm-up period.

• The Metrics property of the incremental model stores two forms of each performance metric as variables (columns) of a table, Cumulative and Window, with individual metrics in rows. When the incremental model is warm, updateMetrics and updateMetricsAndFit update the metrics at the following frequencies:

• Cumulative — The functions compute cumulative metrics since the start of model performance tracking. The functions update metrics every time you call the functions and base the calculation on the entire supplied data set.

• Window — The functions compute metrics based on all observations within a window determined by the 'MetricsWindowSize' name-value pair argument. 'MetricsWindowSize' also determines the frequency at which the software updates Window metrics. For example, if MetricsWindowSize is 20, the functions compute metrics based on the last 20 observations in the supplied data (X((end – 20 + 1):end,:) and Y((end – 20 + 1):end)).

Incremental functions that track performance metrics within a window use the following process:

1. For each specified metric, store a buffer of length MetricsWindowSize and a buffer of observation weights.

2. Populate elements of the metrics buffer with the model performance based on batches of incoming observations, and store corresponding observations weights in the weights buffer.

3. When the buffer is filled, overwrite IncrementalMdl.Metrics.Window with the weighted average performance in the metrics window. If the buffer is overfilled when the function processes a batch of observations, the latest incoming MetricsWindowSize observations enter the buffer, and the earliest observations are removed from the buffer. For example, suppose MetricsWindowSize is 20, the metrics buffer has 10 values from a previously processed batch, and 15 values are incoming. To compose the length 20 window, the functions use the measurements from the 15 incoming observations and the latest 5 measurements from the previous batch.

## References

[1] Kempka, Michał, Wojciech Kotłowski, and Manfred K. Warmuth. "Adaptive Scale-Invariant Online Algorithms for Learning Linear Models." CoRR (February 2019). https://arxiv.org/abs/1902.07528.

[2] Langford, J., L. Li, and T. Zhang. “Sparse Online Learning Via Truncated Gradient.” J. Mach. Learn. Res., Vol. 10, 2009, pp. 777–801.

[3] Shalev-Shwartz, S., Y. Singer, and N. Srebro. “Pegasos: Primal Estimated Sub-Gradient Solver for SVM.” Proceedings of the 24th International Conference on Machine Learning, ICML ’07, 2007, pp. 807–814.

[4] Xu, Wei. “Towards Optimal One Pass Large Scale Learning with Averaged Stochastic Gradient Descent.” CoRR, abs/1107.2490, 2011.

Introduced in R2020b