<jupyter_start><jupyter_text>Logging results and uploading models to Comet MLIn this example, we train a simple XGBoost model and log the trainingresults to Comet ML. We also save the resulting model checkpointsas artifacts. Let's start with installing our dependencies:<jupyter_code>!pip install -qU "ray[tune]" sklearn xgboost_ray comet_ml<jupyter_output><empty_output><jupyter_text>Then we need some imports:<jupyter_code>import ray

from ray.air import RunConfig
from ray.air.result import Result
from ray.air.train.integrations.xgboost import XGBoostTrainer
from ray.tune.integration.comet import CometLoggerCallback
from sklearn.datasets import load_breast_cancer<jupyter_output><empty_output><jupyter_text>We define a simple function that returns our training dataset as a Ray Dataset:<jupyter_code>def get_train_dataset() -> ray.data.Dataset:
    """Return the "Breast cancer" dataset as a Ray dataset."""
    data_raw = load_breast_cancer(as_frame=True)
    df = data_raw["data"]
    df["target"] = data_raw["target"]
    return ray.data.from_pandas(df)<jupyter_output><empty_output><jupyter_text>Now we define a simple training function. All the magic happens within the `CometLoggerCallback`:```pythonCometLoggerCallback(    project_name=comet_project,    save_checkpoints=True,)```It will automatically log all results to Comet ML and upload the checkpoints as artifacts. It assumes you're logged in into Comet via an API key or your `~./.comet.config`.<jupyter_code>def train_model(train_dataset: ray.data.Dataset, comet_project: str) -> Result:
    """Train a simple XGBoost model and return the result."""
    trainer = XGBoostTrainer(
        scaling_config={"num_workers": 2},
        params={"tree_method": "auto"},
        label_column="target",
        datasets={"train": train_dataset},
        num_boost_round=10,
        run_config=RunConfig(
            callbacks=[
                # This is the part needed to enable logging to Comet ML.
                # It assumes Comet ML can find a valid API (e.g. by setting
                # the ``COMET_API_KEY`` environment variable).
                CometLoggerCallback(
                    project_name=comet_project,
                    save_checkpoints=True,
                )
            ]
        ),
    )
    result = trainer.fit()
    return result<jupyter_output><empty_output><jupyter_text>Let's kick off a run:<jupyter_code>comet_project = "ray_air_example"

train_dataset = get_train_dataset()
result = train_model(train_dataset=train_dataset, comet_project=comet_project)<jupyter_output>2022-05-19 15:19:17,237	INFO services.py:1483 -- View the Ray dashboard at [1m[32mhttp://127.0.0.1:8265[39m[22m
{'fraction_non_alphanumeric': 0.09134973900074571, 'fraction_numerical': 0.015287099179716629, 'mean_word_length': 4.02434456928839, 'pattern_counts': {'":': 3, '<': 20, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, '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': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '108493', 'license': 'Apache-2.0', 'n_tokens_mistral': 865, 'n_tokens_neox': 811, 'n_words': 222, 'path': 'doc/source/ray-air/examples/upload_to_comet_ml.ipynb', 'repo_name': 'orcahmlee/ray', 'size': '2682'}