spared.metrics.get_metrics
- spared.metrics.get_metrics(gt_mat: Union[array, Tensor], pred_mat: Union[array, Tensor], mask: Union[array, Tensor], detailed: bool = False) dict[source]
Get general regression metrics
This function receives 2 matrices of shapes (n_samples, n_genes) and computes the following metrics:
Pearson correlation (gene-wise) [PCC-Gene]
Pearson correlation (patch-wise) [PCC-Patch]
r2 score (gene-wise) [R2-Gene]
r2 score (patch-wise) [R2-Patch]
Mean squared error [MSE]
Mean absolute error [MAE]
Global metric [Global] (Global = PCC-Gene + R2-Gene + PCC-Patch + R2-Patch - MAE - MSE)
If detailed == True. Then the function returns these aditional keys (all of them are numpy arrays):
Individual pearson correlation for every gene [PPC-Gene-detailed]
Individual pearson correlation for every patch [PPC-Patch-detailed]
Individual r2 score for every gene [R2-Gene-detailed]
Individual r2 score for every patch [R2-Gene-detailed]
Individual MSE for every gene [detailed_mse_gene]
Individual MAE for every gene [detailed_mae_gene]
Individual average error for every gene [detailed_error_gene]
Flat concatenation of all errors in valid positions [detailed_errors]
- Parameters:
gt_mat (Union[np.array, torch.Tensor]) – Ground truth matrix of shape (n_samples, n_genes).
pred_mat (Union[np.array, torch.Tensor]) – Predicted matrix of shape (n_samples, n_genes).
mask (Union[np.array, torch.Tensor]) – Boolean mask with False in positions that must be ignored in metric computation (n_samples, n_genes).
detailed (bool) – If True, the dictionary also includes the detailed metrics.
- Returns:
Dictionary containing the metrics computed. The keys are: [‘PCC-Gene’, ‘PCC-Patch’, ‘R2-Gene’, ‘R2-Patch’, ‘MSE’, ‘MAE’, ‘Global’]
- Return type:
dict