'Returns the index of the leaf that each sample is predicted as.
.. versionadded:: 0.17
Parameters
X : array_like or sparse matrix, shape = [n_samples, n_features]
The input samples. Internally, it will be converted to
``dtype=np.float32`` and if a sparse matrix is provided
to a sparse ``csr_matrix``.
check_input : boolean, (default=True)
Allow to bypass several input checking.
Don\'t use this parameter unless you know what you do.
Returns
X_leaves : array_like, shape = [n_samples,]
For each datapoint x in X, return the index of the leaf x
ends up in. Leaves are numbered within
``[0; self.tree_.node_count)``, possibly with gaps in the
numbering.'

def apply(self, X, check_input=True):

    check_is_fitted(self, 'tree_')
    X = self._validate_X_predict(X, check_input)
    return self.tree_.apply(X)
