This project demonstrates the use of MLflow for managing the end-to-end machine learning lifecycle on the Wine-Quality dataset using a Keras Sequential model. The focus of this project is on the MLflow workflow and how it can be used to track and manage machine learning experiments.
This project follows the MLflow structure, which consists of the following components:
- MLflow Tracking: used for logging and tracking experiments, including hyperparameters, metrics, and artifacts.
- MLflow Projects: used for packaging and deploying models.
- MLflow Models: used for serving and managing models.
Here are some common MLflow commands used in this project:
mlflow set_experiment: sets the experiment name.mlflow start_run: starts a new run.mlflow log_params: logs hyperparameters.mlflow log_metric: logs metrics.mlflow log_model: logs the model.mlflow register_model: registers the model in the model registry.
The getting-started.ipynb notebook executes the following MLflow workflow:
- Sets the experiment name and starts a new run.
- Logs hyperparameters and metrics.
- Trains the ANN model using Keras.
- Logs the model and registers it in the model registry.
The MLflow workflow consists of the following steps:
- Set Tracking URI: Set the tracking URI to store the experiment results.
mlflow.set_tracking_uri(uri="http://127.0.0.1:5000")
- Set Experiment: Set the experiment name to organize the runs.
mlflow.set_experiment("wine-quality")
- Start Run: Start a new run to track the experiment.
with mlflow.start_run(): # MLflow code here
- Log Parameters: Log the hyperparameters used in the experiment.
mlflow.log_params({"learning_rate": 0.01, "batch_size": 32})
- Log Metric: Log the metrics used to evaluate the experiment.
mlflow.log_metric("accuracy", 0.9)
- Set Tag: Set a tag to categorize the experiment for better organization and searchability.
mlflow.set_tag("model", "keras-sequential")
- Infer Signature: Model signature defines the input and output schema of your model.
signature = infer_signature(X_train, model.predict(X_train))
- Log Model: Log the model using MLflow for loading and deployment.
mlflow.keras.log_model(model, "model", signature=signature)
- Register Model: Model registry is used to manage and version models.
mlflow.register_model(model_uri, "wine-quality")
In this project, we use MLflow to track and manage the deep learning model. We start using MLflow after defining the model architecture and before training the model. We use MLflow to log the hyperparameters, metrics, and model.
- Model Definition: After defining the model architecture, we use MLflow to log the hyperparameters.
- Model Training: During model training, we use MLflow to log the metrics.
- Model Evaluation: After model evaluation, we use MLflow to log the final
- Use MLflow to track and compare experiments.
- Use MLflow to deploy and serve models.
- Use MLflow to manage and version models.