Logging a run
In this exercise, you will train a model using scikit-learn's Linear Regression to predict profit from the Unicorn dataset. You have created an experiment called Unicorn Sklearn Experiment and started a new run. You will log metrics for r2_score and parameters for n_jobs as well as log the training code as an artifact.
The Linear Regression model will be trained with n_jobs parameter set to 1. The r2_score metric has been produced using the r2_score() from scikit-learn based on y_pred variable which came from predictions of X_test.
model = LinearRegression(n_jobs=1)
model.fit(X_train, y_train)
y_pred = model.predict(X_test)
r2_score = r2_score(y_test, y_pred)
The mlflow module as well as the LinearRegression, train_test_split, and metrics modules from scikit-learn will be imported.
This exercise is part of the course
Introduction to MLflow
Exercise instructions
- Log the
r2_scorevariable as a metric called"r2_score". - Log a parameter called
"n_jobs"to the Tracking Server. - Log the
"train.py"file as an artifact in the run.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Log the metric r2_score as "r2_score"
____.____("____", ____)
# Log parameter n_jobs as "n_jobs"
____.____("____", ____)
# Log the training code
____.____("train.py")