Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""Train the ensemble on the training set.
Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_features)
The training input samples.
y : array-like of shape (n_samples,)
The target values.
Returns
-------
self : object
Returns self.
"""
check_target_type(y)
# RandomUnderSampler is not supporting sample_weight. We need to pass
# None.
return self._fit(X, y, self.max_samples, sample_weight=None)
The training input samples. Sparse matrix can be CSC, CSR, COO,
DOK, or LIL. DOK and LIL are converted to CSR.
y : array-like of shape (n_samples,)
The target values (class labels).
sample_weight : array-like of shape (n_samples,), default=None
Sample weights. If None, the sample weights are initialized to
``1 / n_samples``.
Returns
-------
self : object
Returns self.
"""
check_target_type(y)
self.samplers_ = []
self.pipelines_ = []
super().fit(X, y, sample_weight)
return self
# store information to build dataframe
self._X_columns = X.columns
self._X_dtypes = X.dtypes
else:
self._X_columns = None
self._X_dtypes = None
if hasattr(y, "loc"):
# store information to build a series
self._y_name = y.name
self._y_dtype = y.dtype
else:
self._y_name = None
self._y_dtype = None
y, binarize_y = check_target_type(y, indicate_one_vs_all=True)
X = check_array(X, accept_sparse=["csr", "csc"], dtype=None,
force_all_finite=False)
y = check_array(
y, accept_sparse=["csr", "csc"], dtype=None, ensure_2d=False
)
check_consistent_length(X, y)
return X, y, binarize_y
# store information to build dataframe
self._X_columns = X.columns
self._X_dtypes = X.dtypes
else:
self._X_columns = None
self._X_dtypes = None
if hasattr(y, "loc"):
# store information to build a series
self._y_name = y.name
self._y_dtype = y.dtype
else:
self._y_name = None
self._y_dtype = None
y, binarize_y = check_target_type(y, indicate_one_vs_all=True)
X, y = check_X_y(X, y, accept_sparse=["csr", "csc"], dtype=None)
return X, y, binarize_y
@staticmethod
def _check_X_y(X, y):
y, binarize_y = check_target_type(y, indicate_one_vs_all=True)
X, y = check_X_y(X, y, accept_sparse=['csr', 'csc'])
return X, y, binarize_y
def _fit_resample(self, X, y):
self._validate_estimator()
y = check_target_type(y)
X, y = check_X_y(X, y, accept_sparse=["csr", "csc"])
self.sampling_strategy_ = self.sampling_strategy
X_res, y_res = self.smote_.fit_resample(X, y)
return self.enn_.fit_resample(X_res, y_res)
def _check_X_y(self, X, y):
if self.accept_sparse:
X, y = check_X_y(X, y, accept_sparse=['csr', 'csc'])
else:
X, y = check_X_y(X, y, accept_sparse=False)
y = check_target_type(y)
return X, y
# store information to build dataframe
self._X_columns = X.columns
self._X_dtypes = X.dtypes
else:
self._X_columns = None
self._X_dtypes = None
if hasattr(y, "loc"):
# store information to build a series
self._y_name = y.name
self._y_dtype = y.dtype
else:
self._y_name = None
self._y_dtype = None
y, binarize_y = check_target_type(y, indicate_one_vs_all=True)
X = check_array(X, accept_sparse=["csr", "csc"], dtype=None,
force_all_finite=False)
y = check_array(
y, accept_sparse=["csr", "csc"], dtype=None, ensure_2d=False
)
return X, y, binarize_y