Skip to content

Commit 8881395

Browse files
committed
Update files to use _BaseComposition, fix conflicting files
1 parent 023e8b0 commit 8881395

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

sklearn/ensemble/voting_classifier.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,6 @@ def fit(self, X, y, sample_weight=None):
167167
delayed(_parallel_fit_estimator)(clone(clf), X, transformed_y,
168168
sample_weight)
169169
for _, clf in self.estimators if clf is not None)
170-
171170
return self
172171

173172
@property
@@ -210,7 +209,6 @@ def predict(self, X):
210209
arr=predictions.astype('int'))
211210

212211
maj = self.le_.inverse_transform(maj)
213-
214212
return maj
215213

216214
def _collect_probas(self, X):

sklearn/utils/metaestimators.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# Andreas Mueller
44
# License: BSD
55

6+
import numpy as np
7+
from ..utils import safe_indexing
68
from operator import attrgetter
79
from functools import update_wrapper
810
from ..externals import six
@@ -120,3 +122,38 @@ def if_delegate_has_method(delegate):
120122

121123
return lambda fn: _IffHasAttrDescriptor(fn, delegate,
122124
attribute_name=fn.__name__)
125+
126+
127+
def _safe_split(estimator, X, y, indices, train_indices=None):
128+
"""Create subset of dataset and properly handle kernels."""
129+
from ..gaussian_process.kernels import Kernel as GPKernel
130+
131+
if (hasattr(estimator, 'kernel') and callable(estimator.kernel) and
132+
not isinstance(estimator.kernel, GPKernel)):
133+
# cannot compute the kernel values with custom function
134+
raise ValueError("Cannot use a custom kernel function. "
135+
"Precompute the kernel matrix instead.")
136+
137+
if not hasattr(X, "shape"):
138+
if getattr(estimator, "_pairwise", False):
139+
raise ValueError("Precomputed kernels or affinity matrices have "
140+
"to be passed as arrays or sparse matrices.")
141+
X_subset = [X[index] for index in indices]
142+
else:
143+
if getattr(estimator, "_pairwise", False):
144+
# X is a precomputed square kernel matrix
145+
if X.shape[0] != X.shape[1]:
146+
raise ValueError("X should be a square kernel matrix")
147+
if train_indices is None:
148+
X_subset = X[np.ix_(indices, indices)]
149+
else:
150+
X_subset = X[np.ix_(indices, train_indices)]
151+
else:
152+
X_subset = safe_indexing(X, indices)
153+
154+
if y is not None:
155+
y_subset = safe_indexing(y, indices)
156+
else:
157+
y_subset = None
158+
159+
return X_subset, y_subset

0 commit comments

Comments
 (0)