<!--
{
  "availability" : [
    "macOS: 10.15.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CreateML",
  "identifier" : "/documentation/CreateML/MLWordEmbedding/prediction(from:maxCount:maxDistance:distanceType:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Create ML",
      "CreateML"
    ],
    "preciseIdentifier" : "s:8CreateML15MLWordEmbeddingV10prediction4from8maxCount0G8Distance12distanceTypeSaySS4text_Sd0J0tGSS_SiSdSo010NLDistanceK0VtKF"
  },
  "title" : "prediction(from:maxCount:maxDistance:distanceType:)"
}
-->

# prediction(from:maxCount:maxDistance:distanceType:)

Predicts neighbors.

```
func prediction(from text: String, maxCount: Int = 10, maxDistance: Double = 2.0, distanceType: NLDistanceType = .cosine) throws -> [(text: String, distance: Double)]
```

## Parameters

`text`

A string in the embedding vocabulary.

`maxCount`

The largest number of neighboring strings.

`maxDistance`

The maximum allowed neighbor distance.

`distanceType`

The type of distance formula to use for evaluating a neighbor’s distance from the input string.

## Return Value

An array of neighboring strings and their distances to the input string.

## Discussion

The distance values are calculated with a formula determined by
<doc://com.apple.documentation/documentation/NaturalLanguage/NLDistanceType>,
such as
<doc://com.apple.documentation/documentation/NaturalLanguage/NLDistanceType/cosine>.

---

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)