Last active
January 11, 2019 03:48
-
-
Save merylldindin/4b03e57b74f72daaad55b6d4db4bf98b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.metrics import confusion_matrix | |
def kappa_score(y_true, y_pred): | |
cfm = confusion_matrix(y_true, y_pred) | |
n_c = len(np.unique(y_true)) | |
s_0 = np.sum(cfm, axis=0) | |
s_1 = np.sum(cfm, axis=1) | |
exp = np.outer(s_0, s_1).astype(np.double) / np.sum(s_0) | |
mat = np.ones([n_c, n_c], dtype=np.int) | |
mat.flat[::n_c + 1] = 0 | |
sco = np.sum(mat * cfm) / np.sum(mat * exp) | |
return 1 - sco |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment