scxpand.core.inference_results#

Inference results data structure for scXpand models.

This module defines the InferenceResults dataclass that provides a structured way to return inference results instead of using dictionaries.

Classes

InferenceResults(predictions[, metrics, ...])

Structured results from scXpand model inference.

ModelInfo([model_name, model_type, version, ...])

Model metadata information.

class scxpand.core.inference_results.InferenceResults(predictions, metrics=None, model_info=None)#

Structured results from scXpand model inference.

This dataclass provides a clean, typed interface for accessing inference results instead of using dictionaries. It automatically handles cases where ground truth labels are not available (metrics will be None).

Variables:
  • predictions – Array of prediction probabilities [0, 1] for each cell

  • metrics – Dictionary containing evaluation metrics (None if ground truth unavailable)

  • model_info – Model metadata information (None for local models)

Examples

>>> results = scxpand.run_inference(
...     data_path="data.h5ad", model_path="model/"
... )
>>> print(f"Generated {len(results.predictions)} predictions")
>>> if results.metrics:
...     print(f"AUROC: {results.metrics['AUROC']:.3f}")
>>> if results.model_info:
...     print(f"Model type: {results.model_info.model_type}")
__init__(predictions, metrics=None, model_info=None)#
get_auroc()#

Get the overall AUROC score if available.

Return type:

float | None

get_harmonic_avg_auroc()#

Get the harmonic average AUROC across strata if available.

Return type:

float | None

to_dict()#

Convert to dictionary format for backward compatibility.

Return type:

dict[str, Any]

property has_metrics: bool#

Whether evaluation metrics are available.

property has_model_info: bool#

Whether model metadata is available.

metrics: dict[str, Any] | None = None#
model_info: ModelInfo | None = None#
property n_predictions: int#

Number of predictions generated.

predictions: ndarray#
class scxpand.core.inference_results.ModelInfo(model_name=None, model_type=None, version=None, source=None, url=None)#

Model metadata information.

Variables:
  • model_name – Name of the model (for registry models)

  • model_type – Type of model (e.g., “mlp”, “autoencoder”)

  • version – Model version (for registry models)

  • source – Source of the model (“local”, “registry”, “external_url”)

  • url – URL for external models

__init__(model_name=None, model_type=None, version=None, source=None, url=None)#
model_name: str | None = None#
model_type: str | None = None#
source: str | None = None#
url: str | None = None#
version: str | None = None#