<!--
{
  "availability" : [
    "iOS: 18.0.0 -",
    "iPadOS: 18.0.0 -",
    "macCatalyst: 18.0.0 -",
    "macOS: 15.0.0 -",
    "tvOS: 18.0.0 -",
    "visionOS: 2.0.0 -",
    "watchOS: 11.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CreateMLComponents",
  "identifier" : "/documentation/CreateMLComponents/TimeSeriesForecasterBatches",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "Create ML Components"
    ],
    "preciseIdentifier" : "s:18CreateMLComponents27TimeSeriesForecasterBatchesV"
  },
  "title" : "TimeSeriesForecasterBatches"
}
-->

# TimeSeriesForecasterBatches

A sequence of forecaster batches on a time series shaped array.

```
struct TimeSeriesForecasterBatches<Scalar> where Scalar : MLShapedArrayScalar
```

## Overview

A time-series forecaster takes a series of samples and produces a prediction of the next samples.
For example the sequence `[1, 2, 3, 4]` could predict `[5, 6]`.
To train a forecaster, each training batch contains the input samples along with the annotations (ground truth
predictions). For example a batch could have this:

```
features = [
    [1, 2, 3, 4],
    [2, 3, 4, 5],
    [3, 4, 5, 6],
]
annotations = [
    [5, 6],
    [6, 7],
    [7, 8],
]
```

The shape of the features in the sequence is `[batchSize, inputWindowSize, featureSize]` and the shape of the
annotations is `[batchSize, forecastWindowSize, annotationSize]`. The batch sequence will return as many
feature-annotation examples as fit in the input. For example, an input sequence size of 10 with an input sample
count of 4 and a prediction sample count of 2 will produce 5 examples:

```
features: [1, 2, 3, 4], annotations: [5, 6]
features: [2, 3, 4, 5], annotations: [6, 7]
features: [3, 4, 5, 6], annotations: [7, 8]
features: [4, 5, 6, 7], annotations: [8, 9]
features: [5, 6, 7, 8], annotations: [9, 10]
```

Note that 9 and 10 are never used as features because there would be no annotations for those examples.

## Topics

### Creating a time series forecaster batch

[`init(features: MLShapedArray<Scalar>, annotations: MLShapedArray<Scalar>, batchSize: Int, inputWindowSize: Int, forecastWindowSize: Int, shufflesBatches: Bool) throws`](/documentation/CreateMLComponents/TimeSeriesForecasterBatches/init(features:annotations:batchSize:inputWindowSize:forecastWindowSize:shufflesBatches:))

Creates a batch sequence.

### Inspecting a time series forecaster batch

[`let annotations: MLShapedArray<Scalar>`](/documentation/CreateMLComponents/TimeSeriesForecasterBatches/annotations)

The original annotations.

[`let batchSize: Int`](/documentation/CreateMLComponents/TimeSeriesForecasterBatches/batchSize)

The batch size.

[`let features: MLShapedArray<Scalar>`](/documentation/CreateMLComponents/TimeSeriesForecasterBatches/features)

The original features.

[`let forecastWindowSize: Int`](/documentation/CreateMLComponents/TimeSeriesForecasterBatches/forecastWindowSize)

The prediction sample count.

[`let inputWindowSize: Int`](/documentation/CreateMLComponents/TimeSeriesForecasterBatches/inputWindowSize)

The input sample count.

[`var shufflesBatches: Bool`](/documentation/CreateMLComponents/TimeSeriesForecasterBatches/shufflesBatches)

A Boolean value indicating whether to shuffle the batches.

### Default Implementations

[Sequence Implementations](/documentation/CreateMLComponents/TimeSeriesForecasterBatches/Sequence-Implementations)

## Relationships

### Conforms To

[`Sequence`](/documentation/Swift/Sequence)

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

[`Sendable`](/documentation/Swift/Sendable)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)