code: def pca(
      input_matrix: Union[pd.Series, pd.DataFrame],
      n_components=2,
      random_state=None,
  ) -> pd.Series:
      """
      Perform principal component analysis on the given input.
  
      Principal Component Analysis (PCA) is a statistical method that is
      used to reveal where the variance in a dataset comes from. For
      textual data, one could for example first represent a Series of
      documents using :meth:`texthero.representation.tfidf` to get a vector
      representation of each document. Then, PCA can generate new vectors
      from the tfidf representation that showcase the differences among
      the documents most strongly in fewer dimensions.
  
      For example, the tfidf vectors will have length 100 if hero.tfidf was
      called on a large corpus with max_features=100. Visualizing 100
      dimensions is hard! Using PCA with n_components=3, every document will
      now get a vector of length 3, and the vectors will be chosen so that
      the document differences are easily visible. The corpus can now be
      visualized in 3D and we can get a good first view of the data!
  
      In general, *pca* should be called after the text has already been
      represented to a matrix form.
  
      PCA cannot directly handle sparse input, so when calling pca on a
      sparse DataFrame, the input has to be expanded which can lead to
      memory problems with big datasets.
  
      Parameters
      ----------
      input_matrix : Pandas Series (VectorSeries) or DataFrame
  
      n_components : int or str, optional, default=2
          Number of components to keep (dimensionality of output vectors).
          If n_components is not set or None, all components are kept.
          If set to "mle", the number of components is
          automatically estimated.
  
      random_state : int, optional, default=None
          Pass an int for reproducible results across multiple function calls.
  
  
      Returns
      -------
      Pandas Series with the vector calculated by PCA for the document in
      every cell.
  
      Examples
      --------
      >>> import texthero as hero
      >>> import pandas as pd
      >>> s = pd.Series(["Football is great",
      ...                "Hi, I'm Texthero, who are you? Tell me!"])
      >>> s = s.pipe(hero.clean).pipe(hero.tokenize).pipe(hero.tfidf)
      >>> # Attention, your results might differ due to
      >>> # the randomness in PCA!
      >>> hero.pca(s) # doctest: +SKIP
      document
      0     [1.5713577608669735, 1.1102230246251565e-16]
      1    [-1.5713577608669729, 1.1102230246251568e-16]
      dtype: object
  
      See also
      --------
      `PCA on Wikipedia
      <https://en.wikipedia.org/wiki/Principal_component_analysis>`_
  
      """
      # Default n_components=2 to enable users to easily plot the results.
      pca = PCA(
          n_components=n_components,
          random_state=random_state,
          copy=False,
      )
  
      if isinstance(input_matrix, pd.DataFrame):
          values = input_matrix.values
      else:
          values = list(input_matrix)
  
      return pd.Series(
          list(pca.fit_transform(values)), index=input_matrix.index
      )
  
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 4 for calling a global function with example usage: pca(input_matrix, n_components, random_state) and returns: pd