<!--
{
  "availability" : [
    "iOS: 15.0.0 -",
    "iPadOS: 15.0.0 -",
    "macCatalyst: 15.0.0 -",
    "macOS: 11.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CreateML",
  "identifier" : "/documentation/CreateML/MLImageClassifier/init(trainingData:parameters:)-4r6hr",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Create ML"
    ],
    "preciseIdentifier" : "s:8CreateML17MLImageClassifierV12trainingData10parametersA2C0F6SourceO_AC15ModelParametersVtKcfc"
  },
  "title" : "init(trainingData:parameters:)"
}
-->

# init(trainingData:parameters:)

Creates an image classifier with a training dataset represented by a data source.

```
init(trainingData: MLImageClassifier.DataSource, parameters: MLImageClassifier.ModelParameters = ModelParameters(
            validation: .split(strategy: .automatic),
            augmentation: [],
            algorithm: .transferLearning(
                featureExtractor: .scenePrint(revision: 1),
                classifier: .logisticRegressor
            )
        )) throws
```

## Parameters

`trainingData`

A set of labeled images the task uses to train the image classifier model, contained in a
data source.

`parameters`

An `MLImageClassifier/ModelParameters-swift.struct` instance you use to configure the model
for the training session.

## Discussion

When you create an `MLImageClassifier` instance, initialize it with an
`MLImageClassifier/ModelParameters-swift.struct` structure. This allows you to configure the image classifier
training process. For example, you can explicitly define the validation dataset instead of allowing the model
to choose a random selection of your training data. Alternatively, as shown in the following example, set
`validationData` to `nil` to allow the classifier to choose the validation data for you from among your
training data. This lets you set other parameters—like maximum iterations and augmentation options—to values
other than the default.

```swift
let parameters = MLImageClassifier.ModelParameters(
    featureExtractor: .scenePrint(revision: 1),
    validationData: nil,
    maxIterations: 20,
    augmentationOptions: [.crop]
)
```

Use the parameter structure and your training data to build a classifier. The following example uses training
data from labeled directories within a directory called `Training`, which resides in the `Downloads` directory:

```swift
if let downloads = FileManager.default.urls(for: .downloadsDirectory, in: .userDomainMask).first {
    let trainingURL = downloads.appendingPathComponent("Training")
    let classifier = try MLImageClassifier(
        trainingData: .labeledDirectories(at: trainingURL),
        parameters: parameters
    )
}
```

Training begins immediately.

> Note: If you represent your training data with a dictionary of strings and corresponding URL arrays, use
> ``MLImageClassifier/init(trainingData:parameters:)-7j4w6`` instead.

---

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)