File size: 1,064 Bytes
42a08fb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
"""MLflow configuration helpers for the project."""

from __future__ import annotations

from typing import Mapping, Optional

import mlflow
import mlflow.lightgbm
import mlflow.sklearn
import mlflow.xgboost

DEFAULT_TRACKING_URI = "http://127.0.0.1:5000"
DEFAULT_EXPERIMENT_NAME = "OC_P6_Credit_Scoring"


def configure_mlflow(
    tracking_uri: str = DEFAULT_TRACKING_URI,
    experiment_name: str = DEFAULT_EXPERIMENT_NAME,
    *,
    autolog: bool = True,
    log_models: bool = False,
    extra_tags: Optional[Mapping[str, str]] = None,
) -> mlflow:
    """Configure MLflow tracking for this project.

    Returns the mlflow module to allow `mlflow = configure_mlflow()` usage.
    """
    if autolog:
        mlflow.autolog(log_models=log_models)
    else:
        # Désactiver tous les autologs explicitement
        mlflow.autolog(disable=True)

    mlflow.set_tracking_uri(tracking_uri)
    mlflow.set_experiment(experiment_name)

    if extra_tags:
        for key, value in extra_tags.items():
            mlflow.set_tag(key, value)

    return mlflow