Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/whats_new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <acadiansith>`.

- Add ``sample_weight`` parameter to :func:`metrics.cohen_kappa_score` by
Victor Poughon.

Bug fixes
.........

Expand Down
8 changes: 6 additions & 2 deletions sklearn/metrics/classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -328,7 +331,8 @@ class labels [2]_.
.. [3] `Wikipedia entry for the Cohen's kappa.
<https://en.wikipedia.org/wiki/Cohen%27s_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)
Expand Down
1 change: 0 additions & 1 deletion sklearn/metrics/tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down