#NEWLINE# def apply( self , X ) : #NEWLINE# #INDENT# 'Apply trees in the ensemble to X, return leaf indices.\n\n        .. versionadded:: 0.17\n\n        Parameters\n        ----------\n        X : array-like or sparse matrix, shape = [n_samples, n_features]\n            The input samples. Internally, it will be converted to\n            ``dtype=np.float32`` and if a sparse matrix is provided\n            to a sparse ``csr_matrix``.\n\n        Returns\n        -------\n        X_leaves : array_like, shape = [n_samples, n_estimators, n_classes]\n            For each datapoint x in X and for each tree in the ensemble,\n            return the index of the leaf x ends up in each estimator.\n            In the case of binary classification n_classes is 1.\n        ' #NEWLINE# self . _check_initialized ( ) #NEWLINE# X = self . estimators_ [ ( 0 , 0 ) ] . _validate_X_predict ( X , check_input = True ) #NEWLINE# ( n_estimators , n_classes ) = self . estimators_ . shape #NEWLINE# leaves = np . zeros ( ( X . shape [ 0 ] , n_estimators , n_classes ) ) #NEWLINE# for i in range ( n_estimators ) : #NEWLINE# #INDENT# for j in range ( n_classes ) : #NEWLINE# #INDENT# estimator = self . estimators_ [ ( i , j ) ] #NEWLINE# leaves [ : , i , j ] = estimator . apply ( X , check_input = False ) #NEWLINE# #UNINDENT# #UNINDENT# return leaves