docstr: HSTree (Tree with hierarchical shrinkage applied).
  Hierarchical shinkage is an extremely fast post-hoc regularization method which works on any decision tree (or tree-based ensemble, such as Random Forest).
  It does not modify the tree structure, and instead regularizes the tree by shrinking the prediction over each node towards the sample means of its ancestors (using a single regularization parameter).
  Experiments over a wide variety of datasets show that hierarchical shrinkage substantially increases the predictive performance of individual decision trees and decision-tree ensembles.
  https://arxiv.org/abs/2202.00858
  
  Params
  ------
  estimator_: sklearn tree or tree ensemble model (e.g. RandomForest or GradientBoosting)
      Defaults to CART Classification Tree with 20 max leaf nodes
      Note: this estimator will be directly modified
  
  reg_param: float
      Higher is more regularization (can be arbitrarily large, should not be < 0)
  
  shrinkage_scheme: str
      Experimental: Used to experiment with different forms of shrinkage. options are:
          (i) node_based shrinks based on number of samples in parent node
          (ii) leaf_based only shrinks leaf nodes based on number of leaf samples
          (iii) constant shrinks every node by a constant lambda
  
  max_leaf_nodes: int
      If estimator is None, then max_leaf_nodes is passed to the default decision tree
docstr_tok: ["HSTree","(","Tree","with","hierarchical","shrinkage","applied",")",".","Hierarchical","shinkage","is","an","extremely","fast","post-hoc","regularization","method","which","works","on","any","decision","tree","(","or","tree-based","ensemble",",","such","as","Random","Forest",")",".","It","does","not","modify","the","tree","structure",",","and","instead","regularizes","the","tree","by","shrinking","the","prediction","over","each","node","towards","the","sample","means","of","its","ancestors","(","using","a","single","regularization","parameter",")",".","Experiments","over","a","wide","variety","of","datasets","show","that","hierarchical","shrinkage","substantially","increases","the","predictive","performance","of","individual","decision","trees","and","decision-tree","ensembles",".","https",":","\/\/arxiv.org\/abs\/2202.00858","Params","--","--","--","estimator_",":","sklearn","tree","or","tree","ensemble","model","(","e.g",".","RandomForest","or","GradientBoosting",")","Defaults","to","CART","Classification","Tree","with","20","max","leaf","nodes","Note",":","this","estimator","will","be","directly","modified","reg_param",":","float","Higher","is","more","regularization","(","can","be","arbitrarily","large",",","should","not","be","<","0",")","shrinkage_scheme",":","str","Experimental",":","Used","to","experiment","with","different","forms","of","shrinkage",".","options","are",":","(","i",")","node_based","shrinks","based","on","number","of","samples","in","parent","node","(","ii",")","leaf_based","only","shrinks","leaf","nodes","based","on","number","of","leaf","samples","(","iii",")","constant","shrinks","every","node","by","a","constant","lambda","max_leaf_nodes",":","int","If","estimator","is","None",",","then","max_leaf_nodes","is","passed","to","the","default","decision","tree"]
code: def __init__(
      self,
      estimator_: BaseEstimator = DecisionTreeClassifier(
          max_leaf_nodes=20
      ),
      reg_param: float = 1,
      shrinkage_scheme_: str = "node_based",
      max_leaf_nodes: int = None,
      random_state: int = None,
  ):
      """HSTree (Tree with hierarchical shrinkage applied).
      Hierarchical shinkage is an extremely fast post-hoc regularization method which works on any decision tree (or tree-based ensemble, such as Random Forest).
      It does not modify the tree structure, and instead regularizes the tree by shrinking the prediction over each node towards the sample means of its ancestors (using a single regularization parameter).
      Experiments over a wide variety of datasets show that hierarchical shrinkage substantially increases the predictive performance of individual decision trees and decision-tree ensembles.
      https://arxiv.org/abs/2202.00858
  
      Params
      ------
      estimator_: sklearn tree or tree ensemble model (e.g. RandomForest or GradientBoosting)
          Defaults to CART Classification Tree with 20 max leaf nodes
          Note: this estimator will be directly modified
  
      reg_param: float
          Higher is more regularization (can be arbitrarily large, should not be < 0)
  
      shrinkage_scheme: str
          Experimental: Used to experiment with different forms of shrinkage. options are:
              (i) node_based shrinks based on number of samples in parent node
              (ii) leaf_based only shrinks leaf nodes based on number of leaf samples
              (iii) constant shrinks every node by a constant lambda
  
      max_leaf_nodes: int
          If estimator is None, then max_leaf_nodes is passed to the default decision tree
      """
      super().__init__()
      self.reg_param = reg_param
      self.estimator_ = estimator_
      self.shrinkage_scheme_ = shrinkage_scheme_
      self.random_state = random_state
      if checks.check_is_fitted(self.estimator_):
          self._shrink()
      if max_leaf_nodes is not None:
          self.estimator_.max_leaf_nodes = max_leaf_nodes
          self.estimator_.random_state = random_state
  
imports: import time
  from copy import deepcopy
  from typing import List
  import numpy
  from sklearn import datasets
  from sklearn.base import BaseEstimator, RegressorMixin, ClassifierMixin
  from sklearn.metrics import r2_score, mean_squared_error, log_loss
  from sklearn.model_selection import cross_val_score, KFold
  from sklearn.model_selection import train_test_split
  from sklearn.tree import DecisionTreeRegressor, DecisionTreeClassifier, export_text
  from sklearn.ensemble import GradientBoostingClassifier, GradientBoostingRegressor, RandomForestRegressor
  from imodels.util import checks
  from imodels.util.arguments import check_fit_arguments
  from imodels.util.tree import compute_tree_complexity
label_desc: Use image node_id 1 to create a new HSTree object from inherited base classes: BaseEstimator with example: obj = HSTree(estimator_, reg_param, shrinkage_scheme_, max_leaf_nodes, random_state)