Garfield.model.utils.weighted_knn_transfer
- Garfield.model.utils.weighted_knn_transfer(query_adata, query_adata_emb, ref_adata_obs, label_keys, knn_model, threshold=1, pred_unknown=False, mode='package')[source]
Annotates
query_adatacells with an input trained weighted KNN classifier.- Parameters:
query_adata (
AnnData) – Annotated dataset to be used to queryate KNN classifier. Embedding to be usedquery_adata_emb (str) – Name of the obsm layer to be used for label transfer. If set to “X”, query_adata.X will be used
ref_adata_obs (
pd.DataFrame) – obs of ref Anndatalabel_keys (str) – Names of the columns to be used as target variables (e.g. cell_type) in
query_adata.knn_model (
KNeighborsTransformer) – knn model trained on reference adata with weighted_knn_trainer functionthreshold (float) – Threshold of uncertainty used to annotating cells as “Unknown”. cells with uncertainties higher than this value will be annotated as “Unknown”. Set to 1 to keep all predictions. This enables one to later on play with thresholds.
pred_unknown (bool) –
Falseby default. Whether to annotate any cell as “unknown” or not. If False,thresholdwill not be used and each cell will be annotated with the label which is the most common in itsn_neighborsnearest cells.mode (str) – Has to be one of “paper” or “package”. If mode is set to “package”, uncertainties will be 1 - P(pred_label), otherwise it will be 1 - P(true_label).