'Apply trees in the ensemble to X, return leaf indices.
.. versionadded:: 0.17
Parameters
X : array-like or sparse matrix, shape = [n_samples, n_features]
The input samples. Internally, its dtype will be converted to
``dtype=np.float32``. If a sparse matrix is provided, it will
be converted to a sparse ``csr_matrix``.
Returns
X_leaves : array_like, shape = [n_samples, n_estimators]
For each datapoint x in X and for each tree in the ensemble,
return the index of the leaf x ends up in each estimator.'

def apply(self, X):

    leaves = super(GradientBoostingRegressor, self).apply(X)
    leaves = leaves.reshape(X.shape[0], self.estimators_.shape[0])
    return leaves
