メインコンテンツ

train

Train statistical process control (SPC) anomaly detector and obtain detection threshold

Since R2025a

Description

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

The train function trains a time series SPC (Statistical Process Control) anomaly detector as part of the time series anomaly detection workflow.

The SPC anomaly detector 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.

Input Arguments

collapse all

Anomaly detector, specified as a TimeSeriesSPCDetector object.

Training data set used to train the detector model within a detector object, specified as a matrix, a cell array, or a timetable. 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.

Training Options

expand all

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

Method for evaluating anomaly state of time series data , specified as "individual" or "ewma".

  • When you specify "individual", the detector evaluates and plots the time series data in time order.

  • When you specify "ewma", the detector evaluates and plots the exponentially weighted moving average of the time series.

Forgetting factor of the EWMA model. Lambda acts as a smoothing parameter by controlling how much each moving average value is influenced by past measurements. A higher Lambda value gives more weight to the more recent measurements.

Output Arguments

collapse all

Trained statistical process control anomaly detector model, returned as a trained TimeSeriesSPCDetector object.

Version History

Introduced in R2025a

expand all