docstr: Parameters
  -------
  term_doc_matrix : TermDocMatrix
  non_text : bool
  
  Returnss
  -------
  New term doc matrix
docstr_tok: ["Parameters","--","--","--","-","term_doc_matrix",":","TermDocMatrix","non_text",":","bool","Returnss","--","--","--","-","New","term","doc","matrix"]
code: def compact(self, term_doc_matrix, non_text=False):
      """
      Parameters
      -------
      term_doc_matrix : TermDocMatrix
      non_text : bool
  
      Returnss
      -------
      New term doc matrix
      """
      ranker = self.term_ranker(term_doc_matrix)
      if non_text:
          ranker = ranker.use_non_text_features()
      tdf = ranker.get_ranks()
      tdf_sum = tdf.sum(axis=0)
      tdf_portions = tdf / tdf_sum
      threshold = np.max(self.term_count / tdf_sum)
      terms_to_remove = tdf_portions[
          ~(tdf_portions > threshold).any(axis=1)
      ].index
      return term_doc_matrix.remove_terms(
          terms_to_remove, non_text=non_text
      )
  
imports: import numpy
  from scattertext.termranking import AbsoluteFrequencyRanker
label_desc: Use image node_id 2 for calling the ClassPercentageCompactor obj's underlying member method code with example usage: obj.compact(term_doc_matrix, non_text) and returns: term_doc_matrix