code: def kmeans(
      input_matrix: Union[pd.Series, pd.DataFrame],
      n_clusters=5,
      n_init=10,
      max_iter=300,
      random_state=None,
      algorithm="auto",
  ) -> VectorSeries:
      """
      Performs K-means clustering algorithm on the given input.
  
      K-means clustering is used in natural language processing
      to separate texts into k clusters (groups)
      (e.g. some texts in a corpus might be about sports
      and some about music, so they will differ in the usage
      of technical terms; the K-means algorithm uses this
      to separate them into two clusters).
  
      Given a document-term matrix (so in
      texthero usually a Series after applying
      :meth:`texthero.representation.tfidf` or some other first
      representation function that assigns a scalar (a weight) to each
      word), K-means will find k topics (clusters) and assign a topic to
      each document.
  
      Kmeans can directly handle sparse input, so when calling kmeans on a
      sparse DataFrame, the advantage of sparseness is kept.
  
      Parameters
      ----------
      input_matrix: Pandas Series (VectorSeries) or DataFrame
  
      n_clusters: int, optional, default=5
          The number of clusters to separate the data into.
  
      n_init : int, optional, default=10
          Number of time the k-means algorithm will be run with different
          centroid seeds. The final results will be the best output of
          n_init consecutive runs in terms of inertia.
  
      max_iter : int, optional, default=300
          Maximum number of iterations of the k-means algorithm for a
          single run.
  
      random_state : int, optional, default=None
          Determines random number generation for centroid initialization. Use
          an int to make the randomness deterministic.
  
      algorithm : {"auto", "full", "elkan"}, optional, default="auto"
          K-means algorithm to use. The classical EM-style algorithm is "full".
          The "elkan" variation is more efficient on data with well-defined
          clusters, by using the triangle inequality. However it's more memory
          intensive.
  
      Returns
      -------
      Pandas Series with the cluster the document was assigned to in each
      cell.
  
      Examples
      --------
      >>> import texthero as hero
      >>> import pandas as pd
      >>> s = pd.Series(["Football, Sports, Soccer",
      ...                 "music, violin, orchestra",
      ...                "football, fun, sports", "music, fun, guitar"])
      >>> s = s.pipe(hero.clean).pipe(hero.tokenize).pipe(
      ...                                         hero.term_frequency
      ...                                             )
      >>> hero.kmeans(s, n_clusters=2, random_state=42) # doctest: +SKIP
      0    1
      1    0
      2    1
      3    0
      dtype: category
      Categories (2, int64): [0, 1]
      >>> # As we can see, the documents are correctly
      >>> # separated into topics / clusters by the algorithm.
  
      See also
      --------
      `kmeans on Wikipedia
      <https://en.wikipedia.org/wiki/K-means_clustering>`_
  
      """
  
      if isinstance(input_matrix, pd.DataFrame):
          input_matrix_coo = input_matrix.sparse.to_coo()
          input_matrix_for_vectorization = input_matrix_coo.astype(
              "float64"
          )
      else:
          input_matrix_for_vectorization = list(input_matrix)
  
      kmeans = KMeans(
          n_clusters=n_clusters,
          n_init=n_init,
          max_iter=max_iter,
          random_state=random_state,
          copy_x=True,
          algorithm=algorithm,
      ).fit(input_matrix_for_vectorization)
      return pd.Series(
          kmeans.predict(input_matrix_for_vectorization),
          index=input_matrix.index,
      ).astype("category")
  
imports: import pandas
  import numpy
  from sklearn.feature_extraction.text import TfidfVectorizer, CountVectorizer
  from sklearn.manifold import TSNE
  from sklearn.decomposition import PCA, NMF
  from sklearn.cluster import KMeans, DBSCAN, MeanShift
  from sklearn.metrics.pairwise import cosine_similarity
  from sklearn.preprocessing import normalize
  from scipy.sparse import coo_matrix
  from typing import Optional, Union, Any
  from texthero._types import TextSeries, TokenSeries, VectorSeries, DataFrame, InputSeries
  from texthero import preprocessing
  import logging
  import warnings
label_desc: Use image node_id 7 for calling a global function with example usage: kmeans(input_matrix, n_clusters, n_init, max_iter, random_state, algorithm) and returns: pd