code
stringlengths
66
870k
docstring
stringlengths
19
26.7k
func_name
stringlengths
1
138
language
stringclasses
1 value
repo
stringlengths
7
68
path
stringlengths
5
324
url
stringlengths
46
389
license
stringclasses
7 values
def iteration_ends(self, time_step): """Perform updates to learning rate and potential other states at the end of an iteration Parameters ---------- time_step : int number of training samples trained on so far, used to update learning rate for 'invscaling...
Perform updates to learning rate and potential other states at the end of an iteration Parameters ---------- time_step : int number of training samples trained on so far, used to update learning rate for 'invscaling'
iteration_ends
python
scikit-learn/scikit-learn
sklearn/neural_network/_stochastic_optimizers.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/neural_network/_stochastic_optimizers.py
BSD-3-Clause
def _get_updates(self, grads): """Get the values used to update params with given gradients Parameters ---------- grads : list, length = len(coefs_) + len(intercepts_) Containing gradients with respect to coefs_ and intercepts_ in MLP model. So length should be a...
Get the values used to update params with given gradients Parameters ---------- grads : list, length = len(coefs_) + len(intercepts_) Containing gradients with respect to coefs_ and intercepts_ in MLP model. So length should be aligned with params Returns ...
_get_updates
python
scikit-learn/scikit-learn
sklearn/neural_network/_stochastic_optimizers.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/neural_network/_stochastic_optimizers.py
BSD-3-Clause
def test_poisson_loss(global_random_seed): """Test Poisson loss against well tested HalfPoissonLoss.""" n = 1000 rng = np.random.default_rng(global_random_seed) y_true = rng.integers(low=0, high=10, size=n).astype(float) y_raw = rng.standard_normal(n) y_pred = np.exp(y_raw) sw = rng.uniform(...
Test Poisson loss against well tested HalfPoissonLoss.
test_poisson_loss
python
scikit-learn/scikit-learn
sklearn/neural_network/tests/test_base.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/neural_network/tests/test_base.py
BSD-3-Clause
def test_mlp_loading_from_joblib_partial_fit(tmp_path): """Loading from MLP and partial fitting updates weights. Non-regression test for #19626.""" pre_trained_estimator = MLPRegressor( hidden_layer_sizes=(42,), random_state=42, learning_rate_init=0.01, max_iter=200 ) features, target = [[2]...
Loading from MLP and partial fitting updates weights. Non-regression test for #19626.
test_mlp_loading_from_joblib_partial_fit
python
scikit-learn/scikit-learn
sklearn/neural_network/tests/test_mlp.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/neural_network/tests/test_mlp.py
BSD-3-Clause
def test_preserve_feature_names(Estimator): """Check that feature names are preserved when early stopping is enabled. Feature names are required for consistency checks during scoring. Non-regression test for gh-24846 """ pd = pytest.importorskip("pandas") rng = np.random.RandomState(0) X ...
Check that feature names are preserved when early stopping is enabled. Feature names are required for consistency checks during scoring. Non-regression test for gh-24846
test_preserve_feature_names
python
scikit-learn/scikit-learn
sklearn/neural_network/tests/test_mlp.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/neural_network/tests/test_mlp.py
BSD-3-Clause
def test_mlp_warm_start_with_early_stopping(MLPEstimator): """Check that early stopping works with warm start.""" mlp = MLPEstimator( max_iter=10, random_state=0, warm_start=True, early_stopping=True ) with warnings.catch_warnings(): warnings.simplefilter("ignore", ConvergenceWarning) ...
Check that early stopping works with warm start.
test_mlp_warm_start_with_early_stopping
python
scikit-learn/scikit-learn
sklearn/neural_network/tests/test_mlp.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/neural_network/tests/test_mlp.py
BSD-3-Clause
def test_mlp_warm_start_no_convergence(MLPEstimator, solver): """Check that we stop the number of iteration at `max_iter` when warm starting. Non-regression test for: https://github.com/scikit-learn/scikit-learn/issues/24764 """ model = MLPEstimator( solver=solver, warm_start=True, ...
Check that we stop the number of iteration at `max_iter` when warm starting. Non-regression test for: https://github.com/scikit-learn/scikit-learn/issues/24764
test_mlp_warm_start_no_convergence
python
scikit-learn/scikit-learn
sklearn/neural_network/tests/test_mlp.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/neural_network/tests/test_mlp.py
BSD-3-Clause
def test_mlp_partial_fit_after_fit(MLPEstimator): """Check partial fit does not fail after fit when early_stopping=True. Non-regression test for gh-25693. """ mlp = MLPEstimator(early_stopping=True, random_state=0).fit(X_iris, y_iris) msg = "partial_fit does not support early_stopping=True" wi...
Check partial fit does not fail after fit when early_stopping=True. Non-regression test for gh-25693.
test_mlp_partial_fit_after_fit
python
scikit-learn/scikit-learn
sklearn/neural_network/tests/test_mlp.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/neural_network/tests/test_mlp.py
BSD-3-Clause
def test_mlp_diverging_loss(): """Test that a diverging model does not raise errors when early stopping is enabled. Non-regression test for: https://github.com/scikit-learn/scikit-learn/issues/29504 """ mlp = MLPRegressor( hidden_layer_sizes=100, activation="identity", solve...
Test that a diverging model does not raise errors when early stopping is enabled. Non-regression test for: https://github.com/scikit-learn/scikit-learn/issues/29504
test_mlp_diverging_loss
python
scikit-learn/scikit-learn
sklearn/neural_network/tests/test_mlp.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/neural_network/tests/test_mlp.py
BSD-3-Clause
def test_mlp_vs_poisson_glm_equivalent(global_random_seed): """Test MLP with Poisson loss and no hidden layer equals GLM.""" n = 100 rng = np.random.default_rng(global_random_seed) X = np.linspace(0, 1, n) y = rng.poisson(np.exp(X + 1)) X = X.reshape(n, -1) glm = PoissonRegressor(alpha=0, to...
Test MLP with Poisson loss and no hidden layer equals GLM.
test_mlp_vs_poisson_glm_equivalent
python
scikit-learn/scikit-learn
sklearn/neural_network/tests/test_mlp.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/neural_network/tests/test_mlp.py
BSD-3-Clause
def test_minimum_input_sample_size(): """Check error message when the validation set is too small.""" X, y = make_regression(n_samples=2, n_features=5, random_state=0) model = MLPRegressor(early_stopping=True, random_state=0) with pytest.raises(ValueError, match="The validation set is too small"): ...
Check error message when the validation set is too small.
test_minimum_input_sample_size
python
scikit-learn/scikit-learn
sklearn/neural_network/tests/test_mlp.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/neural_network/tests/test_mlp.py
BSD-3-Clause
def _is_constant_feature(var, mean, n_samples): """Detect if a feature is indistinguishable from a constant feature. The detection is based on its computed variance and on the theoretical error bounds of the '2 pass algorithm' for variance computation. See "Algorithms for computing the sample variance...
Detect if a feature is indistinguishable from a constant feature. The detection is based on its computed variance and on the theoretical error bounds of the '2 pass algorithm' for variance computation. See "Algorithms for computing the sample variance: analysis and recommendations", by Chan, Golub, an...
_is_constant_feature
python
scikit-learn/scikit-learn
sklearn/preprocessing/_data.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_data.py
BSD-3-Clause
def _handle_zeros_in_scale(scale, copy=True, constant_mask=None): """Set scales of near constant features to 1. The goal is to avoid division by very small or zero values. Near constant features are detected automatically by identifying scales close to machine precision unless they are precomputed by ...
Set scales of near constant features to 1. The goal is to avoid division by very small or zero values. Near constant features are detected automatically by identifying scales close to machine precision unless they are precomputed by the caller and passed with the `constant_mask` kwarg. Typically ...
_handle_zeros_in_scale
python
scikit-learn/scikit-learn
sklearn/preprocessing/_data.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_data.py
BSD-3-Clause
def scale(X, *, axis=0, with_mean=True, with_std=True, copy=True): """Standardize a dataset along any axis. Center to the mean and component wise scale to unit variance. Read more in the :ref:`User Guide <preprocessing_scaler>`. Parameters ---------- X : {array-like, sparse matrix} of shape (...
Standardize a dataset along any axis. Center to the mean and component wise scale to unit variance. Read more in the :ref:`User Guide <preprocessing_scaler>`. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The data to center and scale. axis : {...
scale
python
scikit-learn/scikit-learn
sklearn/preprocessing/_data.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_data.py
BSD-3-Clause
def _reset(self): """Reset internal data-dependent state of the scaler, if necessary. __init__ parameters are not touched. """ # Checking one attribute is enough, because they are all set together # in partial_fit if hasattr(self, "scale_"): del self.scale_ ...
Reset internal data-dependent state of the scaler, if necessary. __init__ parameters are not touched.
_reset
python
scikit-learn/scikit-learn
sklearn/preprocessing/_data.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_data.py
BSD-3-Clause
def fit(self, X, y=None): """Compute the minimum and maximum to be used for later scaling. Parameters ---------- X : array-like of shape (n_samples, n_features) The data used to compute the per-feature minimum and maximum used for later scaling along the features...
Compute the minimum and maximum to be used for later scaling. Parameters ---------- X : array-like of shape (n_samples, n_features) The data used to compute the per-feature minimum and maximum used for later scaling along the features axis. y : None ...
fit
python
scikit-learn/scikit-learn
sklearn/preprocessing/_data.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_data.py
BSD-3-Clause
def partial_fit(self, X, y=None): """Online computation of min and max on X for later scaling. All of X is processed as a single batch. This is intended for cases when :meth:`fit` is not feasible due to very large number of `n_samples` or because X is read from a continuous stream. ...
Online computation of min and max on X for later scaling. All of X is processed as a single batch. This is intended for cases when :meth:`fit` is not feasible due to very large number of `n_samples` or because X is read from a continuous stream. Parameters ---------- X ...
partial_fit
python
scikit-learn/scikit-learn
sklearn/preprocessing/_data.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_data.py
BSD-3-Clause
def transform(self, X): """Scale features of X according to feature_range. Parameters ---------- X : array-like of shape (n_samples, n_features) Input data that will be transformed. Returns ------- Xt : ndarray of shape (n_samples, n_features) ...
Scale features of X according to feature_range. Parameters ---------- X : array-like of shape (n_samples, n_features) Input data that will be transformed. Returns ------- Xt : ndarray of shape (n_samples, n_features) Transformed data.
transform
python
scikit-learn/scikit-learn
sklearn/preprocessing/_data.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_data.py
BSD-3-Clause
def inverse_transform(self, X): """Undo the scaling of X according to feature_range. Parameters ---------- X : array-like of shape (n_samples, n_features) Input data that will be transformed. It cannot be sparse. Returns ------- X_original : ndarray ...
Undo the scaling of X according to feature_range. Parameters ---------- X : array-like of shape (n_samples, n_features) Input data that will be transformed. It cannot be sparse. Returns ------- X_original : ndarray of shape (n_samples, n_features) ...
inverse_transform
python
scikit-learn/scikit-learn
sklearn/preprocessing/_data.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_data.py
BSD-3-Clause
def minmax_scale(X, feature_range=(0, 1), *, axis=0, copy=True): """Transform features by scaling each feature to a given range. This estimator scales and translates each feature individually such that it is in the given range on the training set, i.e. between zero and one. The transformation is g...
Transform features by scaling each feature to a given range. This estimator scales and translates each feature individually such that it is in the given range on the training set, i.e. between zero and one. The transformation is given by (when ``axis=0``):: X_std = (X - X.min(axis=0)) / (X.ma...
minmax_scale
python
scikit-learn/scikit-learn
sklearn/preprocessing/_data.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_data.py
BSD-3-Clause
def fit(self, X, y=None, sample_weight=None): """Compute the mean and std to be used for later scaling. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The data used to compute the mean and standard deviation used for later ...
Compute the mean and std to be used for later scaling. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The data used to compute the mean and standard deviation used for later scaling along the features axis. y : None ...
fit
python
scikit-learn/scikit-learn
sklearn/preprocessing/_data.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_data.py
BSD-3-Clause
def partial_fit(self, X, y=None, sample_weight=None): """Online computation of mean and std on X for later scaling. All of X is processed as a single batch. This is intended for cases when :meth:`fit` is not feasible due to very large number of `n_samples` or because X is read from a co...
Online computation of mean and std on X for later scaling. All of X is processed as a single batch. This is intended for cases when :meth:`fit` is not feasible due to very large number of `n_samples` or because X is read from a continuous stream. The algorithm for incremental mean and ...
partial_fit
python
scikit-learn/scikit-learn
sklearn/preprocessing/_data.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_data.py
BSD-3-Clause
def transform(self, X, copy=None): """Perform standardization by centering and scaling. Parameters ---------- X : {array-like, sparse matrix of shape (n_samples, n_features) The data used to scale along the features axis. copy : bool, default=None Copy th...
Perform standardization by centering and scaling. Parameters ---------- X : {array-like, sparse matrix of shape (n_samples, n_features) The data used to scale along the features axis. copy : bool, default=None Copy the input X or not. Returns ---...
transform
python
scikit-learn/scikit-learn
sklearn/preprocessing/_data.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_data.py
BSD-3-Clause
def inverse_transform(self, X, copy=None): """Scale back the data to the original representation. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The data used to scale along the features axis. copy : bool, default=None ...
Scale back the data to the original representation. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The data used to scale along the features axis. copy : bool, default=None Copy the input `X` or not. Returns ...
inverse_transform
python
scikit-learn/scikit-learn
sklearn/preprocessing/_data.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_data.py
BSD-3-Clause
def fit(self, X, y=None): """Compute the maximum absolute value to be used for later scaling. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The data used to compute the per-feature minimum and maximum used for later scalin...
Compute the maximum absolute value to be used for later scaling. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The data used to compute the per-feature minimum and maximum used for later scaling along the features axis. y...
fit
python
scikit-learn/scikit-learn
sklearn/preprocessing/_data.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_data.py
BSD-3-Clause
def partial_fit(self, X, y=None): """Online computation of max absolute value of X for later scaling. All of X is processed as a single batch. This is intended for cases when :meth:`fit` is not feasible due to very large number of `n_samples` or because X is read from a continuous strea...
Online computation of max absolute value of X for later scaling. All of X is processed as a single batch. This is intended for cases when :meth:`fit` is not feasible due to very large number of `n_samples` or because X is read from a continuous stream. Parameters ---------- ...
partial_fit
python
scikit-learn/scikit-learn
sklearn/preprocessing/_data.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_data.py
BSD-3-Clause
def transform(self, X): """Scale the data. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The data that should be scaled. Returns ------- X_tr : {ndarray, sparse matrix} of shape (n_samples, n_features) ...
Scale the data. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The data that should be scaled. Returns ------- X_tr : {ndarray, sparse matrix} of shape (n_samples, n_features) Transformed array.
transform
python
scikit-learn/scikit-learn
sklearn/preprocessing/_data.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_data.py
BSD-3-Clause
def inverse_transform(self, X): """Scale back the data to the original representation. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The data that should be transformed back. Returns ------- X_original : {ndar...
Scale back the data to the original representation. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The data that should be transformed back. Returns ------- X_original : {ndarray, sparse matrix} of shape (n_samples, n_...
inverse_transform
python
scikit-learn/scikit-learn
sklearn/preprocessing/_data.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_data.py
BSD-3-Clause
def maxabs_scale(X, *, axis=0, copy=True): """Scale each feature to the [-1, 1] range without breaking the sparsity. This estimator scales each feature individually such that the maximal absolute value of each feature in the training set will be 1.0. This scaler can also be applied to sparse CSR o...
Scale each feature to the [-1, 1] range without breaking the sparsity. This estimator scales each feature individually such that the maximal absolute value of each feature in the training set will be 1.0. This scaler can also be applied to sparse CSR or CSC matrices. Parameters ---------- ...
maxabs_scale
python
scikit-learn/scikit-learn
sklearn/preprocessing/_data.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_data.py
BSD-3-Clause
def fit(self, X, y=None): """Compute the median and quantiles to be used for scaling. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The data used to compute the median and quantiles used for later scaling along the feature...
Compute the median and quantiles to be used for scaling. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The data used to compute the median and quantiles used for later scaling along the features axis. y : Ignored ...
fit
python
scikit-learn/scikit-learn
sklearn/preprocessing/_data.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_data.py
BSD-3-Clause
def transform(self, X): """Center and scale the data. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The data used to scale along the specified axis. Returns ------- X_tr : {ndarray, sparse matrix} of shape (n_...
Center and scale the data. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The data used to scale along the specified axis. Returns ------- X_tr : {ndarray, sparse matrix} of shape (n_samples, n_features) Tr...
transform
python
scikit-learn/scikit-learn
sklearn/preprocessing/_data.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_data.py
BSD-3-Clause
def inverse_transform(self, X): """Scale back the data to the original representation. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The rescaled data to be transformed back. Returns ------- X_original : {ndar...
Scale back the data to the original representation. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The rescaled data to be transformed back. Returns ------- X_original : {ndarray, sparse matrix} of shape (n_samples, n_...
inverse_transform
python
scikit-learn/scikit-learn
sklearn/preprocessing/_data.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_data.py
BSD-3-Clause
def robust_scale( X, *, axis=0, with_centering=True, with_scaling=True, quantile_range=(25.0, 75.0), copy=True, unit_variance=False, ): """Standardize a dataset along any axis. Center to the median and component wise scale according to the interquartile range. Read more...
Standardize a dataset along any axis. Center to the median and component wise scale according to the interquartile range. Read more in the :ref:`User Guide <preprocessing_scaler>`. Parameters ---------- X : {array-like, sparse matrix} of shape (n_sample, n_features) The data to center...
robust_scale
python
scikit-learn/scikit-learn
sklearn/preprocessing/_data.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_data.py
BSD-3-Clause
def normalize(X, norm="l2", *, axis=1, copy=True, return_norm=False): """Scale input vectors individually to unit norm (vector length). Read more in the :ref:`User Guide <preprocessing_normalization>`. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) T...
Scale input vectors individually to unit norm (vector length). Read more in the :ref:`User Guide <preprocessing_normalization>`. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The data to normalize, element by element. scipy.sparse matrices shoul...
normalize
python
scikit-learn/scikit-learn
sklearn/preprocessing/_data.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_data.py
BSD-3-Clause
def transform(self, X, copy=None): """Scale each non zero row of X to unit norm. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The data to normalize, row by row. scipy.sparse matrices should be in CSR format to avoid an un...
Scale each non zero row of X to unit norm. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The data to normalize, row by row. scipy.sparse matrices should be in CSR format to avoid an un-necessary copy. copy : bool, default...
transform
python
scikit-learn/scikit-learn
sklearn/preprocessing/_data.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_data.py
BSD-3-Clause
def binarize(X, *, threshold=0.0, copy=True): """Boolean thresholding of array-like or scipy.sparse matrix. Read more in the :ref:`User Guide <preprocessing_binarization>`. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The data to binarize, element ...
Boolean thresholding of array-like or scipy.sparse matrix. Read more in the :ref:`User Guide <preprocessing_binarization>`. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The data to binarize, element by element. scipy.sparse matrices should be i...
binarize
python
scikit-learn/scikit-learn
sklearn/preprocessing/_data.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_data.py
BSD-3-Clause
def transform(self, X, copy=None): """Binarize each element of X. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The data to binarize, element by element. scipy.sparse matrices should be in CSR format to avoid an ...
Binarize each element of X. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The data to binarize, element by element. scipy.sparse matrices should be in CSR format to avoid an un-necessary copy. copy : bool ...
transform
python
scikit-learn/scikit-learn
sklearn/preprocessing/_data.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_data.py
BSD-3-Clause
def fit(self, K, y=None): """Fit KernelCenterer. Parameters ---------- K : ndarray of shape (n_samples, n_samples) Kernel matrix. y : None Ignored. Returns ------- self : object Returns the instance itself. ""...
Fit KernelCenterer. Parameters ---------- K : ndarray of shape (n_samples, n_samples) Kernel matrix. y : None Ignored. Returns ------- self : object Returns the instance itself.
fit
python
scikit-learn/scikit-learn
sklearn/preprocessing/_data.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_data.py
BSD-3-Clause
def transform(self, K, copy=True): """Center kernel matrix. Parameters ---------- K : ndarray of shape (n_samples1, n_samples2) Kernel matrix. copy : bool, default=True Set to False to perform inplace computation. Returns ------- ...
Center kernel matrix. Parameters ---------- K : ndarray of shape (n_samples1, n_samples2) Kernel matrix. copy : bool, default=True Set to False to perform inplace computation. Returns ------- K_new : ndarray of shape (n_samples1, n_sampl...
transform
python
scikit-learn/scikit-learn
sklearn/preprocessing/_data.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_data.py
BSD-3-Clause
def add_dummy_feature(X, value=1.0): """Augment dataset with an additional dummy feature. This is useful for fitting an intercept term with implementations which cannot otherwise fit it directly. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) Dat...
Augment dataset with an additional dummy feature. This is useful for fitting an intercept term with implementations which cannot otherwise fit it directly. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) Data. value : float Value to use f...
add_dummy_feature
python
scikit-learn/scikit-learn
sklearn/preprocessing/_data.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_data.py
BSD-3-Clause
def _dense_fit(self, X, random_state): """Compute percentiles for dense matrices. Parameters ---------- X : ndarray of shape (n_samples, n_features) The data used to scale along the features axis. """ if self.ignore_implicit_zeros: warnings.warn( ...
Compute percentiles for dense matrices. Parameters ---------- X : ndarray of shape (n_samples, n_features) The data used to scale along the features axis.
_dense_fit
python
scikit-learn/scikit-learn
sklearn/preprocessing/_data.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_data.py
BSD-3-Clause
def _sparse_fit(self, X, random_state): """Compute percentiles for sparse matrices. Parameters ---------- X : sparse matrix of shape (n_samples, n_features) The data used to scale along the features axis. The sparse matrix needs to be nonnegative. If a sparse mat...
Compute percentiles for sparse matrices. Parameters ---------- X : sparse matrix of shape (n_samples, n_features) The data used to scale along the features axis. The sparse matrix needs to be nonnegative. If a sparse matrix is provided, it will be converted i...
_sparse_fit
python
scikit-learn/scikit-learn
sklearn/preprocessing/_data.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_data.py
BSD-3-Clause
def fit(self, X, y=None): """Compute the quantiles used for transforming. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The data used to scale along the features axis. If a sparse matrix is provided, it will be converted i...
Compute the quantiles used for transforming. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The data used to scale along the features axis. If a sparse matrix is provided, it will be converted into a sparse ``csc_matrix...
fit
python
scikit-learn/scikit-learn
sklearn/preprocessing/_data.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_data.py
BSD-3-Clause
def _transform_col(self, X_col, quantiles, inverse): """Private function to transform a single feature.""" output_distribution = self.output_distribution if not inverse: lower_bound_x = quantiles[0] upper_bound_x = quantiles[-1] lower_bound_y = 0 ...
Private function to transform a single feature.
_transform_col
python
scikit-learn/scikit-learn
sklearn/preprocessing/_data.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_data.py
BSD-3-Clause
def _check_inputs(self, X, in_fit, accept_sparse_negative=False, copy=False): """Check inputs before fit and transform.""" X = validate_data( self, X, reset=in_fit, accept_sparse="csc", copy=copy, dtype=FLOAT_DTYPES, # o...
Check inputs before fit and transform.
_check_inputs
python
scikit-learn/scikit-learn
sklearn/preprocessing/_data.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_data.py
BSD-3-Clause
def _transform(self, X, inverse=False): """Forward and inverse transform. Parameters ---------- X : ndarray of shape (n_samples, n_features) The data used to scale along the features axis. inverse : bool, default=False If False, apply forward transform. ...
Forward and inverse transform. Parameters ---------- X : ndarray of shape (n_samples, n_features) The data used to scale along the features axis. inverse : bool, default=False If False, apply forward transform. If True, apply inverse transform. ...
_transform
python
scikit-learn/scikit-learn
sklearn/preprocessing/_data.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_data.py
BSD-3-Clause
def transform(self, X): """Feature-wise transformation of the data. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The data used to scale along the features axis. If a sparse matrix is provided, it will be converted into a ...
Feature-wise transformation of the data. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The data used to scale along the features axis. If a sparse matrix is provided, it will be converted into a sparse ``csc_matrix``. ...
transform
python
scikit-learn/scikit-learn
sklearn/preprocessing/_data.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_data.py
BSD-3-Clause
def inverse_transform(self, X): """Back-projection to the original space. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The data used to scale along the features axis. If a sparse matrix is provided, it will be converted i...
Back-projection to the original space. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The data used to scale along the features axis. If a sparse matrix is provided, it will be converted into a sparse ``csc_matrix``. Ad...
inverse_transform
python
scikit-learn/scikit-learn
sklearn/preprocessing/_data.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_data.py
BSD-3-Clause
def quantile_transform( X, *, axis=0, n_quantiles=1000, output_distribution="uniform", ignore_implicit_zeros=False, subsample=int(1e5), random_state=None, copy=True, ): """Transform features using quantiles information. This method transforms the features to follow a uniform...
Transform features using quantiles information. This method transforms the features to follow a uniform or a normal distribution. Therefore, for a given feature, this transformation tends to spread out the most frequent values. It also reduces the impact of (marginal) outliers: this is therefore a robu...
quantile_transform
python
scikit-learn/scikit-learn
sklearn/preprocessing/_data.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_data.py
BSD-3-Clause
def transform(self, X): """Apply the power transform to each feature using the fitted lambdas. Parameters ---------- X : array-like of shape (n_samples, n_features) The data to be transformed using a power transformation. Returns ------- X_trans : nd...
Apply the power transform to each feature using the fitted lambdas. Parameters ---------- X : array-like of shape (n_samples, n_features) The data to be transformed using a power transformation. Returns ------- X_trans : ndarray of shape (n_samples, n_featur...
transform
python
scikit-learn/scikit-learn
sklearn/preprocessing/_data.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_data.py
BSD-3-Clause
def inverse_transform(self, X): """Apply the inverse power transformation using the fitted lambdas. The inverse of the Box-Cox transformation is given by:: if lambda_ == 0: X_original = exp(X_trans) else: X_original = (X * lambda_ + 1) ** (1 / la...
Apply the inverse power transformation using the fitted lambdas. The inverse of the Box-Cox transformation is given by:: if lambda_ == 0: X_original = exp(X_trans) else: X_original = (X * lambda_ + 1) ** (1 / lambda_) The inverse of the Yeo-John...
inverse_transform
python
scikit-learn/scikit-learn
sklearn/preprocessing/_data.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_data.py
BSD-3-Clause
def _yeo_johnson_inverse_transform(self, x, lmbda): """Return inverse-transformed input x following Yeo-Johnson inverse transform with parameter lambda. """ x_inv = np.zeros_like(x) pos = x >= 0 # when x >= 0 if abs(lmbda) < np.spacing(1.0): x_inv[pos...
Return inverse-transformed input x following Yeo-Johnson inverse transform with parameter lambda.
_yeo_johnson_inverse_transform
python
scikit-learn/scikit-learn
sklearn/preprocessing/_data.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_data.py
BSD-3-Clause
def _yeo_johnson_transform(self, x, lmbda): """Return transformed input x following Yeo-Johnson transform with parameter lambda. """ out = np.zeros_like(x) pos = x >= 0 # binary mask # when x >= 0 if abs(lmbda) < np.spacing(1.0): out[pos] = np.log1p...
Return transformed input x following Yeo-Johnson transform with parameter lambda.
_yeo_johnson_transform
python
scikit-learn/scikit-learn
sklearn/preprocessing/_data.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_data.py
BSD-3-Clause
def _box_cox_optimize(self, x): """Find and return optimal lambda parameter of the Box-Cox transform by MLE, for observed data x. We here use scipy builtins which uses the brent optimizer. """ mask = np.isnan(x) if np.all(mask): raise ValueError("Column must ...
Find and return optimal lambda parameter of the Box-Cox transform by MLE, for observed data x. We here use scipy builtins which uses the brent optimizer.
_box_cox_optimize
python
scikit-learn/scikit-learn
sklearn/preprocessing/_data.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_data.py
BSD-3-Clause
def _yeo_johnson_optimize(self, x): """Find and return optimal lambda parameter of the Yeo-Johnson transform by MLE, for observed data x. Like for Box-Cox, MLE is done via the brent optimizer. """ x_tiny = np.finfo(np.float64).tiny def _neg_log_likelihood(lmbda): ...
Find and return optimal lambda parameter of the Yeo-Johnson transform by MLE, for observed data x. Like for Box-Cox, MLE is done via the brent optimizer.
_yeo_johnson_optimize
python
scikit-learn/scikit-learn
sklearn/preprocessing/_data.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_data.py
BSD-3-Clause
def _neg_log_likelihood(lmbda): """Return the negative log likelihood of the observed data x as a function of lambda.""" x_trans = self._yeo_johnson_transform(x, lmbda) n_samples = x.shape[0] x_trans_var = x_trans.var() # Reject transformed data t...
Return the negative log likelihood of the observed data x as a function of lambda.
_neg_log_likelihood
python
scikit-learn/scikit-learn
sklearn/preprocessing/_data.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_data.py
BSD-3-Clause
def _check_input(self, X, in_fit, check_positive=False, check_shape=False): """Validate the input before fit and transform. Parameters ---------- X : array-like of shape (n_samples, n_features) in_fit : bool Whether or not `_check_input` is called from `fit` or othe...
Validate the input before fit and transform. Parameters ---------- X : array-like of shape (n_samples, n_features) in_fit : bool Whether or not `_check_input` is called from `fit` or other methods, e.g. `predict`, `transform`, etc. check_positive : bool...
_check_input
python
scikit-learn/scikit-learn
sklearn/preprocessing/_data.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_data.py
BSD-3-Clause
def fit(self, X, y=None, sample_weight=None): """ Fit the estimator. Parameters ---------- X : array-like of shape (n_samples, n_features) Data to be discretized. y : None Ignored. This parameter exists only for compatibility with :cl...
Fit the estimator. Parameters ---------- X : array-like of shape (n_samples, n_features) Data to be discretized. y : None Ignored. This parameter exists only for compatibility with :class:`~sklearn.pipeline.Pipeline`. sample_weight ...
fit
python
scikit-learn/scikit-learn
sklearn/preprocessing/_discretization.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_discretization.py
BSD-3-Clause
def _validate_n_bins(self, n_features): """Returns n_bins_, the number of bins per feature.""" orig_bins = self.n_bins if isinstance(orig_bins, Integral): return np.full(n_features, orig_bins, dtype=int) n_bins = check_array(orig_bins, dtype=int, copy=True, ensure_2d=False) ...
Returns n_bins_, the number of bins per feature.
_validate_n_bins
python
scikit-learn/scikit-learn
sklearn/preprocessing/_discretization.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_discretization.py
BSD-3-Clause
def transform(self, X): """ Discretize the data. Parameters ---------- X : array-like of shape (n_samples, n_features) Data to be discretized. Returns ------- Xt : {ndarray, sparse matrix}, dtype={np.float32, np.float64} Data in t...
Discretize the data. Parameters ---------- X : array-like of shape (n_samples, n_features) Data to be discretized. Returns ------- Xt : {ndarray, sparse matrix}, dtype={np.float32, np.float64} Data in the binned space. Will be a sparse m...
transform
python
scikit-learn/scikit-learn
sklearn/preprocessing/_discretization.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_discretization.py
BSD-3-Clause
def inverse_transform(self, X): """ Transform discretized data back to original feature space. Note that this function does not regenerate the original data due to discretization rounding. Parameters ---------- X : array-like of shape (n_samples, n_features) ...
Transform discretized data back to original feature space. Note that this function does not regenerate the original data due to discretization rounding. Parameters ---------- X : array-like of shape (n_samples, n_features) Transformed data in the binned spa...
inverse_transform
python
scikit-learn/scikit-learn
sklearn/preprocessing/_discretization.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_discretization.py
BSD-3-Clause
def get_feature_names_out(self, input_features=None): """Get output feature names. Parameters ---------- input_features : array-like of str or None, default=None Input features. - If `input_features` is `None`, then `feature_names_in_` is used as f...
Get output feature names. Parameters ---------- input_features : array-like of str or None, default=None Input features. - If `input_features` is `None`, then `feature_names_in_` is used as feature names in. If `feature_names_in_` is not defined, ...
get_feature_names_out
python
scikit-learn/scikit-learn
sklearn/preprocessing/_discretization.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_discretization.py
BSD-3-Clause
def _check_X(self, X, ensure_all_finite=True): """ Perform custom check_array: - convert list of strings to object dtype - check for missing values for object dtype data (check_array does not do that) - return list of features (arrays): this list of features is ...
Perform custom check_array: - convert list of strings to object dtype - check for missing values for object dtype data (check_array does not do that) - return list of features (arrays): this list of features is constructed feature by feature to preserve the data type...
_check_X
python
scikit-learn/scikit-learn
sklearn/preprocessing/_encoders.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_encoders.py
BSD-3-Clause
def _check_infrequent_enabled(self): """ This functions checks whether _infrequent_enabled is True or False. This has to be called after parameter validation in the fit function. """ max_categories = getattr(self, "max_categories", None) min_frequency = getattr(self, "min...
This functions checks whether _infrequent_enabled is True or False. This has to be called after parameter validation in the fit function.
_check_infrequent_enabled
python
scikit-learn/scikit-learn
sklearn/preprocessing/_encoders.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_encoders.py
BSD-3-Clause
def _identify_infrequent(self, category_count, n_samples, col_idx): """Compute the infrequent indices. Parameters ---------- category_count : ndarray of shape (n_cardinality,) Category counts. n_samples : int Number of samples. col_idx : int ...
Compute the infrequent indices. Parameters ---------- category_count : ndarray of shape (n_cardinality,) Category counts. n_samples : int Number of samples. col_idx : int Index of the current category. Only used for the error message. ...
_identify_infrequent
python
scikit-learn/scikit-learn
sklearn/preprocessing/_encoders.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_encoders.py
BSD-3-Clause
def _fit_infrequent_category_mapping( self, n_samples, category_counts, missing_indices ): """Fit infrequent categories. Defines the private attribute: `_default_to_infrequent_mappings`. For feature `i`, `_default_to_infrequent_mappings[i]` defines the mapping from the integ...
Fit infrequent categories. Defines the private attribute: `_default_to_infrequent_mappings`. For feature `i`, `_default_to_infrequent_mappings[i]` defines the mapping from the integer encoding returned by `super().transform()` into infrequent categories. If `_default_to_infrequent_mappi...
_fit_infrequent_category_mapping
python
scikit-learn/scikit-learn
sklearn/preprocessing/_encoders.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_encoders.py
BSD-3-Clause
def _map_infrequent_categories(self, X_int, X_mask, ignore_category_indices): """Map infrequent categories to integer representing the infrequent category. This modifies X_int in-place. Values that were invalid based on `X_mask` are mapped to the infrequent category if there was an infrequent ...
Map infrequent categories to integer representing the infrequent category. This modifies X_int in-place. Values that were invalid based on `X_mask` are mapped to the infrequent category if there was an infrequent category for that feature. Parameters ---------- X_int: n...
_map_infrequent_categories
python
scikit-learn/scikit-learn
sklearn/preprocessing/_encoders.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_encoders.py
BSD-3-Clause
def _map_drop_idx_to_infrequent(self, feature_idx, drop_idx): """Convert `drop_idx` into the index for infrequent categories. If there are no infrequent categories, then `drop_idx` is returned. This method is called in `_set_drop_idx` when the `drop` parameter is an array-like. ...
Convert `drop_idx` into the index for infrequent categories. If there are no infrequent categories, then `drop_idx` is returned. This method is called in `_set_drop_idx` when the `drop` parameter is an array-like.
_map_drop_idx_to_infrequent
python
scikit-learn/scikit-learn
sklearn/preprocessing/_encoders.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_encoders.py
BSD-3-Clause
def _set_drop_idx(self): """Compute the drop indices associated with `self.categories_`. If `self.drop` is: - `None`, No categories have been dropped. - `'first'`, All zeros to drop the first category. - `'if_binary'`, All zeros if the category is binary and `None` oth...
Compute the drop indices associated with `self.categories_`. If `self.drop` is: - `None`, No categories have been dropped. - `'first'`, All zeros to drop the first category. - `'if_binary'`, All zeros if the category is binary and `None` otherwise. - array-like, The in...
_set_drop_idx
python
scikit-learn/scikit-learn
sklearn/preprocessing/_encoders.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_encoders.py
BSD-3-Clause
def _compute_transformed_categories(self, i, remove_dropped=True): """Compute the transformed categories used for column `i`. 1. If there are infrequent categories, the category is named 'infrequent_sklearn'. 2. Dropped columns are removed when remove_dropped=True. """ c...
Compute the transformed categories used for column `i`. 1. If there are infrequent categories, the category is named 'infrequent_sklearn'. 2. Dropped columns are removed when remove_dropped=True.
_compute_transformed_categories
python
scikit-learn/scikit-learn
sklearn/preprocessing/_encoders.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_encoders.py
BSD-3-Clause
def _compute_n_features_outs(self): """Compute the n_features_out for each input feature.""" output = [len(cats) for cats in self.categories_] if self._drop_idx_after_grouping is not None: for i, drop_idx in enumerate(self._drop_idx_after_grouping): if drop_idx is no...
Compute the n_features_out for each input feature.
_compute_n_features_outs
python
scikit-learn/scikit-learn
sklearn/preprocessing/_encoders.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_encoders.py
BSD-3-Clause
def fit(self, X, y=None): """ Fit OneHotEncoder to X. Parameters ---------- X : array-like of shape (n_samples, n_features) The data to determine the categories of each feature. y : None Ignored. This parameter exists only for compatibility with ...
Fit OneHotEncoder to X. Parameters ---------- X : array-like of shape (n_samples, n_features) The data to determine the categories of each feature. y : None Ignored. This parameter exists only for compatibility with :class:`~sklearn.pipeline...
fit
python
scikit-learn/scikit-learn
sklearn/preprocessing/_encoders.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_encoders.py
BSD-3-Clause
def transform(self, X): """ Transform X using one-hot encoding. If `sparse_output=True` (default), it returns an instance of :class:`scipy.sparse._csr.csr_matrix` (CSR format). If there are infrequent categories for a feature, set by specifying `max_categories` or `min_...
Transform X using one-hot encoding. If `sparse_output=True` (default), it returns an instance of :class:`scipy.sparse._csr.csr_matrix` (CSR format). If there are infrequent categories for a feature, set by specifying `max_categories` or `min_frequency`, the infrequent categori...
transform
python
scikit-learn/scikit-learn
sklearn/preprocessing/_encoders.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_encoders.py
BSD-3-Clause
def inverse_transform(self, X): """ Convert the data back to the original representation. When unknown categories are encountered (all zeros in the one-hot encoding), ``None`` is used to represent this category. If the feature with the unknown category has a dropped category, th...
Convert the data back to the original representation. When unknown categories are encountered (all zeros in the one-hot encoding), ``None`` is used to represent this category. If the feature with the unknown category has a dropped category, the dropped category will be its inve...
inverse_transform
python
scikit-learn/scikit-learn
sklearn/preprocessing/_encoders.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_encoders.py
BSD-3-Clause
def fit(self, X, y=None): """ Fit the OrdinalEncoder to X. Parameters ---------- X : array-like of shape (n_samples, n_features) The data to determine the categories of each feature. y : None Ignored. This parameter exists only for compatibility ...
Fit the OrdinalEncoder to X. Parameters ---------- X : array-like of shape (n_samples, n_features) The data to determine the categories of each feature. y : None Ignored. This parameter exists only for compatibility with :class:`~sklearn.pip...
fit
python
scikit-learn/scikit-learn
sklearn/preprocessing/_encoders.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_encoders.py
BSD-3-Clause
def transform(self, X): """ Transform X to ordinal codes. Parameters ---------- X : array-like of shape (n_samples, n_features) The data to encode. Returns ------- X_out : ndarray of shape (n_samples, n_features) Transformed input...
Transform X to ordinal codes. Parameters ---------- X : array-like of shape (n_samples, n_features) The data to encode. Returns ------- X_out : ndarray of shape (n_samples, n_features) Transformed input.
transform
python
scikit-learn/scikit-learn
sklearn/preprocessing/_encoders.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_encoders.py
BSD-3-Clause
def inverse_transform(self, X): """ Convert the data back to the original representation. Parameters ---------- X : array-like of shape (n_samples, n_encoded_features) The transformed data. Returns ------- X_original : ndarray of shape (n_sam...
Convert the data back to the original representation. Parameters ---------- X : array-like of shape (n_samples, n_encoded_features) The transformed data. Returns ------- X_original : ndarray of shape (n_samples, n_features) Inverse trans...
inverse_transform
python
scikit-learn/scikit-learn
sklearn/preprocessing/_encoders.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_encoders.py
BSD-3-Clause
def _check_inverse_transform(self, X): """Check that func and inverse_func are the inverse.""" idx_selected = slice(None, None, max(1, X.shape[0] // 100)) X_round_trip = self.inverse_transform(self.transform(X[idx_selected])) if hasattr(X, "dtype"): dtypes = [X.dtype] ...
Check that func and inverse_func are the inverse.
_check_inverse_transform
python
scikit-learn/scikit-learn
sklearn/preprocessing/_function_transformer.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_function_transformer.py
BSD-3-Clause
def fit(self, X, y=None): """Fit transformer by checking X. If ``validate`` is ``True``, ``X`` will be checked. Parameters ---------- X : {array-like, sparse-matrix} of shape (n_samples, n_features) \ if `validate=True` else any object that `func` can handle ...
Fit transformer by checking X. If ``validate`` is ``True``, ``X`` will be checked. Parameters ---------- X : {array-like, sparse-matrix} of shape (n_samples, n_features) if `validate=True` else any object that `func` can handle Input array. y : Igno...
fit
python
scikit-learn/scikit-learn
sklearn/preprocessing/_function_transformer.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_function_transformer.py
BSD-3-Clause
def transform(self, X): """Transform X using the forward function. Parameters ---------- X : {array-like, sparse-matrix} of shape (n_samples, n_features) \ if `validate=True` else any object that `func` can handle Input array. Returns -------...
Transform X using the forward function. Parameters ---------- X : {array-like, sparse-matrix} of shape (n_samples, n_features) if `validate=True` else any object that `func` can handle Input array. Returns ------- X_out : array-like, shape (n...
transform
python
scikit-learn/scikit-learn
sklearn/preprocessing/_function_transformer.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_function_transformer.py
BSD-3-Clause
def inverse_transform(self, X): """Transform X using the inverse function. Parameters ---------- X : {array-like, sparse-matrix} of shape (n_samples, n_features) \ if `validate=True` else any object that `inverse_func` can handle Input array. Returns...
Transform X using the inverse function. Parameters ---------- X : {array-like, sparse-matrix} of shape (n_samples, n_features) if `validate=True` else any object that `inverse_func` can handle Input array. Returns ------- X_original : array-l...
inverse_transform
python
scikit-learn/scikit-learn
sklearn/preprocessing/_function_transformer.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_function_transformer.py
BSD-3-Clause
def get_feature_names_out(self, input_features=None): """Get output feature names for transformation. This method is only defined if `feature_names_out` is not None. Parameters ---------- input_features : array-like of str or None, default=None Input feature names. ...
Get output feature names for transformation. This method is only defined if `feature_names_out` is not None. Parameters ---------- input_features : array-like of str or None, default=None Input feature names. - If `input_features` is None, then `feature_names_i...
get_feature_names_out
python
scikit-learn/scikit-learn
sklearn/preprocessing/_function_transformer.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_function_transformer.py
BSD-3-Clause
def set_output(self, *, transform=None): """Set output container. See :ref:`sphx_glr_auto_examples_miscellaneous_plot_set_output.py` for an example on how to use the API. Parameters ---------- transform : {"default", "pandas", "polars"}, default=None Configu...
Set output container. See :ref:`sphx_glr_auto_examples_miscellaneous_plot_set_output.py` for an example on how to use the API. Parameters ---------- transform : {"default", "pandas", "polars"}, default=None Configure output of `transform` and `fit_transform`. ...
set_output
python
scikit-learn/scikit-learn
sklearn/preprocessing/_function_transformer.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_function_transformer.py
BSD-3-Clause
def _get_function_name(self): """Get the name display of the `func` used in HTML representation.""" if hasattr(self.func, "__name__"): return self.func.__name__ if isinstance(self.func, partial): return self.func.func.__name__ return f"{self.func.__class__.__name_...
Get the name display of the `func` used in HTML representation.
_get_function_name
python
scikit-learn/scikit-learn
sklearn/preprocessing/_function_transformer.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_function_transformer.py
BSD-3-Clause
def fit(self, y): """Fit label encoder. Parameters ---------- y : array-like of shape (n_samples,) Target values. Returns ------- self : returns an instance of self. Fitted label encoder. """ y = column_or_1d(y, warn=True)...
Fit label encoder. Parameters ---------- y : array-like of shape (n_samples,) Target values. Returns ------- self : returns an instance of self. Fitted label encoder.
fit
python
scikit-learn/scikit-learn
sklearn/preprocessing/_label.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_label.py
BSD-3-Clause
def fit_transform(self, y): """Fit label encoder and return encoded labels. Parameters ---------- y : array-like of shape (n_samples,) Target values. Returns ------- y : array-like of shape (n_samples,) Encoded labels. """ ...
Fit label encoder and return encoded labels. Parameters ---------- y : array-like of shape (n_samples,) Target values. Returns ------- y : array-like of shape (n_samples,) Encoded labels.
fit_transform
python
scikit-learn/scikit-learn
sklearn/preprocessing/_label.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_label.py
BSD-3-Clause
def transform(self, y): """Transform labels to normalized encoding. Parameters ---------- y : array-like of shape (n_samples,) Target values. Returns ------- y : array-like of shape (n_samples,) Labels as normalized encodings. """...
Transform labels to normalized encoding. Parameters ---------- y : array-like of shape (n_samples,) Target values. Returns ------- y : array-like of shape (n_samples,) Labels as normalized encodings.
transform
python
scikit-learn/scikit-learn
sklearn/preprocessing/_label.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_label.py
BSD-3-Clause
def inverse_transform(self, y): """Transform labels back to original encoding. Parameters ---------- y : array-like of shape (n_samples,) Target values. Returns ------- y_original : ndarray of shape (n_samples,) Original encoding. ...
Transform labels back to original encoding. Parameters ---------- y : array-like of shape (n_samples,) Target values. Returns ------- y_original : ndarray of shape (n_samples,) Original encoding.
inverse_transform
python
scikit-learn/scikit-learn
sklearn/preprocessing/_label.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_label.py
BSD-3-Clause
def fit(self, y): """Fit label binarizer. Parameters ---------- y : ndarray of shape (n_samples,) or (n_samples, n_classes) Target values. The 2-d matrix should only contain 0 and 1, represents multilabel classification. Returns ------- s...
Fit label binarizer. Parameters ---------- y : ndarray of shape (n_samples,) or (n_samples, n_classes) Target values. The 2-d matrix should only contain 0 and 1, represents multilabel classification. Returns ------- self : object Retu...
fit
python
scikit-learn/scikit-learn
sklearn/preprocessing/_label.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_label.py
BSD-3-Clause
def transform(self, y): """Transform multi-class labels to binary labels. The output of transform is sometimes referred to by some authors as the 1-of-K coding scheme. Parameters ---------- y : {array, sparse matrix} of shape (n_samples,) or \ (n_samples...
Transform multi-class labels to binary labels. The output of transform is sometimes referred to by some authors as the 1-of-K coding scheme. Parameters ---------- y : {array, sparse matrix} of shape (n_samples,) or (n_samples, n_classes) Target value...
transform
python
scikit-learn/scikit-learn
sklearn/preprocessing/_label.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_label.py
BSD-3-Clause
def inverse_transform(self, Y, threshold=None): """Transform binary labels back to multi-class labels. Parameters ---------- Y : {ndarray, sparse matrix} of shape (n_samples, n_classes) Target values. All sparse matrices are converted to CSR before inverse transf...
Transform binary labels back to multi-class labels. Parameters ---------- Y : {ndarray, sparse matrix} of shape (n_samples, n_classes) Target values. All sparse matrices are converted to CSR before inverse transformation. threshold : float, default=None ...
inverse_transform
python
scikit-learn/scikit-learn
sklearn/preprocessing/_label.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_label.py
BSD-3-Clause
def label_binarize(y, *, classes, neg_label=0, pos_label=1, sparse_output=False): """Binarize labels in a one-vs-all fashion. Several regression and binary classification algorithms are available in scikit-learn. A simple way to extend these algorithms to the multi-class classification case is to use t...
Binarize labels in a one-vs-all fashion. Several regression and binary classification algorithms are available in scikit-learn. A simple way to extend these algorithms to the multi-class classification case is to use the so-called one-vs-all scheme. This function makes it possible to compute this ...
label_binarize
python
scikit-learn/scikit-learn
sklearn/preprocessing/_label.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_label.py
BSD-3-Clause
def _inverse_binarize_multiclass(y, classes): """Inverse label binarization transformation for multiclass. Multiclass uses the maximal score instead of a threshold. """ classes = np.asarray(classes) if sp.issparse(y): # Find the argmax for each row in y where y is a CSR matrix y =...
Inverse label binarization transformation for multiclass. Multiclass uses the maximal score instead of a threshold.
_inverse_binarize_multiclass
python
scikit-learn/scikit-learn
sklearn/preprocessing/_label.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_label.py
BSD-3-Clause
def _inverse_binarize_thresholding(y, output_type, classes, threshold): """Inverse label binarization transformation using thresholding.""" if output_type == "binary" and y.ndim == 2 and y.shape[1] > 2: raise ValueError("output_type='binary', but y.shape = {0}".format(y.shape)) if output_type != "...
Inverse label binarization transformation using thresholding.
_inverse_binarize_thresholding
python
scikit-learn/scikit-learn
sklearn/preprocessing/_label.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_label.py
BSD-3-Clause
def fit(self, y): """Fit the label sets binarizer, storing :term:`classes_`. Parameters ---------- y : iterable of iterables A set of labels (any orderable and hashable object) for each sample. If the `classes` parameter is set, `y` will not be iterat...
Fit the label sets binarizer, storing :term:`classes_`. Parameters ---------- y : iterable of iterables A set of labels (any orderable and hashable object) for each sample. If the `classes` parameter is set, `y` will not be iterated. Returns ...
fit
python
scikit-learn/scikit-learn
sklearn/preprocessing/_label.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_label.py
BSD-3-Clause
def fit_transform(self, y): """Fit the label sets binarizer and transform the given label sets. Parameters ---------- y : iterable of iterables A set of labels (any orderable and hashable object) for each sample. If the `classes` parameter is set, `y` will not be...
Fit the label sets binarizer and transform the given label sets. Parameters ---------- y : iterable of iterables A set of labels (any orderable and hashable object) for each sample. If the `classes` parameter is set, `y` will not be iterated. Returns...
fit_transform
python
scikit-learn/scikit-learn
sklearn/preprocessing/_label.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_label.py
BSD-3-Clause
def transform(self, y): """Transform the given label sets. Parameters ---------- y : iterable of iterables A set of labels (any orderable and hashable object) for each sample. If the `classes` parameter is set, `y` will not be iterated. Retur...
Transform the given label sets. Parameters ---------- y : iterable of iterables A set of labels (any orderable and hashable object) for each sample. If the `classes` parameter is set, `y` will not be iterated. Returns ------- y_indica...
transform
python
scikit-learn/scikit-learn
sklearn/preprocessing/_label.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_label.py
BSD-3-Clause
def _transform(self, y, class_mapping): """Transforms the label sets with a given mapping. Parameters ---------- y : iterable of iterables A set of labels (any orderable and hashable object) for each sample. If the `classes` parameter is set, `y` will not be ...
Transforms the label sets with a given mapping. Parameters ---------- y : iterable of iterables A set of labels (any orderable and hashable object) for each sample. If the `classes` parameter is set, `y` will not be iterated. class_mapping : Mapping ...
_transform
python
scikit-learn/scikit-learn
sklearn/preprocessing/_label.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_label.py
BSD-3-Clause
def inverse_transform(self, yt): """Transform the given indicator matrix into label sets. Parameters ---------- yt : {ndarray, sparse matrix} of shape (n_samples, n_classes) A matrix containing only 1s ands 0s. Returns ------- y_original : list of tu...
Transform the given indicator matrix into label sets. Parameters ---------- yt : {ndarray, sparse matrix} of shape (n_samples, n_classes) A matrix containing only 1s ands 0s. Returns ------- y_original : list of tuples The set of labels for each ...
inverse_transform
python
scikit-learn/scikit-learn
sklearn/preprocessing/_label.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_label.py
BSD-3-Clause
def _create_expansion(X, interaction_only, deg, n_features, cumulative_size=0): """Helper function for creating and appending sparse expansion matrices""" total_nnz = _calc_total_nnz(X.indptr, interaction_only, deg) expanded_col = _calc_expanded_nnz(n_features, interaction_only, deg) if expanded_col =...
Helper function for creating and appending sparse expansion matrices
_create_expansion
python
scikit-learn/scikit-learn
sklearn/preprocessing/_polynomial.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_polynomial.py
BSD-3-Clause