> ## Documentation Index
> Fetch the complete documentation index at: https://arize-ax.mintlify.site/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Log experiment

> Log experiment results to Arize AX from remote pipelines

Some teams have complex experiment pipelines and might need to run experiments remotely. Teams can still log those experiment results to Arize AX via  [`log_experiment`](/api-clients/python/version-8/client-resources/experiments#create-an-experiment) to maintain a record of experiments for tracking and comparing.

# Steps to log an experiment

## 1. Store the experiment results in a dataframe

We will be logging an example experiment with three columns:

* `result` is the output of the LLM pipeline.
* `correctness` is the evaluation label of the experiment.
* `example_id` is the dataset row ID, which is needed to map the results to the specific dataset row with inputs and expected outputs.

```python theme={null}
# Example DataFrame:
experiment_run_df = pd.DataFrame(
    {
        "result": [
            "The telephone was invented by **Alexander Graham Bell**.",
            "The invention of the light bulb is commonly attributed to **Thomas Edison**"
        ],
        "label": ["correct", "incorrect"],
        "score": [1, 0],
        "explanation_text": [
            "This statement is accurate because Alexander Graham Bell is credited with inventing the telephone.",
            "This statement is inaccurate; others like Humphry Davy and Joseph Swan made earlier versions of the light bulb.",
        ],
    }
)
```

## 2. Define column mappings

This code sets up mappings that link each dataset example to `example_id`, the LLM output to `result`, and evaluator outputs to `label`, `score`, and `explanation`.

<CodeGroup>
  ```python Python SDK v8 theme={null}
  from arize.experiments import (
      ExperimentTaskFieldNames,
      EvaluationResultFieldNames,
  )

  # Define field mappings for the LLM task id and example output
  task_fields = ExperimentTaskFieldNames(
      example_id="example_id", output="result"
  )

  # Define field mappings for evaluator
  evaluator_fields = EvaluationResultFieldNames(
      label="label",
      score="score",
      explanation="explanation_text",
  )

  # This maps the dataset ID to the example_id
  dataset_examples = client.datasets.list_examples(dataset_id=dataset_id, all=True)
  dataset_df = dataset_examples.to_df()
  experiment_run_df["example_id"] = dataset_df["id"]
  ```

  ```python Python SDK v7 theme={null}
  from arize.experimental.datasets.experiments.types import (
      ExperimentTaskResultColumnNames,
      EvaluationResultColumnNames,
  )

  # Define column mappings for the LLM task id and example output
  task_cols = ExperimentTaskResultColumnNames(
      example_id="example_id", result="result"
  )

  # Define column mappings for evaluator
  evaluator_cols = EvaluationResultColumnNames(
      label="label",
      score="score",
      explanation="explanation_text",
  )

  # Get dataset and map the dataset ID to the example_id
  dataset = arize_client.get_dataset(space_id="your-arize-space-id", dataset_id=dataset_id)
  experiment_run_df["example_id"] = dataset["id"]
  ```
</CodeGroup>

## 3. Log the experiment&#x20;

Log the experiment to Arize AX using the columns and label for correctness.

<CodeGroup>
  ```python Python SDK v8 theme={null}
  from arize import ArizeClient

  client = ArizeClient(api_key="your-arize-api-key")

  experiment = client.experiments.create(
      name="my_experiment",
      dataset_id=dataset_id,
      experiment_runs=experiment_run_df,
      task_fields=task_fields,
      evaluator_columns={"correctness": evaluator_fields},
  )
  ```

  ```python Python SDK v7 theme={null}
  from arize.experimental.datasets import ArizeDatasetsClient

  arize_client = ArizeDatasetsClient(api_key="your-arize-api-key")

  arize_client.log_experiment(
      space_id="your-arize-space-id",
      experiment_name="my_experiment",
      experiment_df=experiment_run_df,
      task_columns=task_cols,
      evaluator_columns={"correctness": evaluator_cols},
      dataset_name="inventions-dataset",
  )
  ```
</CodeGroup>
