def fleiss_kappa(table):
 table = (1.0 * np.asarray(table))
 (n_sub, n_cat) = table.shape
 n_total = table.sum()
 n_rater = table.sum(1)
 n_rat = n_rater.max()
 assert (n_total == (n_sub * n_rat))
 p_cat = (table.sum(0) / n_total)
 table2 = (table * table)
 p_rat = ((table2.sum(1) - n_rat) / (n_rat * (n_rat - 1.0)))
 p_mean = p_rat.mean()
 p_mean_exp = (p_cat * p_cat).sum()
 kappa = ((p_mean - p_mean_exp) / (1 - p_mean_exp))
 return kappa

def fleiss_kappa ( table ) : table = ( 1.0 * np . asarray ( table ) ) ( n_sub , n_cat ) = table . shape n_total = table . sum ( ) n_rater = table . sum ( 1 ) n_rat = n_rater . max ( ) assert ( n_total == ( n_sub * n_rat ) ) p_cat = ( table . sum ( 0 ) / n_total ) table2 = ( table * table ) p_rat = ( ( table2 . sum ( 1 ) - n_rat ) / ( n_rat * ( n_rat - 1.0 ) ) ) p_mean = p_rat . mean ( ) p_mean_exp = ( p_cat * p_cat ) . sum ( ) kappa = ( ( p_mean - p_mean_exp ) / ( 1 - p_mean_exp ) ) return kappa
returns the reliability of agreement as a number between -1 .