主要内容

train

Train time series machine learning anomaly detector and obtain detection threshold

Since R2026a

Description

Add-On Required: This feature requires the Time Series Anomaly Detection for MATLAB add-on.

The train function trains time series machine learning anomaly detectors as part of the time series anomaly detection workflow.

The machine learning anomaly detectors provide two options that you can use to control training —window length and training stride. Unlike deep learning anomaly detectors, you cannot use GPU or parallel CPU processing with these models.

detector = train(detector,trainData) trains the anomaly detector detector with a training data set trainData that contains only normal data, and not any anomalous data. This syntax uses default options.

When the ThresholdMethod property for detector is set to any method but "manual", train also obtains the detection threshold that the detector uses to identify an anomaly.

You can use train to train a newly created detector or continue the training of a previously trained detector.

For an example of using train as part of the detector development workflow, see .

detector = train(detector,trainData,Name=Value) specifies additional training options using name-value arguments, which are the same for all machine learning detectors.

Input Arguments

collapse all

All Detectors

Training data set used to train the detector model within a detector object, specified as a matrix, a cell array, a timetable, or a cell array of timetables. trainData must contain only normal data, and not any anomalous data.

When trainData contains m sets of signals, each of which contain n channels, the possible formats are these:

  • n-column matrix that consists of a single multichannel signal observation (m=1).

    A sufficiently long single observation can be as effective for training as multiple shorter observations.

  • Cell array with m cells that each contain a matrix that has NumChannels columns.

  • Timetable that contains a single multichannel signal observation, arranged in one of two possible ways.

    • The n channels are distributed in the columns of a matrix that the timetable contains in a single variable

    • The n channels are represented by n timetable variables that each contain a vector.

      In either case, the timetable must contain finite, increasing, and uniformly sampled time values.

Name-Value Arguments

expand all

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Example: detectorIF = train(detectorIF,WindowLength=15) sets the value of the sliding window WindowLength to 15 when training the TimeSeriesIforest model detectorIF.

Machine Learning Training Options

expand all

Window length of each time series segment, specified as a positive integer scalar.

Stride length of sliding window in training stage, specified as a positive integer.

Output Arguments

collapse all

Trained anomaly detector model, returned as a trained TimeSeriesIForestDetector, TimeSeriesRRCForestDetector, TimeSeriesLOFDetector, or TimeSeriesOCSVMDetector object.

Version History

Introduced in R2026a

expand all