class_docstr: textClust, a clustering algorithm for text data.
  
  textClust [^1][^2] is a stream clustering algorithm for textual data that can identify and track topics
  over time in a stream of texts. The algorithm uses a widely popular two-phase clustering
  approach where the stream is first summarised in real-time.
  
  The result is many small preliminary clusters in the stream called `micro-clusters`.
  Micro-clusters maintain enough information to update and efficiently calculate the
  cosine similarity between them over time, based on the TF-IDF vector of their texts.
  Upon request, the miro-clusters can be reclustered to generate the final result
  using any distance-based clustering algorithm, such as hierarchical clustering.
  To keep the micro-clusters up-to-date, our algorithm applies a fading strategy where
  micro-clusters that are not updated regularly lose relevance and are eventually removed.
  
  Parameters
  ----------
  radius
      Distance threshold to merge two micro-clusters. Must be within the range `(0, 1]`
  fading_factor
      Fading factor of micro-clusters
  tgap
     Time between outlier removal
  term_fading
      Determines whether individual terms should also be faded
  real_time_fading
      Parameter that specifies whether natural time or the number of observations should be used
      for fading
  micro_distance
       Distance metric used for clustering macro-clusters
  macro_distance
      Distance metric used for clustering macro-clusters
  num_macro
      Number of macro clusters that should be identified during the reclustering phase
  min_weight
      Minimum weight of micro clusters to be used for reclustering
  auto_r
      Parameter that specifies if  `radius` should be automatically updated
  auto_merge
      Determines, if close observations shall be merged together
  sigma
      Parameter that influences the automated trheshold adaption technique
  
   Attributes
  ----------
  micro_clusters
      Micro-clusters generated by the algorithm. Micro-clusters are of type `textclust.microcluster`
  
  References
  ----------
  [^1]: Assenmacher, D. und Trautmann, H. (2022). Textual One-Pass Stream Clustering with
  Automated Distance Threshold Adaption. In: Asian Conference on Intelligent Information and
  Database Systems (Accepted)
  [^2]: Carnein, M., Assenmacher, D., Trautmann, H. (2017). Stream Clustering of Chat Messages with
  Applications to Twitch Streams. In: Advances in Conceptual Modeling. ER 2017.
  
  Examples
  --------
  
  >>> from river import compose
  >>> from river import feature_extraction
  >>> from river import metrics
  >>> from river import cluster
  
  >>> corpus = [
  ...    {"text":'This is the first document.',"idd":1, "cluster": 1, "cluster":1},
  ...    {"text":'This document is the second document.',"idd":2,"cluster": 1},
  ...    {"text":'And this is super unrelated.',"idd":3,"cluster": 2},
  ...    {"text":'Is this the first document?',"idd":4,"cluster": 1},
  ...    {"text":'This is super unrelated as well',"idd":5,"cluster": 2},
  ...    {"text":'Test text',"idd":6,"cluster": 5}
  ... ]
  
  >>> stopwords = [ 'stop', 'the', 'to', 'and', 'a', 'in', 'it', 'is', 'I']
  
  >>> metric = metrics.AdjustedRand()
  
  >>> model = compose.Pipeline(
  ...     feature_extraction.BagOfWords(lowercase=True, ngram_range=(1, 2), stop_words=stopwords),
  ...     cluster.TextClust(real_time_fading=False, fading_factor=0.001, tgap=100, auto_r=True,
  ...     radius=0.9)
  ... )
  
  >>> for x in corpus:
  ...     y_pred = model.predict_one(x["text"])
  ...     y = x["cluster"]
  ...     metric.update(y,y_pred)
  ...     model.learn_one(x["text"])
  
  >>> print(metric)
  AdjustedRand: -0.17647058823529413
class_docstr_tok: ["textClust",",","a","clustering","algorithm","for","text","data",".","textClust","[","^1","]","[","^2","]","is","a","stream","clustering","algorithm","for","textual","data","that","can","identify","and","track","topics","over","time","in","a","stream","of","texts",".","The","algorithm","uses","a","widely","popular","two-phase","clustering","approach","where","the","stream","is","first","summarised","in","real-time",".","The","result","is","many","small","preliminary","clusters","in","the","stream","called","`","micro-clusters","`",".","Micro-clusters","maintain","enough","information","to","update","and","efficiently","calculate","the","cosine","similarity","between","them","over","time",",","based","on","the","TF-IDF","vector","of","their","texts",".","Upon","request",",","the","miro-clusters","can","be","reclustered","to","generate","the","final","result","using","any","distance-based","clustering","algorithm",",","such","as","hierarchical","clustering",".","To","keep","the","micro-clusters","up-to-date",",","our","algorithm","applies","a","fading","strategy","where","micro-clusters","that","are","not","updated","regularly","lose","relevance","and","are","eventually","removed",".","Parameters","--","--","--","--","--","radius","Distance","threshold","to","merge","two","micro-clusters",".","Must","be","within","the","range","`","(","0",",","1","]","`","fading_factor","Fading","factor","of","micro-clusters","tgap","Time","between","outlier","removal","term_fading","Determines","whether","individual","terms","should","also","be","faded","real_time_fading","Parameter","that","specifies","whether","natural","time","or","the","number","of","observations","should","be","used","for","fading","micro_distance","Distance","metric","used","for","clustering","macro-clusters","macro_distance","Distance","metric","used","for","clustering","macro-clusters","num_macro","Number","of","macro","clusters","that","should","be","identified","during","the","reclustering","phase","min_weight","Minimum","weight","of","micro","clusters","to","be","used","for","reclustering","auto_r","Parameter","that","specifies","if","`","radius","`","should","be","automatically","updated","auto_merge","Determines",",","if","close","observations","shall","be","merged","together","sigma","Parameter","that","influences","the","automated","trheshold","adaption","technique","Attributes","--","--","--","--","--","micro_clusters","Micro-clusters","generated","by","the","algorithm",".","Micro-clusters","are","of","type","`","textclust.microcluster","`","References","--","--","--","--","--","[","^1","]",":","Assenmacher",",","D.","und","Trautmann",",","H.","(","2022",")",".","Textual","One-Pass","Stream","Clustering","with","Automated","Distance","Threshold","Adaption",".","In",":","Asian","Conference","on","Intelligent","Information","and","Database","Systems","(","Accepted",")","[","^2","]",":","Carnein",",","M.",",","Assenmacher",",","D.",",","Trautmann",",","H.","(","2017",")",".","Stream","Clustering","of","Chat","Messages","with","Applications","to","Twitch","Streams",".","In",":","Advances","in","Conceptual","Modeling",".","ER","2017",".","Examples","--","--","--","--",">",">",">","from","river","import","compose",">",">",">","from","river","import","feature_extraction",">",">",">","from","river","import","metrics",">",">",">","from","river","import","cluster",">",">",">","corpus","=","[","...","{","``","text","''",":","'This","is","the","first","document",".","'",",","''","idd","''",":1",",","``","cluster","''",":","1",",","``","cluster","''",":1","}",",","...","{","``","text","''",":","'This","document","is","the","second","document",".","'",",","''","idd","''",":2",",","''","cluster","''",":","1","}",",","...","{","``","text","''",":","'And","this","is","super","unrelated",".","'",",","''","idd","''",":3",",","''","cluster","''",":","2","}",",","...","{","``","text","''",":","'Is","this","the","first","document","?","'",",","''","idd","''",":4",",","''","cluster","''",":","1","}",",","...","{","``","text","''",":","'This","is","super","unrelated","as","well","'",",","''","idd","''",":5",",","''","cluster","''",":","2","}",",","...","{","``","text","''",":","'Test","text","'",",","''","idd","''",":6",",","''","cluster","''",":","5","}","...","]",">",">",">","stopwords","=","[","'stop","'",",","'the","'",",","'to","'",",","'and","'",",","'","a","'",",","'in","'",",","'it","'",",","'is","'",",","'","I","'","]",">",">",">","metric","=","metrics.AdjustedRand","(",")",">",">",">","model","=","compose.Pipeline","(","...","feature_extraction.BagOfWords","(","lowercase=True",",","ngram_range=","(","1",",","2",")",",","stop_words=stopwords",")",",","...","cluster.TextClust","(","real_time_fading=False",",","fading_factor=0.001",",","tgap=100",",","auto_r=True",",","...","radius=0.9",")","...",")",">",">",">","for","x","in","corpus",":","...","y_pred","=","model.predict_one","(","x","[","``","text","''","]",")","...","y","=","x","[","``","cluster","''","]","...","metric.update","(","y",",","y_pred",")","...","model.learn_one","(","x","[","``","text","''","]",")",">",">",">","print","(","metric",")","AdjustedRand",":","-0.17647058823529413"]
code: def showclusters(self, topn, num, type="micro"):
      # first clusters are sorted according to their respective weights
      if type == "micro":
          sortedmicro = sorted(
              self.micro_clusters.values(),
              key=lambda x: x.weight,
              reverse=True,
          )
      else:
          sortedmicro = sorted(
              self.get_macroclusters().values(),
              key=lambda x: x.weight,
              reverse=True,
          )
  
      print("-------------------------------------------")
      print("Summary of " + type + " clusters:")
  
      for micro in sortedmicro[0:topn]:
          print("----")
          print(type + " cluster id " + str(micro.id))
          print(type + " cluster weight " + str(micro.weight))
          if type != "micro":
              print("merged micro clusters: " + str(micro.merged_ids))
  
          # get indices of top terms
          indices = sorted(
              range(len([i["tf"] for i in micro.tf.values()])),
              key=[i["tf"] for i in micro.tf.values()].__getitem__,
              reverse=True,
          )
  
          # get representative and weight for micro cluster (room for improvement here?)
          representatives = [
              (
                  list(micro.tf.keys())[i],
                  micro.tf[list(micro.tf.keys())[i]]["tf"],
              )
              for i in indices[0 : min(len(micro.tf.keys()), num)]
          ]
          for rep in representatives:
              print(
                  "weight: "
                  + str(round(rep[1], 2))
                  + "\t token: "
                  + str(rep[0]).expandtabs(10)
              )
      print("-------------------------------------------")
  
imports: from __future__ import annotations
  import math
  import numpy
  import pandas
  from river import base
label_desc: Use image node_id 13 for calling the TextClust obj's underlying member method code with example usage: obj.showclusters(topn, num, type) without return types