<!--
{
  "availability" : [
    "iOS: 16.0.0 -",
    "iPadOS: 16.0.0 -",
    "macCatalyst: 16.0.0 -",
    "macOS: 13.0.0 -",
    "tvOS: 16.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 11.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CreateMLComponents",
  "identifier" : "/documentation/CreateMLComponents/meanSquaredError(_:_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Create ML Components"
    ],
    "preciseIdentifier" : "s:18CreateMLComponents16meanSquaredErroryxq__q0_tSFRz7ElementQy_RszSlR_SlR0_ACQy0_ADRSr1_lF"
  },
  "title" : "meanSquaredError(_:_:)"
}
-->

# meanSquaredError(_:_:)

Computes the mean squared error between predicted and ground truth values.

```
@backDeployed(before: macOS 15.0, iOS 18.0, tvOS 18.0, visionOS 2.0)
func meanSquaredError<T>(_ predicted: some Collection, _ groundTruth: some Collection) -> T where T : FloatingPoint
```

## Parameters

`predicted`

The predicted values.

`groundTruth`

The ground truth values. The collection must have same number of elements as the predicted values.

## Return Value

The mean squared error.

## Discussion

Empty collections of predicted and ground truth values will return a value of NaN.

---

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)