From 280541fce7382860cd7bd9bfac004cf62654ccad Mon Sep 17 00:00:00 2001 From: Victor Poughon Date: Tue, 4 Oct 2016 09:55:01 +0200 Subject: [PATCH 1/3] Add sample_weight parameter to cohen_kappa_score --- doc/whats_new.rst | 3 +++ sklearn/metrics/classification.py | 9 +++++++-- sklearn/metrics/tests/test_common.py | 1 - 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/doc/whats_new.rst b/doc/whats_new.rst index 857967bfdc1cd..4d43ca34737ca 100644 --- a/doc/whats_new.rst +++ b/doc/whats_new.rst @@ -31,6 +31,9 @@ Enhancements `_) by `Andrea Esuli`_. + - Add ``sample_weight`` parameter to `metrics.cohen_kappa_score`. By Victor + Poughon. + Bug fixes ......... diff --git a/sklearn/metrics/classification.py b/sklearn/metrics/classification.py index 60cdacea976f5..872ce12424b76 100644 --- a/sklearn/metrics/classification.py +++ b/sklearn/metrics/classification.py @@ -18,6 +18,7 @@ # Jatin Shah # Saurabh Jha # Bernardo Stein +# Victor Poughon # License: BSD 3 clause from __future__ import division @@ -275,7 +276,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 +312,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 +332,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 fa4c7e8d3124b..1cf95120301f5 100644 --- a/sklearn/metrics/tests/test_common.py +++ b/sklearn/metrics/tests/test_common.py @@ -368,7 +368,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 From e54f47abf55461db0725b5dbd389dd9587627be1 Mon Sep 17 00:00:00 2001 From: Victor Poughon Date: Tue, 8 Nov 2016 14:31:33 +0100 Subject: [PATCH 2/3] Fix formatting issue from PR#7569 review --- doc/whats_new.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/whats_new.rst b/doc/whats_new.rst index 4d43ca34737ca..1e795589cd096 100644 --- a/doc/whats_new.rst +++ b/doc/whats_new.rst @@ -31,8 +31,8 @@ Enhancements `_) by `Andrea Esuli`_. - - Add ``sample_weight`` parameter to `metrics.cohen_kappa_score`. By Victor - Poughon. + - Add ``sample_weight`` parameter to :func:`metrics.cohen_kappa_score` by + Victor Poughon. Bug fixes ......... From 97c5aa088a77c1b696c9d276f9efbb604621619f Mon Sep 17 00:00:00 2001 From: Victor Poughon Date: Tue, 7 Feb 2017 14:38:53 +0100 Subject: [PATCH 3/3] Remove superfluous author list mention (#7569) --- sklearn/metrics/classification.py | 1 - 1 file changed, 1 deletion(-) diff --git a/sklearn/metrics/classification.py b/sklearn/metrics/classification.py index 872ce12424b76..b41443d1292a9 100644 --- a/sklearn/metrics/classification.py +++ b/sklearn/metrics/classification.py @@ -18,7 +18,6 @@ # Jatin Shah # Saurabh Jha # Bernardo Stein -# Victor Poughon # License: BSD 3 clause from __future__ import division