Skip to content

scdecon.validation

validation

Validation: accuracy metrics for deconvolution against known proportions.

A pure computation layer (NumPy / pandas / scipy.stats) operating on proportion DataFrame objects oriented as cell types x samples. It imports no I/O or plotting.

ValidationReport dataclass

ValidationReport(overall_rmse: float, per_type: DataFrame)

Typed, lightweight result of a validation run.

Attributes:

Name Type Description
overall_rmse float

Root-mean-square error across all cell-type x sample entries.

per_type DataFrame

One row per cell type (index), with columns rmse, pearson, spearman (the last two computed across samples; nan when a correlation is undefined).

mean_pearson property

mean_pearson: float

nan-aware mean of the per-cell-type Pearson correlations.

mean_spearman property

mean_spearman: float

nan-aware mean of the per-cell-type Spearman correlations.

to_frame

to_frame() -> pd.DataFrame

Return the per-cell-type metric table (a copy), for serialisation.

render

render() -> str

Return a one-line human-readable summary.

align_proportions

align_proportions(truth: DataFrame, prediction: DataFrame) -> tuple[pd.DataFrame, pd.DataFrame]

Check that truth and prediction describe the same data and align them.

Both must be cell types (index) x samples (columns) with identical cell-type and sample label sets (order-independent). The prediction is reindexed to the truth's cell-type and sample order.

Parameters:

Name Type Description Default
truth DataFrame

Ground-truth proportions (cell types x samples).

required
prediction DataFrame

Estimated proportions (cell types x samples).

required

Returns:

Type Description
tuple[DataFrame, DataFrame]

(truth, aligned_prediction) with matching index and columns.

Raises:

Type Description
ValueError

If either frame is empty, has duplicate cell-type or sample labels, or the cell-type / sample label sets differ.

evaluate

evaluate(truth: DataFrame, prediction: DataFrame) -> ValidationReport

Score estimated proportions against ground truth.

Parameters:

Name Type Description Default
truth DataFrame

Ground-truth proportions, cell types (index) x samples (columns).

required
prediction DataFrame

Estimated proportions, same orientation and labels as truth.

required

Returns:

Type Description
ValidationReport

Overall RMSE and per-cell-type RMSE / Pearson / Spearman.

Raises:

Type Description
ValueError

If the inputs cannot be aligned (see :func:align_proportions).