A version of the training table evaluated in an ablation.
AblationVariant(
id,
strategy,
name,
steps=(),
n_removed=0,
f_removed=0.0,
is_control=False,
group=None,
group_column=None,
left_out=None,
sweep=None,
value=None,
corruption=None,
column=None,
n_corrupted=0,
checked_by=None,
)
An Ablation evaluates a model on several versions of the target table of a validation: the full table, the table with the rows that failed some of the steps removed (a variant), and the table with the same number of rows removed at random (a control). Each time it calls the evaluate= function, it passes the version being evaluated as the variant= argument, so the function can tell them apart (e.g., to log the runs, or to name the files that a model is saved to). The variants of an ablation are also listed in its plan() and its results.
Attributes
id: str
-
A short identifier for the version, unique within the ablation: "full" for the full table, "step_<i>" for a variant of drop_each(), "all" for drop_all(), the name= (or "steps_<i>_<j>") for drop_steps(), "all_but_<i>" for drop_all_but_each(), "<column>=<value>" for drop_groups(), "<score>:lowest_<q>" (or "<score>:below_<value>", and the same with highest and above) for sweep_score(), where <score> is step_<i> or the score column, "step_<i>:<param>=<value>" for sweep_step(), "inject:<corruption>:<column>_<rate>" (or "inject:duplicate_<rate>") for inject(), "shapley_<i>_<j>" for a group of steps that only shapley() needs, and "control_<n>" for the control that removes n random rows (or "control_<id>" for the control of a drop_all_but_each() variant).
strategy: str
-
The kind of version: "full", "drop_steps", "drop_each", "drop_all", "drop_all_but_each", "drop_groups", "sweep_score", "sweep_step", "inject", "shapley", or "control".
name: str
-
A name for the version, as shown in reports (e.g., "Step 2").
steps: tuple[int, …]
-
The numbers of the validation steps whose failing rows were removed (empty for the full table, for groups, for the points of a sweep, for injected defects, and for most controls).
n_removed: int
-
The number of rows removed from the table.
f_removed: float
-
The share of the table’s rows that were removed (from 0 to 1).
is_control: bool
-
Is this a control (random rows removed) rather than a variant?
group: Any
-
For a variant of drop_groups(), the value of group_column in the rows it removes (None for the rows where it’s missing).
group_column: str | None
-
For a variant of drop_groups(), the column the rows are grouped by (otherwise None).
left_out: int | None
-
For a variant of drop_all_but_each() (and its control), the step whose rows are kept (otherwise None).
sweep: str | None
-
For a point of a sweep (from sweep_score() or sweep_step()), the id of the sweep, which its points share (e.g., "step_2:lowest" or "step_2:min_val"; otherwise None).
value: float | None
-
For a point of a sweep, its value: the share of the scored rows removed, the score threshold, or the value of the step’s parameter. For a variant of inject(), the share of the rows corrupted (otherwise None).
corruption: str | None
-
For a variant of inject(), the defect put into the rows: "null", "shuffle", "truncate", "duplicate", or the name of the corruption function (otherwise None).
column: str | None
-
For a variant of inject(), the column whose values were corrupted (None for "duplicate", and otherwise).
n_corrupted: int
-
For a variant of inject(), the number of rows corrupted (or copied, for "duplicate").
checked_by: int | None
-
For a variant of inject(), the step that checks for the defect, given as its
step= (otherwise None).
Examples
Here’s a table of temperature readings, some of them recorded in tenths of a degree (so they’re ten times too high). The evaluate() function takes the variant= argument and keeps a log of each call, as a real function might do to name the files that its models are saved to.
import pointblank as pb
import polars as pl
temps = [20 + (k * 37 % 11 - 5) * 0.6 for k in range(300)]
for k in range(0, 300, 25):
temps[k] *= 10
readings = pl.DataFrame({"temp": temps})
calls = []
def evaluate(train, *, seed, variant):
calls.append(
{
"id": variant.id,
"strategy": variant.strategy,
"n_removed": variant.n_removed,
"is_control": variant.is_control,
"seed": seed,
"n_rows": train.height,
}
)
sample = train.sample(fraction=1.0, with_replacement=True, seed=seed)
return abs(sample["temp"].mean() - 20)
validation = (
pb.Validate(data=readings)
.col_vals_between(columns="temp", left=-10, right=45)
.interrogate()
)
ablation = pb.Ablation(
validation, evaluate=evaluate, metric="error", higher_is_better=False, repeats=3
).drop_each()
ablation.run()
pl.DataFrame(calls)
shape: (9, 6)| id | strategy | n_removed | is_control | seed | n_rows |
|---|
| str | str | i64 | bool | i64 | i64 |
| "full" | "full" | 0 | false | 0 | 300 |
| "full" | "full" | 0 | false | 1 | 300 |
| "full" | "full" | 0 | false | 2 | 300 |
| "step_1" | "drop_each" | 12 | false | 0 | 288 |
| "step_1" | "drop_each" | 12 | false | 1 | 288 |
| "step_1" | "drop_each" | 12 | false | 2 | 288 |
| "control_12" | "control" | 12 | true | 0 | 288 |
| "control_12" | "control" | 12 | true | 1 | 288 |
| "control_12" | "control" | 12 | true | 2 | 288 |
The function was called three times (once for each repeat, with the seeds 0, 1, and 2) for each of the three versions of the table: the full table ("full"), the variant of drop_each() that removes the 12 rows failing step 1 ("step_1"), and its control, which removes 12 random rows ("control_12"). The variant and its control both train on 288 rows, so the training table alone can’t tell them apart, but variant= can. The variant always removes the same rows, while the control draws a new set of random rows for each repeat.
See Also
- Ablation
-
Measure how the rows that fail validation steps affect a model trained on the data.