h='/local/path/to/config.yaml'

# Run the pipelinetraining_pipeline()

The reference to a local file will change depending on where you are executing the pipeline and code from, so please bear this in mind. It is best practice to put all config files in a configs directory at the root of your repository and check them into git history.

A simple version of such a YAML file could be:

parameters:

gamma: 0.01

Please note that this would take precedence over any parameters passed in the code.

If you are unsure how to format this config file, you can generate a template config file from a pipeline.

training_pipeline.write_run_configuration_template(path='/local/path/to/config.yaml')

Check out this section for advanced configuration options.

Full Code Example

This section combines all the code from this section into one simple script that you can use to run easily:

from typing_extensions import Tuple, Annotated

import pandas as pd

from sklearn.datasets import load_iris

from sklearn.model_selection import train_test_split

from sklearn.base import ClassifierMixin

from sklearn.svm import SVC

from zenml import pipeline, step

@step

def training_data_loader() -> Tuple[

Annotated[pd.DataFrame, "X_train"],

Annotated[pd.DataFrame, "X_test"],

Annotated[pd.Series, "y_train"],

Annotated[pd.Series, "y_test"],

]:

"""Load the iris dataset as tuple of Pandas DataFrame / Series."""

iris = load_iris(as_frame=True)

X_train, X_test, y_train, y_test = train_test_split(

iris.data, iris.target, test_size=0.2, shuffle=True, random_state=42

return X_train, X_test, y_train, y_test

@step

def svc_trainer(

X_train: pd.DataFrame,

y_train: pd.Series,

gamma: float = 0.001,

) -> Tuple[

Annotated[ClassifierMixin, "trained_model"],

Annotated[float, "training_acc"],

]:

"""Train a sklearn SVC classifier and log to MLflow."""

model = SVC(gamma=gamma)

model.fit(X_train.to_numpy(), y_train.to_numpy())

train_acc = model.score(X_train.to_numpy(), y_train.to_numpy())

print(f"Train accuracy: {train_acc}")