Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
def mlflow_run(self, name='n-york-taxi-test-run'):
:param name: Name of the run to be logged by MLflow
:return: Tuple (ExperimentID, runID)
with mlflow.start_run(run_name=name) as run:
# retrieve current run and experiment id
runID =
experimentID =
# preprocess data, create model and train/evaluate
# with training and validation data
_params = self.params[0]
metrics = self._metrics[0]
mae = metrics['mean_absolute_error']
mse = metrics['loss']
# compute regression evaluation metrics
rmse = np.sqrt(mse)
# ***************************** MLflow Tracking Start
# Log input parameters
# Log metrics
mlflow.log_metric("mae", mae)
mlflow.log_metric("mse", mse)
mlflow.log_metric("rmse", rmse)
# Log model
mlflow.keras.log_model(self.model, "Keras_model for NY-Taxi dataset")
# ***************************** MLflow Tracking End
print("MLflow Run with run_id {} and experiment_id {}".format(runID, experimentID))
print('Mean Absolute Error :', mae)
print('Mean Squared Error :', mse)
print('Root Mean Squared Error:', rmse)
return (experimentID, runID)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment