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

# LinearRegressor

A linear regressor.

```
struct LinearRegressor<Scalar> where Scalar : MLShapedArrayScalar, Scalar : BinaryFloatingPoint
```

## Topics

### Creating a regressor

[`init(configuration: LinearRegressor<Scalar>.Configuration)`](/documentation/CreateMLComponents/LinearRegressor/init(configuration:))

Creates a linear regressor.

[`struct Configuration`](/documentation/CreateMLComponents/LinearRegressor/Configuration-swift.struct)

A linear regressor configuration.

### Getting the configuration

[`var configuration: LinearRegressor<Scalar>.Configuration`](/documentation/CreateMLComponents/LinearRegressor/configuration-swift.property)

The linear regressor configuration.

### Encoding and decoding

[`func encodeWithOptimizer(LinearRegressorModel<Scalar>, to: inout any EstimatorEncoder) throws`](/documentation/CreateMLComponents/LinearRegressor/encodeWithOptimizer(_:to:))

Encodes the transformer and optimizer to an encoder.

[`func decodeWithOptimizer(from: inout any EstimatorDecoder) throws -> LinearRegressorModel<Scalar>`](/documentation/CreateMLComponents/LinearRegressor/decodeWithOptimizer(from:))

Reads the encoded transformer and optimizer with a decoder.

### Fitting

[`func fitted<Input>(to: Input, eventHandler: EventHandler?) async throws -> LinearRegressorModel<Scalar>`](/documentation/CreateMLComponents/LinearRegressor/fitted(to:eventHandler:))

Fits a linear regressor model to a sequence of examples.

[`func fitted<Input, Validation>(to: Input, validateOn: Validation, eventHandler: EventHandler?) async throws -> LinearRegressorModel<Scalar>`](/documentation/CreateMLComponents/LinearRegressor/fitted(to:validateOn:eventHandler:))

Fits a linear regressor model to a sequence of examples.

[`typealias Annotation`](/documentation/CreateMLComponents/LinearRegressor/Annotation)

The annotation type.

[`typealias Transformer`](/documentation/CreateMLComponents/LinearRegressor/Transformer)

The transformer type created by this estimator.

### Default Implementations

[UpdatableSupervisedEstimator Implementations](/documentation/CreateMLComponents/LinearRegressor/UpdatableSupervisedEstimator-Implementations)

## Relationships

### Conforms To

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

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

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

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

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

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

---

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)