<!--
{
  "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/OneHotEncoder",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "Create ML Components"
    ],
    "preciseIdentifier" : "s:18CreateMLComponents13OneHotEncoderV"
  },
  "title" : "OneHotEncoder"
}
-->

# OneHotEncoder

An estimator that encodes categorical values to an integer array.

```
struct OneHotEncoder<Category> where Category : Comparable, Category : Decodable, Category : Encodable, Category : Hashable
```

## Overview

The encoded array has an element count equal to the number of categories to encode.
The encoded array for a given category has repeating zero values except at one index where the value is 1.

## Topics

### Creating the estimator

[`init()`](/documentation/CreateMLComponents/OneHotEncoder/init())

Creates a one-hot encoding estimator.

### Fitting

[`func fitted<S>(to: S, eventHandler: EventHandler?) throws -> OneHotEncoder<Category>.Transformer`](/documentation/CreateMLComponents/OneHotEncoder/fitted(to:eventHandler:))

Fits a one-hot encoder to a sequence of categories.

### Default Implementations

[Estimator Implementations](/documentation/CreateMLComponents/OneHotEncoder/Estimator-Implementations)

[UpdatableEstimator Implementations](/documentation/CreateMLComponents/OneHotEncoder/UpdatableEstimator-Implementations)

## Relationships

### Conforms To

[`Estimator`](/documentation/CreateMLComponents/Estimator)

[`UpdatableEstimator`](/documentation/CreateMLComponents/UpdatableEstimator)

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

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

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

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

---

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)