tf.contrib.metrics.cohen_kappa(
labels,
predictions_idx,
num_classes,
weights=None,
metrics_collections=None,
updates_collections=None,
name=None
)
Defined in tensorflow/contrib/metrics/python/ops/metric_ops.py.
Calculates Cohen's kappa.
Cohen's kappa is a statistic that measures inter-annotator agreement.
The cohen_kappa function calculates the confusion matrix, and creates three
local variables to compute the Cohen's kappa: po, pe_row, and pe_col,
which refer to the diagonal part, rows and columns totals of the confusion
matrix, respectively. This value is ultimately returned as kappa, an
idempotent operation that is calculated by
pe = (pe_row * pe_col) / N
k = (sum(po) - sum(pe)) / (N - sum(pe))
For estimation of the metric over a stream of data, the function creates an
update_op operation that updates these variables and returns the
kappa. update_op weights each prediction by the corresponding value in
weights.
Class labels are expected to start at 0. E.g., if num_classes
was three, then the possible labels would be [0, 1, 2].
If weights is None, weights default to 1. Use weights of 0 to mask values.
NOTE: Equivalent to sklearn.metrics.cohen_kappa_score, but the method
doesn't support weighted matrix yet.
Args:
labels: 1-DTensorof real labels for the classification task. Must be one of the following types: int16, int32, int64.predictions_idx: 1-DTensorof predicted class indices for a given classification. Must have the same type aslabels.num_classes: The possible number of labels.weights: OptionalTensorwhose shape matchespredictions.metrics_collections: An optional list of collections thatkappashould be added to.updates_collections: An optional list of collections thatupdate_opshould be added to.name: An optional variable_scope name.
Returns:
kappa: Scalar floatTensorrepresenting the current Cohen's kappa.update_op:Operationthat incrementspo,pe_rowandpe_colvariables appropriately and whose value matcheskappa.
Raises:
ValueError: Ifnum_classesis less than 2, orpredictionsandlabelshave mismatched shapes, or ifweightsis notNoneand its shape doesn't matchpredictions, or if eithermetrics_collectionsorupdates_collectionsare not a list or tuple.RuntimeError: If eager execution is enabled.