diff --git a/doc/whats_new.rst b/doc/whats_new.rst index 7a93e8feee74a..d110b509d6c79 100644 --- a/doc/whats_new.rst +++ b/doc/whats_new.rst @@ -144,6 +144,9 @@ Enhancements - Added ability to use sparse matrices in :func:`feature_selection.f_regression` with ``center=True``. :issue:`8065` by :user:`Daniel LeJeune `. + - Add ``sample_weight`` parameter to :func:`metrics.cohen_kappa_score` by + Victor Poughon. + Bug fixes ......... diff --git a/sklearn/metrics/classification.py b/sklearn/metrics/classification.py index 9dd87e89ec474..798d4ae124414 100644 --- a/sklearn/metrics/classification.py +++ b/sklearn/metrics/classification.py @@ -275,7 +275,7 @@ def confusion_matrix(y_true, y_pred, labels=None, sample_weight=None): return CM -def cohen_kappa_score(y1, y2, labels=None, weights=None): +def cohen_kappa_score(y1, y2, labels=None, weights=None, sample_weight=None): """Cohen's kappa: a statistic that measures inter-annotator agreement. This function computes Cohen's kappa [1]_, a score that expresses the level @@ -311,6 +311,9 @@ class labels [2]_. List of weighting type to calculate the score. None means no weighted; "linear" means linear weighted; "quadratic" means quadratic weighted. + sample_weight : array-like of shape = [n_samples], optional + Sample weights. + Returns ------- kappa : float @@ -328,7 +331,8 @@ class labels [2]_. .. [3] `Wikipedia entry for the Cohen's kappa. `_ """ - confusion = confusion_matrix(y1, y2, labels=labels) + confusion = confusion_matrix(y1, y2, labels=labels, + sample_weight=sample_weight) n_classes = confusion.shape[0] sum0 = np.sum(confusion, axis=0) sum1 = np.sum(confusion, axis=1) diff --git a/sklearn/metrics/tests/test_common.py b/sklearn/metrics/tests/test_common.py index 97dd4a4e684d2..a91fc57c74a77 100644 --- a/sklearn/metrics/tests/test_common.py +++ b/sklearn/metrics/tests/test_common.py @@ -369,7 +369,6 @@ # No Sample weight support METRICS_WITHOUT_SAMPLE_WEIGHT = [ - "cohen_kappa_score", "confusion_matrix", # Left this one here because the tests in this file do # not work for confusion_matrix, as its output is a # matrix instead of a number. Testing of