sklearn.metrics.cluster
.contingency_matrix¶
-
sklearn.metrics.cluster.
contingency_matrix
(labels_true, labels_pred, eps=None, sparse=False)[source]¶ Build a contingency matrix describing the relationship between labels.
- Parameters
- labels_trueint array, shape = [n_samples]
Ground truth class labels to be used as a reference
- labels_predarray-like of shape (n_samples,)
Cluster labels to evaluate
- epsNone or float, optional.
If a float, that value is added to all values in the contingency matrix. This helps to stop NaN propagation. If
None
, nothing is adjusted.- sparseboolean, optional.
If True, return a sparse CSR continency matrix. If
eps is not None
, andsparse is True
, will throw ValueError.New in version 0.18.
- Returns
- contingency{array-like, sparse}, shape=[n_classes_true, n_classes_pred]
Matrix \(C\) such that \(C_{i, j}\) is the number of samples in true class \(i\) and in predicted class \(j\). If
eps is None
, the dtype of this array will be integer. Ifeps
is given, the dtype will be float. Will be ascipy.sparse.csr_matrix
ifsparse=True
.