def transform(self, X, y=None):
"""Binarize X based on the fitted cut points."""
# scikit-learn checks
X = check_array(X)
if self.cut_points is None:
raise NotFittedError('Estimator not fitted, call `fit` before exploiting the model.')
if X.shape[1] != len(self.cut_points):
raise ValueError("Provided array's dimensions do not match with the ones from the "
"array `fit` was called on.")
binned = np.array([
np.digitize(x, self.cut_points[i])
if len(self.cut_points[i]) > 0
else np.zeros(x.shape)
for i, x in enumerate(X.T)
]).T
return binned
评论列表
文章目录