<jupyter_start><jupyter_text>Demo: ML Flow[MLFlow](https://mlflow.org/) is a tool to keep track of experiments. Is easy to setup and you can keep track of different parameters and metrics.<jupyter_code>import mlflow

from sklearn.datasets import load_iris
from sklearn.metrics import precision_recall_fscore_support
from sklearn.tree import DecisionTreeClassifier
from sklearn.model_selection import train_test_split
data = load_iris()
X, y = data["data"], data["target"]
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)<jupyter_output><empty_output><jupyter_text>SetupTo get started, set the experiment name. Different runs of the same experiment should be saved under the same experiment name to make it possible to compare.You can log the parameters via `log_param(name, value)` (for single parameters) and `log_params(Dict[name, value])` for multiple parameters.You can log the metrics via `log_metric(name, value)`.For more possibilities check the [documentation](https://mlflow.org/docs/latest/index.html)<jupyter_code>mlflow.set_experiment("iris_experiment")

with mlflow.start_run():
    params = {
        "max_depth": 1,
        "criterion": "entropy"
    }
    
    mlflow.log_params(params)
    
    clf = DecisionTreeClassifier(**params)
    clf.fit(X_train, y_train)
    
    prec, rec, fscore, _ = precision_recall_fscore_support(y_test, clf.predict(X_test), average="macro")
    mlflow.log_metric("precision", prec)
    mlflow.log_metric("recall", rec)
    mlflow.log_metric("f1-score", fscore)<jupyter_output><empty_output><jupyter_text>Second ExperimentWe run two experiment to see how they behave.<jupyter_code>with mlflow.start_run():
    params = {
        "max_depth": 6,
        "criterion": "gini"
    }
    
    mlflow.log_params(params)
    
    clf = DecisionTreeClassifier(**params)
    clf.fit(X_train, y_train)
    
    prec, rec, fscore, _ = precision_recall_fscore_support(y_test, clf.predict(X_test), average="macro")
    mlflow.log_metric("precision", prec)
    mlflow.log_metric("recall", rec)
    mlflow.log_metric("f1-score", fscore)<jupyter_output><empty_output><jupyter_text>Checking the resultsTo check the results you should run `mlflow ui` from your terminal, or you can run it from here (warning, if you run the cell you need to stop the cell before running anything else).<jupyter_code>!mlflow ui<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10286188303608461, 'fraction_numerical': 0.0033181252592285357, 'mean_word_length': 5.10632911392405, 'pattern_counts': {'":': 4, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '403582', 'license': 'MIT', 'n_tokens_mistral': 796, 'n_tokens_neox': 776, 'n_words': 203, 'path': 'teorico/demo_12_mlflow.ipynb', 'repo_name': 'guillepaez53/AprendizajeSupervisado', 'size': '2411'}