Challenge: Steps in Parallel

Requirements

Continue to update the code to introduce the Random Forest model by performing the following updates.

[Import Random Forest]

from sklearn.ensemble import RandomForestClassifier

Add Random Forest Function

@step(name="random_forest")

def train_random_forest(x, x_test, y, n_estimators):

    """Train a Random Forest ensemble model."""

    n_estimators = int(n_estimators)

    model = RandomForestClassifier(n_estimators=n_estimators)

    model.fit(x, y)

    print(model.predict(x_test))

Add Random Forest Function to Pipeline

train_random_forest(x, x_test, y, n_estimators)

[Updated ml_pipeline Function Arguments]{style=“font-family: ‘Open Sans’, Verdana, Arial, Helvetica, sans-serif; font-weight: 600;”}

[n_estimators=100]{face=“monospace, serif” style=“font-family: monospace, serif;”}

[Updated ml_pipelineFunction Call]{style=“font-family: ‘Open Sans’, Verdana, Arial, Helvetica, sans-serif; font-weight: 600;”}

[ml_pipeline(rs=42, iters=100, n_estimators=100)]{face=“monospace, serif” style=“font-family: monospace, serif;”}

[Run the Pipeline]{style=“font-family: ‘Open Sans’, Verdana, Arial, Helvetica, sans-serif; font-weight: 600;”}

python3 -m kale kale_sdk_parallel_steps.py --kfp

SOLUTION

When you are finished, compare your notebook to the solution and make any necessary changes so that your notebook matches the solution in the next unit.