Create an Experiment¶
Creating an experiment in MLflow is simple. You just need to provide a name for the experiment, and MLflow will take care of the rest. If you want to create a new experiment, you can use the mlflow.set_experiment
function. This function will create a new experiment with the specified name and return its ID. If an experiment with the same name already exists, it will raise an exception.
import mlflow
experiment = mlflow.set_experiment("mlflow-demo")
We can see the details of the experiment by printing some of its attributes.
print(f"Name: {experiment.name}")
print(f"Experiment_id: {experiment.experiment_id}")
print(f"Artifact Location: {experiment.artifact_location}")
print(f"Tags: {experiment.tags}")
print(f"Lifecycle_stage: {experiment.lifecycle_stage}")
Name: mlflow-demo Experiment_id: 219393972832050318 Artifact Location: file:///home/sngular/projects/codespace/mlops-cookbook/docs/basics/mlruns/219393972832050318 Tags: {} Lifecycle_stage: active
What is an Experiment?¶
An "experiment" in MLflow is like a specific chapter in your research book. It's an organized set of steps and records that detail how you've tested a particular approach in your machine learning project. Each experiment in MLflow includes the code you've used, the configured parameters, the input data, the results obtained, and any additional notes you want to add.
For example, if you are developing a model to predict house prices, an experiment in MLflow might involve training the model with a specific dataset, adjusting parameters like the number of trees in a random forest model, recording performance metrics like mean squared error (MSE), and making notes about any significant observations. Every time you try a different set of parameters or data, or even change the algorithm, you can create a new experiment in MLflow to maintain a clear record of your research and results. This makes it easier to track your progress and make informed decisions in your machine learning project.