HammingDistance
Fraction of labels that are incorrectly predicted (Hamming loss).
The Hamming distance (or Hamming loss) is the fraction of the total
predictions that are wrong. For single-label classification it equals
1 - accuracy; for multi-label classification it counts per-label
mismatches independently, making it especially useful when each sample
can belong to multiple classes simultaneously.
A lower Hamming distance indicates better performance. MAXIMIZE = False
so the DashAI framework treats smaller values as improvements.
::
Hamming Loss = (1/N) · Σᵢ 𝟙[ŷᵢ ≠ yᵢ]
Range: [0, 1], lower is better (MAXIMIZE = False).
References
- [1] Hamming, R.W. (1950). "Error detecting and error correcting codes." Bell System Technical Journal, 29(2), 147-160.
- [2] https://scikit-learn.org/stable/modules/generated/sklearn.metrics.hamming_loss.html
Methods
score(true_labels: 'DashAIDataset', probs_pred_labels: 'np.ndarray', multiclass: Optional[bool] = None) -> float
HammingDistanceCalculate Hamming Distance between true labels and predicted labels.
Parameters
- true_labels : DashAIDataset
- A DashAI dataset with labels.
- probs_pred_labels : np.ndarray
- A two-dimensional matrix in which each column represents a class and the row values represent the probability that an example belongs to the class associated with the column.
- multiclass : bool, optional
- Whether the task is a multiclass classification. If None, it will be determined automatically from the number of unique labels.
Returns
- float
- Hamming Distance between true labels and predicted labels
get_metadata(cls: 'BaseMetric') -> Dict[str, Any]
BaseMetricGet metadata values for the current metric.
Returns
- Dict[str, Any]
- Dictionary with the metadata
is_multiclass(true_labels: 'np.ndarray') -> bool
ClassificationMetricDetermine if the classification problem is multiclass (more than 2 classes).
Parameters
- true_labels : np.ndarray
- Array of true labels.
Returns
- bool
- True if the problem has more than 2 unique classes, False otherwise.
Compatible with
TabularClassificationTaskImageClassificationTaskTextClassificationTask