Skip to main content
Welcome to this guide on setting up an MLflow server and running an end-to-end machine learning experiment. In this demo, we simulate health insurance claims data (with injected anomalies) and build an anomaly detection model using the Isolation Forest algorithm. Follow along to set up your MLflow server in VS Code, generate synthetic data, train a model, and log results to MLflow.
Before you begin, ensure that you have VS Code and the required Python libraries installed. This guide assumes you have the necessary setup to run MLflow and execute Python scripts.

1. Setting Up MLflow

Begin by launching the MLflow UI. Open the terminal in VS Code and run:
After executing the command, MLflow will start, and a pop-up notification should appear. Click on “open browser” to verify that the MLflow web UI is accessible. Once confirmed, create a new terminal in VS Code to continue with the next steps.

2. Generating Synthetic Data

If you haven’t already generated the synthetic data, run the provided script. This script simulates health insurance claims, including some injected anomalies. Create a file named synthetic_health_claims.py and add the following content:
Run the script using the following command:
Upon execution, you should see an output confirming that the synthetic data was generated and saved. The console output will also show that the MLflow UI is running, along with relevant log messages.

3. Creating and Running the ML Experiment

In this section, you’ll train an ML model to perform anomaly detection using the Isolation Forest algorithm and log experiment details to the MLflow server.

Step 3.1: Model Training Script

Create a file named isolation_model.py with the following content:
Run the script by executing:
The terminal will display detailed output regarding the experiment, including logged parameters and metrics. A typical output snippet might look like this:

4. Validating the Experiment in MLflow

Once the script finishes running, refresh your browser where the MLflow UI is open. You should now see the “Health Insurance Claim Anomaly Detection” experiment, complete with parameters, metrics, and the model artifact.
The image shows an MLflow experiment interface displaying details of a machine learning run, including parameters, metrics, and model information for an anomaly detection task.
This UI confirms that your experiment has been successfully logged and is ready for further exploration or deployment.

5. Next Steps

In a production setting, your model may undergo multiple iterations and rigorous testing before deployment. For this demo, we directly use the output from this experiment. The logged model artifact, which might be stored as a pickle file or another format, can be downloaded from the MLflow UI and integrated further. The next phase typically involves building a service around the model using frameworks like BentoML. For more detailed information on BentoML, refer to the BentoML Documentation.
Thank you for reading this guide on setting up the MLflow server and running your ML experiment. For additional resources, check out the following links: Happy experimenting!

Watch Video