mantispy.metrics.variance_carried#
- mantispy.metrics.variance_carried(adata, reference, use_rep='X_pca', groupby='feature_group', n_splits=5)[source]#
How much of a named feature block a learned embedding linearly carries.
A learned embedding has no
varvocabulary, so a hit read off it is only a compound ID. This scores, per named feature, the out-of-fold R^2 of predicting that feature from the embedding with a cross-fit ridge, so a value near 1 means the embedding carries the feature and near 0 means it does not.- Parameters:
- adata
AnnData Object holding the learned embedding in
obsm.- reference
AnnData Object whose
Xholds the named block (e.g. CellProfiler features) to recover.- use_rep
str(default:'X_pca') obsmkey of the embedding used as the predictor.- groupby
str|None(default:'feature_group') reference.varcolumn to average over, one row of the result per group;Nonereturns one row per feature instead.- n_splits
int(default:5) Folds of the cross-fit that produces the out-of-fold predictions.
- adata
- Returns:
columns
["feature", "variance_carried"]whengroupbyisNone, else["<groupby>", "variance_carried", "n_features"]holding the mean over each group.- Return type:
- Raises:
KeyError –
obsmholds nothing underuse_rep.ValueError – The two objects share no
obs_names.ValueError –
adataorreferencehas non-uniqueobs_names.ValueError –
groupbyis notNoneand not a column ofreference.var.
Notes
The two blocks may hold the same wells in different row orders, so the rows are aligned on the shared
obs_namesbefore regressing; matching by position instead returns a near-zero R^2 for an informative block, which reads as a real negative result.