class_docstr: RIPPER (Repeated Incremental Pruning to Produce Error Reduction) is a heuristic rule induction algorithm
  based on separate-and-conquer. The explainer outputs a rule set in Disjunctive Normal Form (DNF) for a single
  target concept.
  
  References:
      .. [#ML95] `William W Cohen, "Fast Effective Rule Induction"
          Machine Learning: Proceedings of the Twelfth International Conference, 1995.
          <http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.107.2612&rep=rep1&type=pdf>
class_docstr_tok: ["RIPPER","(","Repeated","Incremental","Pruning","to","Produce","Error","Reduction",")","is","a","heuristic","rule","induction","algorithm","based","on","separate-and-conquer",".","The","explainer","outputs","a","rule","set","in","Disjunctive","Normal","Form","(","DNF",")","for","a","single","target","concept",".","References",":","..","[","#","ML95","]","`","William","W","Cohen",",","``","Fast","Effective","Rule","Induction","''","Machine","Learning",":","Proceedings","of","the","Twelfth","International","Conference",",","1995",".","<","http",":","\/\/citeseerx.ist.psu.edu\/viewdoc\/download","?","doi=10.1.1.107.2612","&","rep=rep1","&","type=pdf",">"]
docstr: The replacement step for RIPPER optimization
  
  Parameters
  ----------
      pos: np.ndarray
          Positive instances
      neg: np.ndarray
          Negative instances
      rules : list
          Rules that needs to be optimized
      index : int
          Index of selected rule
      ratio : float
          The percentage of pruning data
  
  Returns
  -------
  list
      A replacement rule
docstr_tok: ["The","replacement","step","for","RIPPER","optimization","Parameters","--","--","--","--","--","pos",":","np.ndarray","Positive","instances","neg",":","np.ndarray","Negative","instances","rules",":","list","Rules","that","needs","to","be","optimized","index",":","int","Index","of","selected","rule","ratio",":","float","The","percentage","of","pruning","data","Returns","--","--","--","-","list","A","replacement","rule"]
code: def _replacement(
      self,
      pos: np.ndarray,
      neg: np.ndarray,
      rules,
      index: int,
      ratio: float = 2 / 3,
  ):
      """
      The replacement step for RIPPER optimization
  
      Parameters
      ----------
          pos: np.ndarray
              Positive instances
          neg: np.ndarray
              Negative instances
          rules : list
              Rules that needs to be optimized
          index : int
              Index of selected rule
          ratio : float
              The percentage of pruning data
  
      Returns
      -------
      list
          A replacement rule
      """
      rest = rules[:index] + rules[index + 1 :]
  
      new_pos = _unbound_rule_list(pos, rest)
  
      if len(new_pos) > 2:
          pos_grow, pos_prune, neg_grow, neg_prune = _split_instances(
              new_pos, neg, ratio, self.random_state
          )
  
          new_rule = self._grow_rule(pos=pos_grow, neg=neg_grow)
  
          pruned_rule = _pruning_optimization(
              pos_prune=pos_prune,
              neg_prune=neg_prune,
              rule=new_rule,
              rules=rules,
              index=index,
          )
          return pruned_rule
      else:
          return rules[index]
  
imports: import logging
  import logging.config
  from collections import OrderedDict
  import numpy
  from aix360.algorithms.dise import DISExplainer
  from aix360.algorithms.rule_induction.ripper.base import _encoding_for_parallel, init_encoder, encode_nominal, _split_instances
  from aix360.algorithms.rule_induction.ripper.binding import append_literal, _bind_literal, _bind_rule, unbound_rule_list_index, _unbound, _unbound_rule_list, _rule_list_predict, LE, EQ, _find_best_literal, Literal, _filter_contradicted_instances
  from aix360.algorithms.rule_induction.ripper.mdl import _mdl
  from aix360.algorithms.rule_induction.ripper.pruning import _pruning_irep, _minimize_rule_list, _pruning_optimization
  from aix360.algorithms.rule_induction.trxf.core.conjunction import Conjunction
  from aix360.algorithms.rule_induction.trxf.core.dnf_ruleset import DnfRuleSet
  from aix360.algorithms.rule_induction.trxf.core.feature import Feature
  from aix360.algorithms.rule_induction.trxf.core.predicate import Predicate, Relation
  from pandas import DataFrame, Series
label_desc: Use image node_id 9 for calling the RipperExplainer obj's underlying member method code with example usage: obj._replacement(pos, neg, rules, index, ratio) and returns: pruned_rule, rules