class_docstr: The CountFrequencyEncoder() replaces categories by either the count or the
  percentage of observations per category.
  
  For example in the variable colour, if 10 observations are blue, blue will
  be replaced by 10. Alternatively, if 10% of the observations are blue, blue
  will be replaced by 0.1.
  
  The CountFrequencyEncoder() will encode only categorical variables by default
  (type 'object' or 'categorical'). You can pass a list of variables to encode.
  Alternatively, the encoder will find and encode all categorical variables
  (type 'object' or 'categorical').
  
  With `ignore_format=True` you have the option to encode numerical variables as well.
  The procedure is identical, you can either enter the list of variables to encode, or
  the transformer will automatically select all variables.
  
  The encoder first maps the categories to the counts or frequencies for each
  variable (fit). The encoder then replaces the categories with those numbers
  (transform).
  
  More details in the :ref:`User Guide <count_freq_encoder>`.
  
  Parameters
  ----------
  encoding_method: str, default='count'
      Desired method of encoding.
  
      **'count'**: number of observations per category
  
      **'frequency'**: percentage of observations per category
  
  {variables}
  
  {ignore_format}
  
  {unseen}
  
  Attributes
  ----------
  encoder_dict_:
      Dictionary with the count or frequency per category, per variable.
  
  {variables_}
  
  {feature_names_in_}
  
  {n_features_in_}
  
  Methods
  -------
  fit:
      Learn the count or frequency per category, per variable.
  
  {fit_transform}
  
  {inverse_transform}
  
  {transform}
  
  Notes
  -----
  NAN will be introduced when encoding categories that were not present in the
  training set. If this happens, try grouping infrequent categories using the
  RareLabelEncoder(), or set `unseen='encode'`.
  
  There is a similar implementation in the open-source package
  `Category encoders <https://contrib.scikit-learn.org/category_encoders/>`_
  
  See Also
  --------
  feature_engine.encoding.RareLabelEncoder
  category_encoders.count.CountEncoder
  
  Examples
  --------
  
  >>> import pandas as pd
  >>> from feature_engine.encoding import CountFrequencyEncoder
  >>> X = pd.DataFrame(dict(x1 = [1,2,3,4], x2 = ["c", "a", "b", "c"]))
  >>> cf = CountFrequencyEncoder(encoding_method='count')
  >>> cf.fit(X)
  >>> cf.transform(X)
     x1  x2
  0   1   2
  1   2   1
  2   3   1
  3   4   2
  
  >>> cf = CountFrequencyEncoder(encoding_method='frequency')
  >>> cf.fit(X)
  >>> cf.transform(X)
     x1    x2
  0   1  0.50
  1   2  0.25
  2   3  0.25
  3   4  0.50
class_docstr_tok: ["The","CountFrequencyEncoder","(",")","replaces","categories","by","either","the","count","or","the","percentage","of","observations","per","category",".","For","example","in","the","variable","colour",",","if","10","observations","are","blue",",","blue","will","be","replaced","by","10",".","Alternatively",",","if","10","%","of","the","observations","are","blue",",","blue","will","be","replaced","by","0.1",".","The","CountFrequencyEncoder","(",")","will","encode","only","categorical","variables","by","default","(","type","'object","'","or","'categorical","'",")",".","You","can","pass","a","list","of","variables","to","encode",".","Alternatively",",","the","encoder","will","find","and","encode","all","categorical","variables","(","type","'object","'","or","'categorical","'",")",".","With","`","ignore_format=True","`","you","have","the","option","to","encode","numerical","variables","as","well",".","The","procedure","is","identical",",","you","can","either","enter","the","list","of","variables","to","encode",",","or","the","transformer","will","automatically","select","all","variables",".","The","encoder","first","maps","the","categories","to","the","counts","or","frequencies","for","each","variable","(","fit",")",".","The","encoder","then","replaces","the","categories","with","those","numbers","(","transform",")",".","More","details","in","the",":","ref",":","`","User","Guide","<","count_freq_encoder",">","`",".","Parameters","--","--","--","--","--","encoding_method",":","str",",","default='count'","Desired","method","of","encoding",".","*","*","'count","'","*","*",":","number","of","observations","per","category","*","*","'frequency","'","*","*",":","percentage","of","observations","per","category","{","variables","}","{","ignore_format","}","{","unseen","}","Attributes","--","--","--","--","--","encoder_dict_",":","Dictionary","with","the","count","or","frequency","per","category",",","per","variable",".","{","variables_","}","{","feature_names_in_","}","{","n_features_in_","}","Methods","--","--","--","-","fit",":","Learn","the","count","or","frequency","per","category",",","per","variable",".","{","fit_transform","}","{","inverse_transform","}","{","transform","}","Notes","--","--","-","NAN","will","be","introduced","when","encoding","categories","that","were","not","present","in","the","training","set",".","If","this","happens",",","try","grouping","infrequent","categories","using","the","RareLabelEncoder","(",")",",","or","set","`","unseen='encode","'","`",".","There","is","a","similar","implementation","in","the","open-source","package","`","Category","encoders","<","https",":","\/\/contrib.scikit-learn.org\/category_encoders\/",">","`","_","See","Also","--","--","--","--","feature_engine.encoding.RareLabelEncoder","category_encoders.count.CountEncoder","Examples","--","--","--","--",">",">",">","import","pandas","as","pd",">",">",">","from","feature_engine.encoding","import","CountFrequencyEncoder",">",">",">","X","=","pd.DataFrame","(","dict","(","x1","=","[","1,2,3,4","]",",","x2","=","[","``","c","''",",","``","a","''",",","``","b","''",",","``","c","''","]",")",")",">",">",">","cf","=","CountFrequencyEncoder","(","encoding_method='count","'",")",">",">",">","cf.fit","(","X",")",">",">",">","cf.transform","(","X",")","x1","x2","0","1","2","1","2","1","2","3","1","3","4","2",">",">",">","cf","=","CountFrequencyEncoder","(","encoding_method='frequency","'",")",">",">",">","cf.fit","(","X",")",">",">",">","cf.transform","(","X",")","x1","x2","0","1","0.50","1","2","0.25","2","3","0.25","3","4","0.50"]
docstr: Learn the counts or frequencies which will be used to replace the categories.
  
  Parameters
  ----------
  X: pandas dataframe of shape = [n_samples, n_features]
      The training dataset. Can be the entire dataframe, not just the
      variables to be transformed.
  
  y: pandas Series, default = None
      y is not needed in this encoder. You can pass y or None.
docstr_tok: ["Learn","the","counts","or","frequencies","which","will","be","used","to","replace","the","categories",".","Parameters","--","--","--","--","--","X",":","pandas","dataframe","of","shape","=","[","n_samples",",","n_features","]","The","training","dataset",".","Can","be","the","entire","dataframe",",","not","just","the","variables","to","be","transformed",".","y",":","pandas","Series",",","default","=","None","y","is","not","needed","in","this","encoder",".","You","can","pass","y","or","None","."]
code: def fit(self, X: pd.DataFrame, y: Optional[pd.Series] = None):
      """
      Learn the counts or frequencies which will be used to replace the categories.
  
      Parameters
      ----------
      X: pandas dataframe of shape = [n_samples, n_features]
          The training dataset. Can be the entire dataframe, not just the
          variables to be transformed.
  
      y: pandas Series, default = None
          y is not needed in this encoder. You can pass y or None.
      """
      X = check_X(X)
      self._fit(X)
      self._get_feature_names_in(X)
  
      self.encoder_dict_ = {}
  
      # learn encoding maps
      for var in self.variables_:
          if self.encoding_method == "count":
              self.encoder_dict_[var] = X[var].value_counts().to_dict()
  
          elif self.encoding_method == "frequency":
              self.encoder_dict_[var] = (
                  X[var].value_counts(normalize=True).to_dict()
              )
  
      # unseen categories are replaced by 0
      if self.unseen == "encode":
          self._unseen = 0
  
      return self
  
file_path: feature_engine/feature_engine/encoding/count_frequency.py
imports: from typing import List, Optional, Union
  import pandas
  from feature_engine._docstrings.fit_attributes import _feature_names_in_docstring, _n_features_in_docstring, _variables_attribute_docstring
  from feature_engine._docstrings.init_parameters import _ignore_format_docstring, _unseen_docstring, _variables_categorical_docstring
  from feature_engine._docstrings.methods import _fit_transform_docstring, _inverse_transform_docstring, _transform_encoders_docstring
  from feature_engine._docstrings.substitute import Substitution
  from feature_engine.dataframe_checks import check_X
  from feature_engine.encoding._helper_functions import check_parameter_unseen
  from feature_engine.encoding.base_encoder import CategoricalInitMixin, CategoricalMethodsMixin
label_desc: Use image node_id 2 for calling the CountFrequencyEncoder obj's underlying member method code with example usage: obj.fit(X, y) and returns: self