code: def clustering_with_answer(data_file, answer_file, ccore, **kwargs):
      data_type = kwargs.get("data_type", "points")
      metric = kwargs.get(
          "metric", distance_metric(type_metric.EUCLIDEAN)
      )
  
      original_data = read_sample(data_file)
      data = original_data
  
      if data_type == "distance_matrix":
          data = calculate_distance_matrix(original_data, metric)
  
      reader = answer_reader(answer_file)
  
      amount_medoids = len(reader.get_clusters())
  
      initial_medoids = kmeans_plusplus_initializer(
          data, amount_medoids, **kwargs
      ).initialize(return_index=True)
      kmedoids_instance = kmedoids(
          data, initial_medoids, 0.001, ccore, **kwargs
      )
  
      kmedoids_instance.process()
  
      clusters = kmedoids_instance.get_clusters()
      medoids = kmedoids_instance.get_medoids()
  
      expected_length_clusters = sorted(reader.get_cluster_lengths())
  
      assertion.eq(len(expected_length_clusters), len(medoids))
      assertion.eq(
          len(data), sum([len(cluster) for cluster in clusters])
      )
      assertion.eq(
          sum(expected_length_clusters),
          sum([len(cluster) for cluster in clusters]),
      )
  
      unique_medoids = set()
      for medoid in medoids:
          assertion.false(
              medoid in unique_medoids,
              message="Medoids '%s' is not unique (actual medoids: '%s')"
              % (str(medoid), str(unique_medoids)),
          )
          unique_medoids.add(medoid)
  
      unique_points = set()
      for cluster in clusters:
          for point in cluster:
              assertion.false(
                  point in unique_points,
                  message="Point '%s' is already assigned to one of the clusters."
                  % str(point),
              )
              unique_points.add(point)
  
      assertion.eq(
          expected_length_clusters,
          sorted([len(cluster) for cluster in clusters]),
      )
  
      expected_clusters = reader.get_clusters()
      for actual_cluster in clusters:
          cluster_found = False
          for expected_cluster in expected_clusters:
              if actual_cluster == expected_cluster:
                  cluster_found = True
  
          assertion.true(
              cluster_found,
              message="Actual cluster '%s' is not found among expected."
              % str(actual_cluster),
          )
  
file_path: pyclustering/pyclustering/cluster/tests/kmedoids_templates.py
imports: import math
  import numpy
  from pyclustering.tests.assertion import assertion
  from pyclustering.cluster.kmedoids import kmedoids, build
  from pyclustering.cluster.center_initializer import kmeans_plusplus_initializer
  from pyclustering.samples import answer_reader
  from pyclustering.utils import read_sample, calculate_distance_matrix
  from pyclustering.utils.metric import distance_metric, type_metric
  from random import random, randint
label_desc: Use image node_id 7 for calling the kmedoids_test_template obj's underlying member method code with example usage: obj.clustering_with_answer(data_file, answer_file, ccore) without return types