Concrete estimators: combining BaseEstimator with role mixins
DecisionTreeClassifier shows the standard scikit-learn estimator recipe: inherit BaseEstimator (params, tags, repr) plus a role mixin like ClassifierMixin (score(), classifier tag) through BaseDecisionTree, then implement only the estimator-specific fit/predict logic. Input validation is delegated to sklearn.utils.validation helpers (validate_data, check_is_fitted) and the actual tree construction/inference is delegated to compiled Cython objects (Tree, DepthFirstTreeBuilder/BestFirstTreeBuilder). Learning this composition — mixin for role contract, BaseEstimator for plumbing, thin Python fit/predict wrapping a validated array and a compiled core — is the template for reading or writing any other estimator in the codebase.
class BaseDecisionTree(MultiOutputMixin, BaseEstimator, metaclass=ABCMeta): """Base class for decision trees. Warning: This class should not be used directly. Use derived classes instead. """
sklearn/tree/_classes.py · lines 89–94class DecisionTreeClassifier(ClassifierMixin, BaseDecisionTree): — putting ClassifierMixin first so its score()/tag overrides take priority over the base class's defaults.check_is_fitted(self) X = self._validate_X_predict(X, check_input) proba = self.tree_.predict(X) n_samples = X.shape[0] # Classification if is_classifier(self): if self.n_outputs_ == 1: return self.classes_.take(np.argmax(proba, axis=1), axis=0)
sklearn/tree/_classes.py · lines 520–528Check your understanding
Answered in place — nothing is graded, everything is explained. 0 / 2 passed
Why is `DecisionTreeClassifier` declared as `class DecisionTreeClassifier(ClassifierMixin, BaseDecisionTree):` with the mixin listed first?
Where does the actual tree-splitting computation happen during DecisionTreeClassifier.fit()?