Question

I saw the command listed as below for sklearn.tree.tree

from ._tree import Criterion, Splitter, Tree
from . import _tree

Yet in the same tree folder I cannot find any file or class named _tree. Can anyone tell me where exactly I can find this class?

Was it helpful?

Solution

The module you are looking for is written in Cython. The corresponding file is called _tree.pyx. It can be found in .../scikit-learn/sklearn/tree/_tree.pyx, if you have the scikit learn sources, e.g. in form of the git repo, on your computer.

Cython is translated to C code, which can be found in _tree.c.

The compiled C code is what is imported in the lines you found, and the corresponding file is called _tree.so. In a typical scikit-learn installation, this may be the only file you find. It is not human-readable, so if you are interested in the source, check it out here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top