code: 
  from __future__ import print_function
  from sklearn.metrics.pairwise import cosine_similarity
  from sklearn.decomposition import TruncatedSVD
  from sklearn.pipeline import make_pipeline
  from sklearn.preprocessing import Normalizer
  from sklearn import metrics
  from sklearn.decomposition import TruncatedSVD
  from sklearn.decomposition import NMF
  from sklearn.decomposition import LatentDirichletAllocation
  from sklearn.decomposition import ProjectedGradientNMF
  from sklearn.feature_extraction.text import TfidfVectorizer
  from sklearn.cluster import KMeans
  from sklearn.metrics.pairwise import euclidean_distances
  from sklearn.metrics import jaccard_similarity_score
  from sklearn.metrics.pairwise import paired_distances
  from sklearn.feature_extraction.text import TfidfVectorizer
  from sklearn.cluster import KMeans, MiniBatchKMeans
  from sklearn.feature_extraction.text import CountVectorizer
  from nltk.corpus import stopwords
  #import codecs, difflib, Levenshtein, distance
  import logging
  from optparse import OptionParser
  import sys
  from time import time
  import numpy as np
  # Display progress logs on stdout
  logging.basicConfig(level=logging.INFO,
                      format='%(asctime)s %(levelname)s %(message)s')
  
  # parse commandline arguments
  op = OptionParser()
  op.add_option("--lsa",
                dest="n_components", type="int",
                help="Preprocess documents with latent semantic analysis.")
  op.add_option("--no-minibatch",
                action="store_false", dest="minibatch", default=True,
                help="Use ordinary k-means algorithm (in batch mode).")
  op.add_option("--no-idf",
                action="store_false", dest="use_idf", default=True,
                help="Disable Inverse Document Frequency feature weighting.")
  op.add_option("--use-hashing",
                action="store_true", default=False,
                help="Use a hashing feature vectorizer")
  op.add_option("--n-features", type=int, default=10000,
                help="Maximum number of features (dimensions)"
                     " to extract from text.")
  op.add_option("--verbose",
                action="store_true", dest="verbose", default=False,
                help="Print progress reports inside k-means algorithm.")
  
  print(__doc__)
  op.print_help()
  def is_interactive():
      return not hasattr(sys.modules['__main__'], '__file__')
  
  # work-around for Jupyter notebook and IPython console
  argv = [] if is_interactive() else sys.argv[1:]
  (opts, args) = op.parse_args(argv)
  if len(args) > 0:
      op.error("this script takes no arguments.")
      sys.exit(1)
  
  def is_interactive():
      return not hasattr(sys.modules['__main__'], '__file__')
  # Bring in standard stopwords
  with np.errstate(divide='ignore'):
      np.float64(1.0) / 0.0
  from nltk.corpus import stopwords
  
  # Bring in the default English NLTK stop words
  stoplist = stopwords.words('english')
  
  # Define additional stopwords in a string
  additional_stopwords = """To  [ ] I you am As it  can't  <<...>>  sincerely, .  > - < Kenneth Lay/Corp/Enron@Enron Best regards Sincerely From  Sent Original Message Q <-> * | /\ 100% 12345678910 () """
  
  # Split the the additional stopwords string on each word and then add
  # those words to the NLTK stopwords list
  stoplist += additional_stopwords.split()
  
  stopWords = stopwords.words('english')
  
  print ("\nCalculating document similarity scores...")
  
  # Open and read a bunch of files
  f = open('ken-lay_body.txt')
  doc1 = str(f.read())
  f = open('jeff-skilling_body.txt')
  doc2 = str(f.read())
  f = open('Richard-shapiro_body.txt')
  doc3 = str(f.read())
  f = open('kay-mann_body.txt')
  doc4 = str(f.read())
  f = open('Jeff-dasovich_body.txt',)
  doc5 = str(f.read())
  f = open('tana jones_body.txt')
  doc6 = str(f.read())
  f = open('steven kean_body.txt')
  doc7 = str(f.read())
  f = open('shackleton sara_body.txt')
  doc8 = str(f.read())
  f = open('james steffes_body.txt')
  doc9 = str(f.read())
  f = open('Mark taylor_body.txt')
  doc10 = str(f.read())
  f = open('davis pete_body.txt')
  doc11 = str(f.read())
  f = open('Chris g_body.txt')
  doc12 = str(f.read())
  f = open('kate symes_body.txt')
  doc13 = str(f.read())
  f = open('Mcconnell.body.txt')
  doc14 = str(f.read())
  f = open('kaminski_body.txt')
  doc15 = str(f.read())
  #train_string = 'By these proceedings for judicial review the Claimant seeks to challenge the decision of the Defendant dated the 23rd of May 2014 refusing the Claimant’s application of the 3rd of January 2012 for naturalisation as a British citizen'
  # Construct the training set as a list
  train_set = [ doc1, doc2, doc3, doc4, doc5, doc6,doc7, doc8, doc9, doc10, doc11, doc12, doc13, doc14, doc15]
  
  # Set up the vectoriser, passing in the stop words
  tfidf_vectorizer = TfidfVectorizer(stop_words=stopWords)
  vectorizer = TfidfVectorizer(min_df = 1, stop_words = 'english')
  # Apply the vectoriser to the training set
  tfidf_matrix_train = tfidf_vectorizer.fit_transform(train_set)
  C = cosine_similarity(tfidf_matrix_train)
  #print ("\nSimilarity Score [*] ",cosine_similarity(tfidf_matrix_train[0:1], tfidf_matrix_train))
  
  tfidf_matrix_train.shape
  #print(tfidf_matrix_train.toarray())
  #print(vector.toarray())
  
  
  
  
  print("Top terms per cluster:")
  
  if opts.n_components:
      print("Performing dimensionality reduction using LSA")
      t0 = time()
      # Vectorizer results are normalized, which makes KMeans behave as
      # spherical k-means for better results. Since LSA/SVD results are
      # not normalized, we have to redo the normalization.
      svd = TruncatedSVD(opts.n_components)
      normalizer = Normalizer(copy=False)
      lsa = make_pipeline(svd, normalizer)
      tfidf_matrix_train = lsa.fit_transform(tfidf_matrix_train)
      print("done in %fs" % (time() - t0))
  
      explained_variance = svd.explained_variance_ratio_.sum()
      print("Explained variance of the SVD step: {}%".format(
          int(explained_variance * 100)))
  
      print()
  
  
  # #############################################################################
  # Do the actual clustering
  true_k = 5
  km = KMeans(n_clusters=true_k, init='k-means++', max_iter=100, n_init=1)
  
  data_vectorized=km.fit(tfidf_matrix_train)
  labels = km.labels_
  
  if opts.minibatch:
      km = MiniBatchKMeans(n_clusters=true_k, init='k-means++', n_init=1,
                           init_size=1000, batch_size=1000, verbose=opts.verbose)
  else:
      km = KMeans(n_clusters=true_k, init='k-means++', max_iter=100, n_init=1,
                  verbose=opts.verbose)
  
  NUM_TOPICS= labels
  print("Clustering sparse data with %s" % km)
  t0 = time()
  km.fit(tfidf_matrix_train)
  print("done in %0.3fs" % (time() - t0))
  print()
  
  print("Homogeneity: %0.3f" % metrics.homogeneity_score(labels,km.labels_))
  print("Completeness: %0.3f" % metrics.completeness_score(labels,km.labels_))
  print("V-measure: %0.3f" % metrics.v_measure_score(labels,km.labels_))
  print("Adjusted Rand-Index: %.3f"
        % metrics.adjusted_rand_score( labels, km.labels_))
  print("Silhouette Coefficient: %0.3f"
        % metrics.silhouette_score(tfidf_matrix_train, km.labels_, sample_size=1000))
  
  print()
  
  
  
  # Build a Latent Dirichlet Allocation Model
  lda_model = LatentDirichletAllocation(n_topics=NUM_TOPICS, max_iter=10, learning_method='online')
  lda_Z = lda_model.fit_transform(data_vectorized)
  print(lda_Z.shape)  # (NO_DOCUMENTS, NO_TOPICS)
  
  
  
  pgnmf_model= ProjectedGradientNMF(n_components=NUM_TOPICS)
  pgnmf_z= pgnmf_model.fit_transform(data_vectorized)
  print(pgnmf_z.shape)  # (NO_DOCUMENTS, NO_TOPICS)
  
  
  # Build a Non-Negative Matrix Factorization Model
  nmf_model = NMF(n_components=NUM_TOPICS)
  nmf_Z = nmf_model.fit_transform(data_vectorized)
  print(nmf_Z.shape)  # (NO_DOCUMENTS, NO_TOPICS)
  
  # Build a Latent Semantic Indexing Model
  lsi_model = TruncatedSVD(n_components=NUM_TOPICS)
  lsi_Z = lsi_model.fit_transform(data_vectorized)
  print(lsi_Z.shape)  # (NO_DOCUMENTS, NO_TOPICS)
  
  
  # Let's see how the first document in the corpus looks like in different topic spaces
  print(lda_Z[0])
  print(nmf_Z[0])
  print(lsi_Z[0])
  print(pgnmf_z[0])
  # Let's see how the first document in the corpus looks like in different topic spaces
  print(lda_Z[0])
  print(nmf_Z[0])
  print(lsi_Z[0])
  print(pgnmf_z[0])
  def print_topics(model, vectorizer, top_n=10):
      for idx, topic in enumerate(model.components_):
          print("Concepts %d:" % (idx))
          print([(vectorizer.get_feature_names()[i], topic[i])
                          for i in topic.argsort()[:-top_n - 1:-1]])
  
  print("LDA Model:")
  print_topics(lda_model, vectorizer)
  print("=" * 20)
  
  # #############################################################################
  # Do the actual clustering
  
  if opts.minibatch:
      km = MiniBatchKMeans(n_clusters=true_k, init='k-means++', n_init=1,
                           init_size=10000, batch_size=1000, verbose=opts.verbose)
  else:
      km = KMeans(n_clusters=true_k, init='k-means++', max_iter=100, n_init=1,
                  verbose=opts.verbose)
  
  print("Clustering sparse data with %s" % km)
  t0 = time()
  km.fit(tfidf_matrix_train)
  print("done in %0.3fs" % (time() - t0))
  print()
  
  print("Homogeneity: %0.3f" % metrics.homogeneity_score(labels, km.labels_))
  print("Completeness: %0.3f" % metrics.completeness_score(labels, km.labels_))
  print("V-measure: %0.3f" % metrics.v_measure_score(labels, km.labels_))
  print("Adjusted Rand-Index: %.3f"
        % metrics.adjusted_rand_score(labels, km.labels_))
  print("Silhouette Coefficient: %0.3f"
        % metrics.silhouette_score(tfidf_matrix_train, km.labels_, sample_size=1000))
  
  print()
  
  print("NMF Model:")
  print_topics(nmf_model, vectorizer)
  print("=" * 20)
  
  # #############################################################################
  # Do the actual clustering
  
  if opts.minibatch:
      km = MiniBatchKMeans(n_clusters=true_k, init='k-means++', n_init=1,
                           init_size=10000, batch_size=1000, verbose=opts.verbose)
  else:
      km = KMeans(n_clusters=true_k, init='k-means++', max_iter=100, n_init=1,
                  verbose=opts.verbose)
  
  print("Clustering sparse data with %s" % km)
  t0 = time()
  km.fit(tfidf_matrix_train)
  print("done in %0.3fs" % (time() - t0))
  print()
  
  print("Homogeneity: %0.3f" % metrics.homogeneity_score(labels, km.labels_))
  print("Completeness: %0.3f" % metrics.completeness_score(labels, km.labels_))
  print("V-measure: %0.3f" % metrics.v_measure_score(labels, km.labels_))
  print("Adjusted Rand-Index: %.3f"
        % metrics.adjusted_rand_score(labels, km.labels_))
  print("Silhouette Coefficient: %0.3f"
        % metrics.silhouette_score(tfidf_matrix_train, km.labels_, sample_size=1000))
  
  print()
  
  
  print("PGNMF Model:")
  print_topics(pgnmf_model, vectorizer)
  print("=" * 20)
  
  # #############################################################################
  # Do the actual clustering
  
  if opts.minibatch:
      km = MiniBatchKMeans(n_clusters=true_k, init='k-means++', n_init=1,
                           init_size=10000, batch_size=1000, verbose=opts.verbose)
  else:
      km = KMeans(n_clusters=true_k, init='k-means++', max_iter=100, n_init=1,
                  verbose=opts.verbose)
  
  print("Clustering sparse data with %s" % km)
  t0 = time()
  km.fit(tfidf_matrix_train)
  print("done in %0.3fs" % (time() - t0))
  print()
  
  print("Homogeneity: %0.3f" % metrics.homogeneity_score(labels, km.labels_))
  print("Completeness: %0.3f" % metrics.completeness_score(labels, km.labels_))
  print("V-measure: %0.3f" % metrics.v_measure_score(labels, km.labels_))
  print("Adjusted Rand-Index: %.3f"
        % metrics.adjusted_rand_score(labels, km.labels_))
  print("Silhouette Coefficient: %0.3f"
        % metrics.silhouette_score(tfidf_matrix_train, km.labels_, sample_size=1000))
  
  print()
  
  
  if not opts.use_hashing:
      print("Top terms per cluster:")
  
      if opts.n_components:
          original_space_centroids = svd.inverse_transform(km.cluster_centers_)
          order_centroids = original_space_centroids.argsort()[:, ::-1]
      else:
          order_centroids = km.cluster_centers_.argsort()[:, ::-1]
  
      terms = tfidf_vectorizer .get_feature_names()
      for i in range(true_k):
          print("Cluster %d:" % i, end='')
          for ind in order_centroids[i, :10]:
              print(' %s' % terms[ind], end='')
          print()
  
  
apis: sklearn.preprocessing.Normalizer sklearn.metrics.v_measure_score sklearn.decomposition.ProjectedGradientNMF sklearn.metrics.adjusted_rand_score sklearn.feature_extraction.text.TfidfVectorizer sklearn.decomposition.TruncatedSVD sklearn.decomposition.LatentDirichletAllocation sklearn.cluster.KMeans numpy.errstate sklearn.pipeline.make_pipeline sklearn.metrics.homogeneity_score sklearn.metrics.completeness_score sklearn.metrics.silhouette_score sklearn.metrics.pairwise.cosine_similarity sklearn.decomposition.NMF numpy.float64 sklearn.cluster.MiniBatchKMeans