code: def class_agreement(df):
      """
      Inspired from R package e1071 matchClassed.R classAgreement
      """
      n = df.sum().sum()
      nj = df.sum(axis=0)
      ni = df.sum(axis=1)
      m = min(len(ni), len(nj))
  
      p0 = np.float64(np.diag(df.iloc[0:m, 0:m]).sum()) / n
      pc = np.float64((ni.iloc[0:m] * nj.iloc[0:m]).sum()) / (n**2)
  
      n2 = choose(n, 2)
  
      rand = (
          np.float64(1)
          + (
              (df**2).sum().sum()
              - ((ni**2).sum() + (nj**2).sum()) / 2
          )
          / n2
      )
      nis2 = ni[ni > 1].map(lambda x: choose(int(x), 2)).sum()
      njs2 = nj[nj > 1].map(lambda x: choose(int(x), 2)).sum()
  
      num = (
          df[df > 1]
          .dropna(axis=[0, 1], thresh=1)
          .applymap(lambda n: choose(n, 2))
          .sum()
          .sum()
          - np.float64(nis2 * njs2) / n2
      )
      den = np.float64(nis2 + njs2) / 2 - np.float64(nis2 * njs2) / n2
      crand = num / den
  
      return {
          "diag": p0,
          "kappa": np.float64(p0 - pc) / (1 - pc),
          "rand": rand,
          "crand": crand,
      }
  
imports: import numpy
  from pandas.compat import range
label_desc: Use image node_id 3 for calling a global function with example usage: class_agreement(df) and returns: dict