@@ -375,7 +375,7 @@ def predict(self, X, check_input=True):
375375 else :
376376 return proba [:, :, 0 ]
377377
378- def apply (self , X ):
378+ def apply (self , X , check_input = True ):
379379 """
380380 Returns the index of the leaf that each sample is predicted as.
381381
@@ -386,6 +386,10 @@ def apply(self, X):
386386 ``dtype=np.float32`` and if a sparse matrix is provided
387387 to a sparse ``csr_matrix``.
388388
389+ check_input : boolean, (default=True)
390+ Allow to bypass several input checking.
391+ Don't use this parameter unless you know what you do.
392+
389393 Returns
390394 -------
391395 X_leaves : array_like, shape = [n_samples,]
@@ -398,7 +402,15 @@ def apply(self, X):
398402 raise NotFittedError ("Estimator not fitted, "
399403 "call `fit` before `apply`." )
400404
401- X = check_array (X , dtype = DTYPE , accept_sparse = "csr" )
405+ if check_input :
406+ X = check_array (X , dtype = DTYPE , accept_sparse = "csr" )
407+
408+ n_features = X .shape [1 ]
409+ if self .n_features_ != n_features :
410+ raise ValueError ("Number of features of the model must "
411+ " match the input. Model n_features is %s and "
412+ " input n_features is %s "
413+ % (self .n_features_ , n_features ))
402414
403415 return self .tree_ .apply (X )
404416
0 commit comments