class_docstr: **DEPRECATED: PRatioEncoder() is deprecated in version 1.5 and will be
  removed in Version 1.6. Use WoEEncoder() instead.**
  
  The PRatioEncoder() replaces categories by the ratio of the probability of the
  target = 1 and the probability of the target = 0.
  
  The target probability ratio is given by:
  
  .. math::
  
      p(1) / p(0)
  
  The log of the target probability ratio is:
  
  .. math::
  
      log( p(1) / p(0) )
  
  **Note**
  
  This categorical encoding is exclusive for binary classification.
  
  The division by 0 is not defined and the log(0) is not defined.
  Thus, if p(0) = 0 for the ratio encoder, or either p(0) = 0 or p(1) = 0 for
  log_ratio, in any of the variables, the encoder will return an error.
  
  The encoder 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 numbers for each variable (fit). The
  encoder then transforms the categories into the mapped numbers (transform).
  
  More details in the :ref:`User Guide <pratio_encoder>`.
  
  Parameters
  ----------
  encoding_method: str, default='ratio'
      Desired method of encoding.
  
      **'ratio'**: probability ratio
  
      **'log_ratio'**: log probability ratio
  
  {variables}
  
  {ignore_format}
  
  {unseen}
  
  Attributes
  ----------
  encoder_dict_:
      Dictionary with the probability ratio per category per variable.
  
  {variables_}
  
  {feature_names_in_}
  
  {n_features_in_}
  
  Methods
  -------
  fit:
      Learn probability ratio per category, per variable.
  
  {fit_transform}
  
  {inverse_transform}
  
  {transform}
  
  Notes
  -----
  NAN are introduced when encoding categories that were not present in the training
  dataset. If this happens, try grouping infrequent categories using the
  RareLabelEncoder().
  
  See Also
  --------
  feature_engine.encoding.RareLabelEncoder
class_docstr_tok: ["*","*","DEPRECATED",":","PRatioEncoder","(",")","is","deprecated","in","version","1.5","and","will","be","removed","in","Version","1.6",".","Use","WoEEncoder","(",")","instead",".","*","*","The","PRatioEncoder","(",")","replaces","categories","by","the","ratio","of","the","probability","of","the","target","=","1","and","the","probability","of","the","target","=","0",".","The","target","probability","ratio","is","given","by",":","..","math",":",":","p","(","1",")","\/","p","(","0",")","The","log","of","the","target","probability","ratio","is",":","..","math",":",":","log","(","p","(","1",")","\/","p","(","0",")",")","*","*","Note","*","*","This","categorical","encoding","is","exclusive","for","binary","classification",".","The","division","by","0","is","not","defined","and","the","log","(","0",")","is","not","defined",".","Thus",",","if","p","(","0",")","=","0","for","the","ratio","encoder",",","or","either","p","(","0",")","=","0","or","p","(","1",")","=","0","for","log_ratio",",","in","any","of","the","variables",",","the","encoder","will","return","an","error",".","The","encoder","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","numbers","for","each","variable","(","fit",")",".","The","encoder","then","transforms","the","categories","into","the","mapped","numbers","(","transform",")",".","More","details","in","the",":","ref",":","`","User","Guide","<","pratio_encoder",">","`",".","Parameters","--","--","--","--","--","encoding_method",":","str",",","default='ratio'","Desired","method","of","encoding",".","*","*","'ratio","'","*","*",":","probability","ratio","*","*","'log_ratio","'","*","*",":","log","probability","ratio","{","variables","}","{","ignore_format","}","{","unseen","}","Attributes","--","--","--","--","--","encoder_dict_",":","Dictionary","with","the","probability","ratio","per","category","per","variable",".","{","variables_","}","{","feature_names_in_","}","{","n_features_in_","}","Methods","--","--","--","-","fit",":","Learn","probability","ratio","per","category",",","per","variable",".","{","fit_transform","}","{","inverse_transform","}","{","transform","}","Notes","--","--","-","NAN","are","introduced","when","encoding","categories","that","were","not","present","in","the","training","dataset",".","If","this","happens",",","try","grouping","infrequent","categories","using","the","RareLabelEncoder","(",")",".","See","Also","--","--","--","--","feature_engine.encoding.RareLabelEncoder"]
docstr: Learn the numbers that should be used to replace the categories in each
  variable. That is the ratio of probability.
  
  Parameters
  ----------
  X: pandas dataframe of shape = [n_samples, n_features]
      The training input samples. Can be the entire dataframe, not just the
      categorical variables.
  
  y: pandas series.
      Target, must be binary.
docstr_tok: ["Learn","the","numbers","that","should","be","used","to","replace","the","categories","in","each","variable",".","That","is","the","ratio","of","probability",".","Parameters","--","--","--","--","--","X",":","pandas","dataframe","of","shape","=","[","n_samples",",","n_features","]","The","training","input","samples",".","Can","be","the","entire","dataframe",",","not","just","the","categorical","variables",".","y",":","pandas","series",".","Target",",","must","be","binary","."]
code: def fit(self, X: pd.DataFrame, y: pd.Series):
      """
      Learn the numbers that should be used to replace the categories in each
      variable. That is the ratio of probability.
  
      Parameters
      ----------
      X: pandas dataframe of shape = [n_samples, n_features]
          The training input samples. Can be the entire dataframe, not just the
          categorical variables.
  
      y: pandas series.
          Target, must be binary.
      """
  
      X, y = check_X_y(X, y)
  
      # check that y is binary
      if y.nunique() != 2:
          raise ValueError(
              "This encoder is designed for binary classification. The target "
              "used has more than 2 unique values."
          )
  
      self._fit(X)
      self._get_feature_names_in(X)
  
      temp = pd.concat([X, y], axis=1)
      temp.columns = list(X.columns) + ["target"]
  
      # if target does not have values 0 and 1, we need to remap, to be able to
      # compute the averages.
      if any(x for x in y.unique() if x not in [0, 1]):
          temp["target"] = np.where(
              temp["target"] == y.unique()[0], 0, 1
          )
  
      self.encoder_dict_ = {}
  
      for var in self.variables_:
          t = temp.groupby(var)["target"].mean()
          t = pd.concat([t, 1 - t], axis=1)
          t.columns = ["p1", "p0"]
  
          if self.encoding_method == "log_ratio":
              if (
                  not t.loc[t["p0"] == 0, :].empty
                  or not t.loc[t["p1"] == 0, :].empty
              ):
                  raise ValueError(
                      "p(0) or p(1) for a category in variable {} is zero, log of "
                      "zero is not defined".format(var)
                  )
              else:
                  self.encoder_dict_[var] = (
                      np.log(t.p1 / t.p0)
                  ).to_dict()
  
          elif self.encoding_method == "ratio":
              if not t.loc[t["p0"] == 0, :].empty:
                  raise ValueError(
                      "p(0) for a category in variable {} is zero, division by 0 is "
                      "not defined".format(var)
                  )
  
              else:
                  self.encoder_dict_[var] = (t.p1 / t.p0).to_dict()
  
      return self
  
file_path: feature_engine/feature_engine/encoding/probability_ratio.py
imports: from typing import List, Union
  import numpy
  import pandas
  from sklearn.utils import deprecated
  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.encoding._helper_functions import check_parameter_unseen
  from feature_engine.dataframe_checks import check_X_y
  from feature_engine.encoding.base_encoder import CategoricalInitMixin, CategoricalMethodsMixin
  from feature_engine.tags import _return_tags
label_desc: Use image node_id 2 for calling the PRatioEncoder obj's underlying member method code with example usage: obj.fit(X, y) and returns: self