Registrare il modello
L'ultimo passaggio è registrare e loggare il modello addestrato con MLflow. In questo modo puoi tracciare e versionare i modelli per la messa in produzione.
I pacchetti datetime, mlflow, mlforecast.flavor e il modello addestrato mlf sono già caricati per te.
Questo esercizio fa parte del corso
Progettare pipeline di forecasting per la produzione
Istruzioni dell'esercizio
- Imposta
run_nameusando il timestamp corrente creato per te nella variabilerun_time. - Usa
mlflow.start_run()per avviare una run con l'ID esperimento specificato. - Registra il modello usando il metodo corretto.
Esercizio pratico interattivo
Prova a risolvere questo esercizio completando il codice di esempio.
experiment_name = "ml_forecast"
try:
mlflow.create_experiment(name=experiment_name)
meta = mlflow.get_experiment_by_name(experiment_name)
print(f"Setting a new experiment {experiment_name}")
except:
print(f"Experiment {experiment_name} exists, pulling the metadata")
meta = mlflow.get_experiment_by_name(experiment_name)
# Setup the run name and time
run_time = datetime.datetime.now().strftime("%Y-%m-%d %H-%M-%S")
run_name = f"lightGBM6_{____}"
# Start the run
with mlflow.____(experiment_id=meta.experiment_id, run_name=run_name) as run:
# Log the model
mlforecast.flavor.____(model=mlf, artifact_path="prod_model")
print(f"MLflow Run created - Name: {run_name}, ID: {run.info.run_id}")