.

@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."""

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}")

return model, train_acc

If you want to run the step function outside the context of a ZenML pipeline, all you need to do is call the step function outside of a ZenML pipeline. For example:

svc_trainer(X_train=..., y_train=...)

Next, we will combine our two steps into a pipeline and run it. As you can see, the parameter gamma is configurable as a pipeline input as well.

@pipeline

def training_pipeline(gamma: float = 0.002):

X_train, X_test, y_train, y_test = training_data_loader()

svc_trainer(gamma=gamma, X_train=X_train, y_train=y_train)

if __name__ == "__main__":

training_pipeline(gamma=0.0015)

Best Practice: Always nest the actual execution of the pipeline inside an if __name__ == "__main__" condition. This ensures that loading the pipeline from elsewhere does not also run it.

if __name__ == "__main__":

training_pipeline()

Running python run.py should look somewhat like this in the terminal:

Registered new pipeline with name `training_pipeline`.

Pipeline run `training_pipeline-2023_04_29-09_19_54_273710` has finished in 0.236s.

In the dashboard, you should now be able to see this new run, along with its runtime configuration and a visualization of the training data.

Configure with a YAML file

Instead of configuring your pipeline runs in code, you can also do so from a YAML file. This is best when we do not want to make unnecessary changes to the code; in production this is usually the case.

To do this, simply reference the file like this:

# Configure the pipeline

training_pipeline = training_pipeline.with_options(

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

# Run the pipeline