code: def evaluate_speaker_diarization(labels, labels_gt):
      min_len = min(labels.shape[0], labels_gt.shape[0])
      labels = labels[0:min_len]
      labels_gt = labels_gt[0:min_len]
  
      unique_flags = np.unique(labels)
      unique_flags_gt = np.unique(labels_gt)
  
      # compute contigency table:
      contigency_matrix = np.zeros(
          (unique_flags.shape[0], unique_flags_gt.shape[0])
      )
      for i in range(min_len):
          contigency_matrix[
              int(np.nonzero(unique_flags == labels[i])[0]),
              int(np.nonzero(unique_flags_gt == labels_gt[i])[0]),
          ] += 1.0
  
      columns, rows = contigency_matrix.shape
      row_sum = np.sum(contigency_matrix, axis=0)
      column_sum = np.sum(contigency_matrix, axis=1)
      matrix_sum = np.sum(contigency_matrix)
  
      purity_clust = np.zeros((columns,))
      purity_speak = np.zeros((rows,))
      # compute cluster purity:
      for i in range(columns):
          purity_clust[i] = np.max((contigency_matrix[i, :])) / (
              column_sum[i]
          )
  
      for j in range(rows):
          purity_speak[j] = np.max((contigency_matrix[:, j])) / (
              row_sum[j]
          )
  
      purity_cluster_m = np.sum(purity_clust * column_sum) / matrix_sum
      purity_speaker_m = np.sum(purity_speak * row_sum) / matrix_sum
  
      return purity_cluster_m, purity_speaker_m
  
imports: from __future__ import print_function
  import os
  import csv
  import glob
  import scipy
  import sklearn
  import numpy
  import hmmlearn.hmm
  import sklearn.cluster
  import pickle
  import matplotlib.pyplot
  from scipy.spatial import distance
  import sklearn.discriminant_analysis
  from sklearn.preprocessing import StandardScaler
  import sys
  import pyAudioAnalysis.audioBasicIO
  import pyAudioAnalysis.audioTrainTest
  import pyAudioAnalysis.MidTermFeatures
  import pyAudioAnalysis.ShortTermFeatures
label_desc: Use image node_id 8 for calling a global function with example usage: evaluate_speaker_diarization(labels, labels_gt) and returns: purity_cluster_m,  purity_speaker_m