milia.recommend.diagnostics#

Diagnostics for whether entity-level retrieval makes sense.

Functions

variance(frame, group, metrics)

Within-entity variance against overall variance, per metric.

milia.recommend.diagnostics.variance(frame, group, metrics)#

Within-entity variance against overall variance, per metric.

A ratio near 1 means repeated draws for the same entity vary as much as the population does, so the entity carries little information about the outcome (location or chance drives it); a ratio near 0 means the entity largely determines it and retrieval by similarity can work.

Parameters:
  • frame (DataFrame) – One row per draw (e.g. per random PV placement), with an entity column.

  • group (str) – Entity column.

  • metrics (Sequence[str]) – Outcome columns.

Return type:

DataFrame

Returns:

One row per metric with within, overall and ratio.

Examples

>>> import pandas as pd
>>> frame = pd.DataFrame({"id": [1, 1, 2, 2], "risk": [1.0, 1.1, 5.0, 5.1]})
>>> float(variance(frame, "id", ["risk"])["ratio"].round(4).item())
0.0009