<!--
{
  "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/LinearTimeSeriesForecaster/update(_:with:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Create ML Components",
      "CreateMLComponents"
    ],
    "preciseIdentifier" : "s:18CreateMLComponents26LinearTimeSeriesForecasterV6update_4withxAC5ModelVyx_Gz_AA14AnnotatedBatchVyxGtYaKF"
  },
  "title" : "update(_:with:)"
}
-->

# update(_:with:)

Updates a model with a new batch of examples.

```
func update(_ model: inout LinearTimeSeriesForecaster<Scalar>.Transformer, with input: AnnotatedBatch<Scalar>) async throws -> Scalar
```

## Parameters

`model`

The model to update.

`input`

A shaped array of windowed features. The shape should be
`[batchSize, inputWindowSize, featureSize]`.

## Discussion

Use [`TimeSeriesForecasterBatches`](/documentation/CreateMLComponents/TimeSeriesForecasterBatches) to convert a shaped array of features into batches of windowed
features and annotations. Here is an example of training a forecaster:

```
let estimator = LinearTimeSeriesForecaster<Float>(configuration: configuration)
var model = estimator.makeTransformer()

let batches = try TimeSeriesForecasterBatches(
    features: features,       // shape [N, featureSize]
    annotations: annotations, // shape [N, annotationSize]
    batchSize: 32,
    inputWindowSize: configuration.inputWindowSize,
    forecastWindowSize: configuration.forecastWindowSize,
    shufflesBatches: true
)

for iteration in 0 ..< configuration.maximumIterationCount {
    for batch in batches {
        let loss = try await estimator.update(&model, with: batch)
        print("Loss: \(loss)")
    }
}
```

---

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)