Source code for modeva.models.wrappers.builtin.decision_tree

from sklearn.tree import DecisionTreeRegressor, DecisionTreeClassifier

from ..sklearn import MoSKLearnRegressor, MoSKLearnClassifier
from ....testsuite.interpret.decision_tree import InterpretDecisionTree
from ....utils.helper import limit_function_for_trial_license


[docs] class MoDecisionTreeRegressor(MoSKLearnRegressor): """ A lightweight wrapper of :class:`sklearn.tree.DecisionTreeRegressor`. Parameters ---------- name : str, default=None Identifier for the model instance. *args Variable length argument list passed to the underlying DecisionTreeRegressor model. **kwargs Arbitrary keyword arguments passed to the underlying DecisionTreeRegressor model. """ def __init__(self, name: str = None, *args, **kwargs): super().__init__(name=name, estimator=DecisionTreeRegressor(*args, **kwargs))
[docs] def get_params(self, deep=True): """ Get parameters for this estimator. Parameters ---------- deep : bool, default=True If True, will return the parameters for this estimator and contained subobjects that are estimators. Returns ------- params : dict Parameter names mapped to their values. """ return self.estimator.get_params(deep=deep)
[docs] def interpret(self, dataset): """ Interpret the decision tree with given dataset. Parameters ---------- dataset : DataSet instance The dataset for interpreting the model. Returns ------- An instance of InterpretDecisionTree """ if not dataset.is_built_in(): limit_function_for_trial_license() return InterpretDecisionTree(dataset=dataset, model=self)
[docs] class MoDecisionTreeClassifier(MoSKLearnClassifier): """ A lightweight wrapper of :class:`sklearn.tree.DecisionTreeClassifier`. Parameters ---------- name : str, default=None Identifier for the model instance. *args Variable length argument list passed to the underlying DecisionTreeClassifier model. **kwargs Arbitrary keyword arguments passed to the underlying DecisionTreeClassifier model. """ def __init__(self, name: str = None, *args, **kwargs): super().__init__(name=name, estimator=DecisionTreeClassifier(*args, **kwargs))
[docs] def get_params(self, deep=True): """ Get parameters for this estimator. Parameters ---------- deep : bool, default=True If True, will return the parameters for this estimator and contained subobjects that are estimators. Returns ------- params : dict Parameter names mapped to their values. """ return self.estimator.get_params(deep=deep)
[docs] def interpret(self, dataset): """ Interpret the decision tree with given dataset. Parameters ---------- dataset : DataSet instance The dataset for interpreting the model. Returns ------- An instance of InterpretDecisionTree """ if not dataset.is_built_in(): limit_function_for_trial_license() return InterpretDecisionTree(dataset=dataset, model=self)