Main Content

reset

Reset incremental classification model

Since R2022a

    Description

    Mdl = reset(Mdl) returns the incremental model Mdl with reset learned parameters. If any hyperparameters of Mdl are estimated during incremental training, reset function resets these hyperparameters as well. reset always preserves Mdl.Numpredictors property.

    For incremental classification models, reset always preserves Mdl.ClassNames property and resets Mdl.Prior if it is "empirical".

    example

    Examples

    collapse all

    Load the human activity data set. Randomly shuffle the data.

    load humanactivity
    n = numel(actid);
    rng(1); % For reproducibility
    idx = randsample(n,n);
    X = feat(idx,:);
    Y = actid(idx);

    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 = Y > 2;

    Create an incremental linear SVM model for binary classification. Configure it for loss by specifying the class names, prior class distribution (uniform), and arbitrary coefficient and bias values. Specify a metrics window size of 1000 observations.

    p = size(X,2);
    Beta = randn(p,1);
    Bias = randn(1);
    Mdl = incrementalClassificationLinear('Beta',Beta,'Bias',Bias,...
        'ClassNames',unique(Y),'Prior','uniform','MetricsWindowSize',1000,'Metrics','classiferror');

    Mdl is an incrementalClassificationLinear model. All its properties are read-only.

    Simulate a data stream with incoming chunks of 50 observations each.

    1. Call updateMetricsAndFit to update the performance metrics and fit the model to the incoming window of data. Overwrite the previous incremental model with the new one.

    2. Investigate the model.

    3. Call reset to reset the learned parameters and compare to the previous model to see which parameters are reset.

    numObsPerChunk = 50;
    nchunk = floor(n/numObsPerChunk);
    
    for j = 1:nchunk
        ibegin = min(n,numObsPerChunk*(j-1) + 1);
        iend   = min(n,numObsPerChunk*j);
        idx = ibegin:iend;    
        Mdl = updateMetricsAndFit(Mdl,X(idx,:),Y(idx));
    end

    Display some of the model parameters.

    Mdl
    Mdl = 
      incrementalClassificationLinear
    
                IsWarm: 1
               Metrics: [1x2 table]
            ClassNames: [0 1]
        ScoreTransform: 'none'
                  Beta: [60x1 double]
                  Bias: -0.9069
               Learner: 'svm'
    
    
    
    Mdl.Metrics
    ans=1×2 table
                               Cumulative    Window
                               __________    ______
    
        ClassificationError    0.0018185       0   
    
    
    Mdl.Beta(1:10)
    ans = 10×1
    
       -0.8806
       -0.0259
        1.6498
       12.0393
        0.4948
        8.9050
        0.1317
        0.0006
        0.1071
        0.0092
    
    

    The model is warm (IsWarm=1), you can see the value of the performance metric, ClassificationError, estimations for the model parameters, Bias and Beta.

    Reset the model and display the same parameters.

    newMdl = reset(Mdl)
    newMdl = 
      incrementalClassificationLinear
    
                IsWarm: 0
               Metrics: [1x2 table]
            ClassNames: [0 1]
        ScoreTransform: 'none'
                  Beta: [60x1 double]
                  Bias: 0
               Learner: 'svm'
    
    
    
    newMdl.Metrics
    ans=1×2 table
                               Cumulative    Window
                               __________    ______
    
        ClassificationError       NaN         NaN  
    
    
    newMdl.Beta(1:10)
    ans = 10×1
    
         0
         0
         0
         0
         0
         0
         0
         0
         0
         0
    
    

    reset function resets the warmup status of the model (IsWarm = 0), the values of the performance metrics and the estimated model parameters. In addition to these, it resets the properties, such as NumTrainingObservations, that the software updates at each iteration.

    Input Arguments

    collapse all

    Incremental learning model, specified as an incrementalClassificationKernel, incrementalClassificationLinear, incrementalClassificationECOC, or incrementalClassificationNaiveBayes model object. You can create Mdl directly or by converting a supported, traditionally trained machine learning model using the incrementalLearner function. For more details, see the corresponding object page.

    Version History

    Introduced in R2022a