fit.evaluation¶
Evaluation of a fit: acceptance criteria and their aggregates.
The functions work on the table of the data points of a fit,
FitMetrics.datapoints_df, i.e. on the columns DV (the measured value),
IPRED (the prediction) and DV_SD (the standard deviation of the measured
value, NaN without one), see sbmlsim.fit.metrics.
The points are evaluated per subset of the data with a Grouping: by the
values of columns of the table, e.g. the tissue or the health of the metadata
of the mappings, or by named subsets of fit mappings, which are selected with
the MappingFilter of sbmlsim.fit.helpers a fit selects its data with.
A criterion decides per data point whether its prediction is acceptable, and it is applicable only to some points: a fold criterion to the points whose value and prediction are positive and finite, which have a ratio, an uncertainty criterion to the points with a standard deviation. A criterion is reported as the percentage of the applicable points it accepts.
GMFE, the geometric mean fold error 10**mean(|log10(f/y)|), is how far the
predictions are from the data as a fold factor whatever the direction, AFE,
the average fold error 10**mean(log10(f/y)), is the bias as a fold factor:
1 for no bias, above 1 for an overprediction.
The criterion of Guest et al. (2011) is defined for ratios, e.g. the ratio of
the AUC of a victim drug with and without a perpetrator, and is the published
one, delta = 1: guest_limits and within_guest. It is not a criterion of
the data points of a fit: applied to an absolute value its limits depend on
the unit of the value (an AUC of 50 in one unit is 0.05 in another).
Guest EJ, Aarons L, Houston JB, Rostami-Hodjegan A, Galetin A. Critique of the two-fold measure of prediction success for ratios: application for the assessment of drug-drug interactions. Drug Metab Dispos. 2011;39(2):170-173. https://doi.org/10.1124/dmd.110.036103
Criterion
¶
Bases: Protocol
A criterion of the acceptance of the prediction of a data point.
accepted
¶
Get whether the criterion accepts the prediction of every point.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points
|
DataFrame
|
the data points, see the module. |
required |
Returns:
| Type | Description |
|---|---|
Series
|
|
Series
|
where the criterion is not applicable, with the index of |
Fold
dataclass
¶
The prediction is within a fold factor of the data, y/fold <= f <= y*fold.
Attributes:
| Name | Type | Description |
|---|---|---|
fold |
float
|
the fold factor, larger than 1. |
Uncertainty
dataclass
¶
The prediction is within k standard deviations of the data.
Attributes:
| Name | Type | Description |
|---|---|---|
k |
float
|
the number of standard deviations. |
Subset
dataclass
¶
A named subset of the fit mappings.
Attributes:
| Name | Type | Description |
|---|---|---|
label |
str
|
the name of the subset. |
select |
MappingFilter
|
the filter of the mappings, called with the key and the fit
mapping, see |
Grouping
dataclass
¶
A grouping of the data points of a fit, by columns or by subsets.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
the name of the grouping, the name of its figures and of its rows in the metrics. |
columns |
tuple[str, ...]
|
the columns of the table of the data points; one group per combination of their values. |
subsets |
tuple[Subset, ...]
|
the subsets of the fit mappings, one group per subset; the subsets may overlap. |
by
classmethod
¶
Get the grouping by the values of columns, named after them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
columns
|
str
|
the columns of the table of the data points, e.g. the fields of the metadata of the mappings. |
()
|
Returns:
| Type | Description |
|---|---|
Grouping
|
The grouping, e.g. |
of_subsets
classmethod
¶
groups
¶
Get the groups of the data points with their labels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points
|
DataFrame
|
the data points with the columns |
required |
fit_mappings
|
MappingLookup
|
the fit mapping of an experiment and a mapping key, which the filter of a subset is called with. |
required |
Returns:
| Type | Description |
|---|---|
list[tuple[str, DataFrame]]
|
The label and the points of every group: by columns in the order |
list[tuple[str, DataFrame]]
|
their values appear, the values joined by |
list[tuple[str, DataFrame]]
|
labelled |
list[tuple[str, DataFrame]]
|
including a subset without points. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if a column of the grouping is not a column of the points. |
gmfe
¶
Get the geometric mean fold error 10**mean(|log10(f/y)|).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points
|
DataFrame
|
the data points, see the module. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The fold error of the points with a ratio, |
afe
¶
Get the average fold error 10**mean(log10(f/y)), the bias as a fold factor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points
|
DataFrame
|
the data points, see the module. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The fold error of the points with a ratio, |
criteria_metrics
¶
Get the fold errors and the percentage of the points every criterion accepts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points
|
DataFrame
|
the data points, see the module. |
required |
criteria
|
Sequence[Criterion]
|
the criteria. |
DEFAULT_CRITERIA
|
Returns:
| Type | Description |
|---|---|
dict[str, float]
|
|
dict[str, float]
|
every criterion accepts by its name, |
dict[str, float]
|
applicable to no point. |
guest_limits
¶
Get the limits of the criterion of Guest et al. for observed ratios.
With the observed ratio R, inverted when it is below 1, the limit is
(1 + 2 (R - 1)) / R (delta = 1, as published) and a predicted ratio
is accepted between R / limit and R * limit. The limit is 1 at
R = 1 and tends to 2 for large ratios. The limits of a ratio below 1
are the inverted limits of its inverse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
observed
|
ArrayLike
|
the observed ratios, positive. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
The lower and the upper limit of the predicted ratio of every |
ndarray
|
observed ratio. |
within_guest
¶
Get the percentage of the predicted ratios within the limits of Guest et al.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
observed
|
ArrayLike
|
the observed ratios, positive and finite. |
required |
predicted
|
ArrayLike
|
the predicted ratios; a ratio which is not finite, e.g. of a failed simulation, is not counted. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The percentage (0 to 100) of the finite predicted ratios within the |
float
|
limits of |
Raises:
| Type | Description |
|---|---|
ValueError
|
if an observed ratio is not positive and finite, or the lengths of the ratios differ. |
group_metrics
¶
Get the metrics of every group and kind of fit mapping.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points
|
DataFrame
|
the data points, see |
required |
grouping
|
Grouping
|
the grouping. |
required |
fit_mappings
|
MappingLookup
|
the fit mapping of an experiment and a mapping key. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
One row per group and kind, the kinds in the order of |
DataFrame
|
|
DataFrame
|
the columns |
DataFrame
|
with a ratio, which the fold criteria count), |
DataFrame
|
a standard deviation, which the SD criteria count), |
DataFrame
|
metrics of |
DataFrame
|
units of its observables; the NRMSE is scale free. |
subset_agreement
¶
Get the agreement of a subset of the data points with its confidence.
The bias mean(log10(f/y)) and the half width 1.96 SD of the limits of
agreement of the points with a ratio, and the half widths of the 95%
confidence intervals of the bias, t SD / sqrt(n), and of a limit,
t sqrt(3 SD^2 / n) (Bland and Altman 1999), with t the 97.5% quantile
of the t distribution of n - 1 degrees of freedom: with few points a
limit is uncertain, and the interval says how much.
Bland JM, Altman DG. Measuring agreement in method comparison studies. Stat Methods Med Res. 1999;8(2):135-160.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points
|
DataFrame
|
the data points, see the module. |
required |
Returns:
| Type | Description |
|---|---|
tuple[float, float, float, float] | None
|
The bias, the half width of the limits and the half widths of the |
tuple[float, float, float, float] | None
|
intervals of the bias and of a limit, in decades; |
tuple[float, float, float, float] | None
|
than |