Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""
This class implements the regression tree in CART that uses
the minimum variance criterion.
"""
# Authors: Yubin Park
# License: Apache License 2.0
from bonsai.core.bonsaic import Bonsai
import numpy as np
import logging
class RegTree(Bonsai):
def __init__(self,
max_depth=5,
min_samples_split=2,
min_samples_leaf=1,
min_varsum_decrease=0.0,
subsample=1.0,
random_state=1234,
n_jobs=-1,
**kwarg):
self.max_depth=max_depth
self.min_samples_split = min_samples_split
self.min_samples_leaf = min_samples_leaf
self.min_varsum_decrease = min_varsum_decrease
def find_split(avc):
"""
This class implements a modified version of Alpha Tree that appeared in
- the origial: https://ieeexplore.ieee.org/document/6399474/
- closer to the implementation: https://arxiv.org/abs/1606.05325
"""
# Authors: Yubin Park
# License: Apache License 2.0
from bonsai.core.bonsaic import Bonsai
import numpy as np
class AlphaTree(Bonsai):
def __init__(self,
alpha=1.0,
max_depth=5,
min_samples_split=2,
min_samples_leaf=1,
**kwarg):
self.alpha = alpha
self.max_depth=max_depth
self.min_samples_split = min_samples_split
self.min_samples_leaf = min_samples_leaf
def find_split(avc):
PRECISION = 1e-12
"""
This class implements a tree with the Friedman's splitting criterion
that appeared in:
- https://statweb.stanford.edu/~jhf/ftp/trebst.pdf
FYI, this is the default splitting criterion for Scikit-Learn GBM.
"""
# Authors: Yubin Park
# License: Apache License 2.0
from bonsai.core.bonsaic import Bonsai
import numpy as np
import logging
class FriedmanTree(Bonsai):
def __init__(self,
max_depth=5,
min_samples_split=2,
min_samples_leaf=1,
subsample=1.0,
random_state=1234,
n_jobs=-1,
**kwarg):
self.max_depth=max_depth
self.min_samples_split = min_samples_split
self.min_samples_leaf = min_samples_leaf
def find_split(avc):
if avc.shape[0] == 0:
"""
This class implements the XGBoost base tree that appeared in:
- https://arxiv.org/abs/1603.02754
"""
# Authors: Yubin Park
# License: Apache License 2.0
from bonsai.core.bonsaic import Bonsai
import numpy as np
class XGBTree(Bonsai):
def __init__(self,
max_depth=5,
min_samples_split=2,
min_samples_leaf=1,
subsample=1.0,
subsample_splts=1.0,
reg_lambda=1e-2, # regularization
obj_tolerance=1e-2,
random_state=1234,
distribution="gaussian",
n_jobs=-1,
**kwarg):
self.max_depth=max_depth
self.min_samples_split = min_samples_split
self.min_samples_leaf = min_samples_leaf