10000 Add sample_weight parameter to cohen_kappa_score (#8335) · lemonlaug/scikit-learn@bc9b796 · GitHub
[go: up one dir, main page]

Skip to content

Commit bc9b796

Browse files
vpoughonIsaac Laughlin
authored andcommitted
Add sample_weight parameter to cohen_kappa_score (scikit-learn#8335)
1 parent 87e2f4a commit bc9b796

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

doc/whats_new.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ Enhancements
144144
- Added ability to use sparse matrices in :func:`feature_selection.f_regression`
145145
with ``center=True``. :issue:`8065` by :user:`Daniel LeJeune <acadiansith>`.
146146

147+
- Add ``sample_weight`` parameter to :func:`metrics.cohen_kappa_score` by
148+
Victor Poughon.
149+
147150
Bug fixes
148151
.........
149152

sklearn/metrics/classification.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ def confusion_matrix(y_true, y_pred, labels=None, sample_weight=None):
275275
return CM
276276

277277

278-
def cohen_kappa_score(y1, y2, labels=None, weights=None):
278+
def cohen_kappa_score(y1, y2, labels=None, weights=None, sample_weight=None):
279279
"""Cohen's kappa: a statistic that measures inter-annotator agreement.
280280
281281
This function computes Cohen's kappa [1]_, a score that expresses the level
@@ -311,6 +311,9 @@ class labels [2]_.
311311
List of weighting type to calculate the score. None means no weighted;
312312
"linear" means linear weighted; "quadratic" means quadratic weighted.
313313
314+
sample_weight : array-like of shape = [n_samples], optional
315+
Sample weights.
316+
314317
Returns
315318
-------
316319
kappa : float
@@ -328,7 +331,8 @@ class labels [2]_.
328331
.. [3] `Wikipedia entry for the Cohen's kappa.
329332
<https://en.wikipedia.org/wiki/Cohen%27s_kappa>`_
330333
"""
331-
confusion = confusion_matrix(y1, y2, labels=labels)
334+
confusion = confusion_matrix(y1, y2, labels=labels,
335+
sample_weight=sample_weight)
332336
n_classes = confusion.shape[0]
333337
sum0 = np.sum(confusion, axis=0)
334338
sum1 = np.sum(confusion, axis=1)

sklearn/metrics/tests/test_common.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,6 @@
369369

370370
# No Sample weight support
371371
METRICS_WITHOUT_SAMPLE_WEIGHT = [
372-
"cohen_kappa_score",
373372
"confusion_matrix", # Left this one here because the tests in this file do
374373
# not work for confusion_matrix, as its output is a
375374
# matrix instead of a number. Testing of

0 commit comments

Comments
 (0)
0