The model evaluations Python API provides a set of methods for creating evaluations and logging metrics, images, plots, and tables to them.
palantir_models.transforms.evaluationThe palantir_models.transforms.evaluation decorator creates an evaluation. Apply it to wrap a transform and indicate the evaluation set written to on the model inputs:
Copied!1 2 3 4 5 6 7 8 9 10 11 12 13from transforms.api import configure, transform, Input import palantir_models as pm from palantir_models.transforms import ModelInput # This decorator is required to be applied to create evaluations. # The decorator indicates the evaluation set that will be written to on the model input(s). @pm.transforms.evaluation("error_analysis") @transform.using( input_data=Input("..."), model_input=ModelInput("..."), ) def compute(input_data, model_input): evaluation = model_input.create_evaluation(name="my-evaluation")
In the above example, the evaluation will be written to the error_analysis evaluation set on the model_input model. If the evaluation set does not yet exist, it is created automatically the first time the transform runs.
evaluation_set_name: str
ModelInput.create_evaluationpalantir_models.transforms.ModelInput.create_evaluation(name: Optional[str] = None) -> Evaluation
Evaluation for the model loaded by this ModelInput.@pm.transforms.evaluation.create_evaluation more than once in the same transform returns the same evaluation instance.Copied!1evaluation = model_input.create_evaluation(name="my-evaluation")
name: Optional[str]
palantir_models.evaluations.EvaluationA class for logging the results of a model evaluation. An Evaluation is created from a ModelInput using create_evaluation and captures how a single model version performs against a set of test data.
Unlike an experiment, an evaluation records a single snapshot of results rather than a stepped time series, so its logging methods do not accept a step argument.
| Function | Description |
|---|---|
log_metric(key, value) | Log a single metric to the evaluation. |
log_metrics(metrics) | Log a set of metrics to the evaluation. |
log_image(name, image, caption) | Log an image to the evaluation. |
log_plot(name, plot_data, description) | Log a plot to the evaluation. |
log_table(name, table, description) | Log a table to the evaluation. |
The evaluation_rid property returns the resource identifier (RID) of the evaluation.
Evaluation.log_metricpalantir_models.evaluations.Evaluation.log_metric(key: str, value: Union[int, float])
value under the given key.int or float).Copied!1evaluation.log_metric("mae", 14250.0)
key: str
value: Union[int, float]
Evaluation.log_metricspalantir_models.evaluations.Evaluation.log_metrics(metrics: Dict[str, Union[int, float]])
log_metric.int or float).Copied!1 2 3 4evaluation.log_metrics({ "mae": 14250.0, "r2": 0.91, })
metrics: Dict[str, Union[int, float]]
Evaluation.log_imagepalantir_models.evaluations.Evaluation.log_image(name: str, image: Union[str, bytes, "PIL.Image.Image"], caption: Optional[str] = None)
Copied!1 2 3 4 5 6evaluation.log_image("residual_distribution", pillow_image) evaluation.log_image( "error_heatmap", "path/to/image.png", caption="Geographic error heatmap", )
name: str
image: Union[str, bytes, "PIL.Image.Image"]
caption: Optional[str]
Evaluation.log_plotpalantir_models.evaluations.Evaluation.log_plot(name: str, plot_data: "plotly.graph_objects.Figure", description: Optional[str] = None)
plotly.graph_objects.Figure. Other plot types are rejected.Copied!1 2 3 4 5 6 7 8import plotly.express as px fig = px.box(df, x="price_tier", y="residual", title="Residuals by price tier") evaluation.log_plot( "residuals_by_tier", fig, description="Residual distribution across all price tiers", )
name: str
plot_data: "plotly.graph_objects.Figure"
description: Optional[str]
Evaluation.log_tablepalantir_models.evaluations.Evaluation.log_table(name: str, table: Union["polars.DataFrame", "pandas.DataFrame"], description: Optional[str] = None)
Copied!1 2 3 4 5 6 7 8 9import pandas as pd error_by_tier = pd.DataFrame({ "price_tier": ["affordable", "mid_range", "luxury"], "mae": [8200.0, 15400.0, 42300.0], "r2": [0.94, 0.91, 0.87], }) evaluation.log_table("error_by_price_tier", error_by_tier)
name: str
table: Union["polars.DataFrame", "pandas.DataFrame"]
description: Optional[str]