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 _num_combinations( n_features, min_degree, max_degree, interaction_only, include_bias ): """Calculate number of terms in polynomial expansion This should be equivalent to counting the number of terms returned by _combinations(...) but much faster. """ if interac...
Calculate number of terms in polynomial expansion This should be equivalent to counting the number of terms returned by _combinations(...) but much faster.
_num_combinations
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
def powers_(self): """Exponent for each of the inputs in the output.""" check_is_fitted(self) combinations = self._combinations( n_features=self.n_features_in_, min_degree=self._min_degree, max_degree=self._max_degree, interaction_only=self.intera...
Exponent for each of the inputs in the output.
powers_
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
def get_feature_names_out(self, input_features=None): """Get output feature names for transformation. Parameters ---------- input_features : array-like of str or None, default=None Input features. - If `input_features is None`, then `feature_names_in_` is ...
Get output feature names for transformation. 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 d...
get_feature_names_out
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
def fit(self, X, y=None): """ Compute number of output features. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The data. y : Ignored Not used, present here for API consistency by convention. Retur...
Compute number of output features. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The data. y : Ignored Not used, present here for API consistency by convention. Returns ------- self : obj...
fit
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
def transform(self, X): """Transform data to polynomial features. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The data to transform, row by row. Prefer CSR over CSC for sparse input (for speed), but CSC is r...
Transform data to polynomial features. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The data to transform, row by row. Prefer CSR over CSC for sparse input (for speed), but CSC is required if the degree is 4 or highe...
transform
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
def _get_base_knot_positions(X, n_knots=10, knots="uniform", sample_weight=None): """Calculate base knot positions. Base knots such that first knot <= feature <= last knot. For the B-spline construction with scipy.interpolate.BSpline, 2*degree knots beyond the base interval are added. ...
Calculate base knot positions. Base knots such that first knot <= feature <= last knot. For the B-spline construction with scipy.interpolate.BSpline, 2*degree knots beyond the base interval are added. Returns ------- knots : ndarray of shape (n_knots, n_features), dtype...
_get_base_knot_positions
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
def fit(self, X, y=None, sample_weight=None): """Compute knot positions of splines. Parameters ---------- X : array-like of shape (n_samples, n_features) The data. y : None Ignored. sample_weight : array-like of shape (n_samples,), default = Non...
Compute knot positions of splines. Parameters ---------- X : array-like of shape (n_samples, n_features) The data. y : None Ignored. sample_weight : array-like of shape (n_samples,), default = None Individual weights for each sample. Used to...
fit
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
def transform(self, X): """Transform each feature data to B-splines. Parameters ---------- X : array-like of shape (n_samples, n_features) The data to transform. Returns ------- XBS : {ndarray, sparse matrix} of shape (n_samples, n_features * n_splin...
Transform each feature data to B-splines. Parameters ---------- X : array-like of shape (n_samples, n_features) The data to transform. Returns ------- XBS : {ndarray, sparse matrix} of shape (n_samples, n_features * n_splines) The matrix of featu...
transform
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
def fit_transform(self, X, y): """Fit :class:`TargetEncoder` and transform X with the target encoding. .. note:: `fit(X, y).transform(X)` does not equal `fit_transform(X, y)` because a :term:`cross fitting` scheme is used in `fit_transform` for encoding. See the :ref...
Fit :class:`TargetEncoder` and transform X with the target encoding. .. note:: `fit(X, y).transform(X)` does not equal `fit_transform(X, y)` because a :term:`cross fitting` scheme is used in `fit_transform` for encoding. See the :ref:`User Guide <target_encoder>`. for detail...
fit_transform
python
scikit-learn/scikit-learn
sklearn/preprocessing/_target_encoder.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_target_encoder.py
BSD-3-Clause
def transform(self, X): """Transform X with the target encoding. .. note:: `fit(X, y).transform(X)` does not equal `fit_transform(X, y)` because a :term:`cross fitting` scheme is used in `fit_transform` for encoding. See the :ref:`User Guide <target_encoder>`. for de...
Transform X with the target encoding. .. note:: `fit(X, y).transform(X)` does not equal `fit_transform(X, y)` because a :term:`cross fitting` scheme is used in `fit_transform` for encoding. See the :ref:`User Guide <target_encoder>`. for details. Parameters ...
transform
python
scikit-learn/scikit-learn
sklearn/preprocessing/_target_encoder.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_target_encoder.py
BSD-3-Clause
def _fit_encodings_all(self, X, y): """Fit a target encoding with all the data.""" # avoid circular import from ..preprocessing import ( LabelBinarizer, LabelEncoder, ) check_consistent_length(X, y) self._fit(X, handle_unknown="ignore", ensure_all...
Fit a target encoding with all the data.
_fit_encodings_all
python
scikit-learn/scikit-learn
sklearn/preprocessing/_target_encoder.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_target_encoder.py
BSD-3-Clause
def _fit_encoding_multiclass(self, X_ordinal, y, n_categories, target_mean): """Learn multiclass encodings. Learn encodings for each class (c) then reorder encodings such that the same features (f) are grouped together. `reorder_index` enables converting from: f0_c0, f1_c0, f0_c...
Learn multiclass encodings. Learn encodings for each class (c) then reorder encodings such that the same features (f) are grouped together. `reorder_index` enables converting from: f0_c0, f1_c0, f0_c1, f1_c1, f0_c2, f1_c2 to: f0_c0, f0_c1, f0_c2, f1_c0, f1_c1, f1_c2 ...
_fit_encoding_multiclass
python
scikit-learn/scikit-learn
sklearn/preprocessing/_target_encoder.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_target_encoder.py
BSD-3-Clause
def _transform_X_ordinal( self, X_out, X_ordinal, X_unknown_mask, row_indices, encodings, target_mean, ): """Transform X_ordinal using encodings. In the multiclass case, `X_ordinal` and `X_unknown_mask` have column (axis=1) size `n_fea...
Transform X_ordinal using encodings. In the multiclass case, `X_ordinal` and `X_unknown_mask` have column (axis=1) size `n_features`, while `encodings` has length of size `n_features * n_classes`. `feat_idx` deals with this by repeating feature indices by `n_classes` E.g., for 3 feature...
_transform_X_ordinal
python
scikit-learn/scikit-learn
sklearn/preprocessing/_target_encoder.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_target_encoder.py
BSD-3-Clause
def get_feature_names_out(self, input_features=None): """Get output feature names for transformation. Parameters ---------- input_features : array-like of str or None, default=None Not used, present here for API consistency by convention. Returns ------- ...
Get output feature names for transformation. Parameters ---------- input_features : array-like of str or None, default=None Not used, present here for API consistency by convention. Returns ------- feature_names_out : ndarray of str objects Trans...
get_feature_names_out
python
scikit-learn/scikit-learn
sklearn/preprocessing/_target_encoder.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/_target_encoder.py
BSD-3-Clause
def test_quantile_transform_subsampling_disabled(): """Check the behaviour of `QuantileTransformer` when `subsample=None`.""" X = np.random.RandomState(0).normal(size=(200, 1)) n_quantiles = 5 transformer = QuantileTransformer(n_quantiles=n_quantiles, subsample=None).fit(X) expected_references = n...
Check the behaviour of `QuantileTransformer` when `subsample=None`.
test_quantile_transform_subsampling_disabled
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_data.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_data.py
BSD-3-Clause
def test_power_transformer_box_cox_raise_all_nans_col(): """Check that box-cox raises informative when a column contains all nans. Non-regression test for gh-26303 """ X = rng.random_sample((4, 5)) X[:, 0] = np.nan err_msg = "Column must not be all nan." pt = PowerTransformer(method="box-...
Check that box-cox raises informative when a column contains all nans. Non-regression test for gh-26303
test_power_transformer_box_cox_raise_all_nans_col
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_data.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_data.py
BSD-3-Clause
def test_standard_scaler_raise_error_for_1d_input(): """Check that `inverse_transform` from `StandardScaler` raises an error with 1D array. Non-regression test for: https://github.com/scikit-learn/scikit-learn/issues/19518 """ scaler = StandardScaler().fit(X_2d) err_msg = "Expected 2D array,...
Check that `inverse_transform` from `StandardScaler` raises an error with 1D array. Non-regression test for: https://github.com/scikit-learn/scikit-learn/issues/19518
test_standard_scaler_raise_error_for_1d_input
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_data.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_data.py
BSD-3-Clause
def test_power_transformer_significantly_non_gaussian(): """Check that significantly non-Gaussian data before transforms correctly. For some explored lambdas, the transformed data may be constant and will be rejected. Non-regression test for https://github.com/scikit-learn/scikit-learn/issues/14959 ...
Check that significantly non-Gaussian data before transforms correctly. For some explored lambdas, the transformed data may be constant and will be rejected. Non-regression test for https://github.com/scikit-learn/scikit-learn/issues/14959
test_power_transformer_significantly_non_gaussian
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_data.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_data.py
BSD-3-Clause
def test_one_to_one_features(Transformer): """Check one-to-one transformers give correct feature names.""" tr = Transformer().fit(iris.data) names_out = tr.get_feature_names_out(iris.feature_names) assert_array_equal(names_out, iris.feature_names)
Check one-to-one transformers give correct feature names.
test_one_to_one_features
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_data.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_data.py
BSD-3-Clause
def test_power_transformer_constant_feature(standardize): """Check that PowerTransfomer leaves constant features unchanged.""" X = [[-2, 0, 2], [-2, 0, 2], [-2, 0, 2]] pt = PowerTransformer(method="yeo-johnson", standardize=standardize).fit(X) assert_allclose(pt.lambdas_, [1, 1, 1]) Xft = pt.fit_...
Check that PowerTransfomer leaves constant features unchanged.
test_power_transformer_constant_feature
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_data.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_data.py
BSD-3-Clause
def test_power_transformer_no_warnings(): """Verify that PowerTransformer operates without raising any warnings on valid data. This test addresses numerical issues with floating point numbers (mostly overflows) with the Yeo-Johnson transform, see https://github.com/scikit-learn/scikit-learn/issues/2331...
Verify that PowerTransformer operates without raising any warnings on valid data. This test addresses numerical issues with floating point numbers (mostly overflows) with the Yeo-Johnson transform, see https://github.com/scikit-learn/scikit-learn/issues/23319#issuecomment-1464933635
test_power_transformer_no_warnings
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_data.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_data.py
BSD-3-Clause
def _test_no_warnings(data): """Internal helper to test for unexpected warnings.""" with warnings.catch_warnings(record=True) as caught_warnings: warnings.simplefilter("always") # Ensure all warnings are captured PowerTransformer(method="yeo-johnson", standardize=True).fit_trans...
Internal helper to test for unexpected warnings.
_test_no_warnings
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_data.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_data.py
BSD-3-Clause
def test_yeojohnson_for_different_scipy_version(): """Check that the results are consistent across different SciPy versions.""" pt = PowerTransformer(method="yeo-johnson").fit(X_1col) pt.lambdas_[0] == pytest.approx(0.99546157, rel=1e-7)
Check that the results are consistent across different SciPy versions.
test_yeojohnson_for_different_scipy_version
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_data.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_data.py
BSD-3-Clause
def test_kbinsdiscretizer_effect_sample_weight(): """Check the impact of `sample_weight` one computed quantiles.""" X = np.array([[-2], [-1], [1], [3], [500], [1000]]) # add a large number of bins such that each sample with a non-null weight # will be used as bin edge est = KBinsDiscretizer( ...
Check the impact of `sample_weight` one computed quantiles.
test_kbinsdiscretizer_effect_sample_weight
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_discretization.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_discretization.py
BSD-3-Clause
def test_kbinsdiscretizer_no_mutating_sample_weight(strategy): """Make sure that `sample_weight` is not changed in place.""" if strategy == "quantile": est = KBinsDiscretizer( n_bins=3, encode="ordinal", strategy=strategy, quantile_method="averaged_invert...
Make sure that `sample_weight` is not changed in place.
test_kbinsdiscretizer_no_mutating_sample_weight
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_discretization.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_discretization.py
BSD-3-Clause
def test_kbinsdiscrtizer_get_feature_names_out(encode, expected_names): """Check get_feature_names_out for different settings. Non-regression test for #22731 """ X = [[-2, 1, -4], [-1, 2, -3], [0, 3, -2], [1, 4, -1]] kbd = KBinsDiscretizer( n_bins=4, encode=encode, quantile_method="averaged...
Check get_feature_names_out for different settings. Non-regression test for #22731
test_kbinsdiscrtizer_get_feature_names_out
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_discretization.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_discretization.py
BSD-3-Clause
def test_one_hot_encoder_custom_feature_name_combiner(): """Check the behaviour of `feature_name_combiner` as a callable.""" def name_combiner(feature, category): return feature + "_" + repr(category) enc = OneHotEncoder(feature_name_combiner=name_combiner) X = np.array([["None", None]], dtype...
Check the behaviour of `feature_name_combiner` as a callable.
test_one_hot_encoder_custom_feature_name_combiner
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_encoders.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_encoders.py
BSD-3-Clause
def test_one_hot_encoder_inverse_transform_raise_error_with_unknown( X, X_trans, sparse_ ): """Check that `inverse_transform` raise an error with unknown samples, no dropped feature, and `handle_unknow="error`. Non-regression test for: https://github.com/scikit-learn/scikit-learn/issues/14934 ""...
Check that `inverse_transform` raise an error with unknown samples, no dropped feature, and `handle_unknow="error`. Non-regression test for: https://github.com/scikit-learn/scikit-learn/issues/14934
test_one_hot_encoder_inverse_transform_raise_error_with_unknown
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_encoders.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_encoders.py
BSD-3-Clause
def test_encoder_nan_ending_specified_categories(Encoder): """Test encoder for specified categories that nan is at the end. Non-regression test for: https://github.com/scikit-learn/scikit-learn/issues/27088 """ cats = [np.array([0, np.nan, 1])] enc = Encoder(categories=cats) X = np.array([[...
Test encoder for specified categories that nan is at the end. Non-regression test for: https://github.com/scikit-learn/scikit-learn/issues/27088
test_encoder_nan_ending_specified_categories
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_encoders.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_encoders.py
BSD-3-Clause
def test_ohe_infrequent_two_levels(kwargs, categories): """Test that different parameters for combine 'a', 'c', and 'd' into the infrequent category works as expected.""" X_train = np.array([["a"] * 5 + ["b"] * 20 + ["c"] * 10 + ["d"] * 3]).T ohe = OneHotEncoder( categories=categories, ...
Test that different parameters for combine 'a', 'c', and 'd' into the infrequent category works as expected.
test_ohe_infrequent_two_levels
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_encoders.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_encoders.py
BSD-3-Clause
def test_ohe_infrequent_two_levels_drop_frequent(drop): """Test two levels and dropping the frequent category.""" X_train = np.array([["a"] * 5 + ["b"] * 20 + ["c"] * 10 + ["d"] * 3]).T ohe = OneHotEncoder( handle_unknown="infrequent_if_exist", sparse_output=False, max_categories=2,...
Test two levels and dropping the frequent category.
test_ohe_infrequent_two_levels_drop_frequent
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_encoders.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_encoders.py
BSD-3-Clause
def test_ohe_infrequent_two_levels_drop_infrequent_errors(drop): """Test two levels and dropping any infrequent category removes the whole infrequent category.""" X_train = np.array([["a"] * 5 + ["b"] * 20 + ["c"] * 10 + ["d"] * 3]).T ohe = OneHotEncoder( handle_unknown="infrequent_if_exist", ...
Test two levels and dropping any infrequent category removes the whole infrequent category.
test_ohe_infrequent_two_levels_drop_infrequent_errors
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_encoders.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_encoders.py
BSD-3-Clause
def test_ohe_infrequent_three_levels(kwargs): """Test that different parameters for combing 'a', and 'd' into the infrequent category works as expected.""" X_train = np.array([["a"] * 5 + ["b"] * 20 + ["c"] * 10 + ["d"] * 3]).T ohe = OneHotEncoder( handle_unknown="infrequent_if_exist", sparse_o...
Test that different parameters for combing 'a', and 'd' into the infrequent category works as expected.
test_ohe_infrequent_three_levels
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_encoders.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_encoders.py
BSD-3-Clause
def test_ohe_infrequent_three_levels_drop_frequent(drop): """Test three levels and dropping the frequent category.""" X_train = np.array([["a"] * 5 + ["b"] * 20 + ["c"] * 10 + ["d"] * 3]).T ohe = OneHotEncoder( handle_unknown="infrequent_if_exist", sparse_output=False, max_categorie...
Test three levels and dropping the frequent category.
test_ohe_infrequent_three_levels_drop_frequent
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_encoders.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_encoders.py
BSD-3-Clause
def test_ohe_infrequent_three_levels_drop_infrequent_errors(drop): """Test three levels and dropping the infrequent category.""" X_train = np.array([["a"] * 5 + ["b"] * 20 + ["c"] * 10 + ["d"] * 3]).T ohe = OneHotEncoder( handle_unknown="infrequent_if_exist", sparse_output=False, max...
Test three levels and dropping the infrequent category.
test_ohe_infrequent_three_levels_drop_infrequent_errors
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_encoders.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_encoders.py
BSD-3-Clause
def test_ohe_infrequent_handle_unknown_error(): """Test that different parameters for combining 'a', and 'd' into the infrequent category works as expected.""" X_train = np.array([["a"] * 5 + ["b"] * 20 + ["c"] * 10 + ["d"] * 3]).T ohe = OneHotEncoder( handle_unknown="error", sparse_output=Fals...
Test that different parameters for combining 'a', and 'd' into the infrequent category works as expected.
test_ohe_infrequent_handle_unknown_error
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_encoders.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_encoders.py
BSD-3-Clause
def test_ohe_infrequent_two_levels_user_cats_one_frequent(kwargs): """'a' is the only frequent category, all other categories are infrequent.""" X_train = np.array([["a"] * 5 + ["e"] * 30], dtype=object).T ohe = OneHotEncoder( categories=[["c", "d", "a", "b"]], sparse_output=False, ...
'a' is the only frequent category, all other categories are infrequent.
test_ohe_infrequent_two_levels_user_cats_one_frequent
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_encoders.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_encoders.py
BSD-3-Clause
def test_ohe_infrequent_two_levels_user_cats(): """Test that the order of the categories provided by a user is respected.""" X_train = np.array( [["a"] * 5 + ["b"] * 20 + ["c"] * 10 + ["d"] * 3], dtype=object ).T ohe = OneHotEncoder( categories=[["c", "d", "a", "b"]], sparse_outp...
Test that the order of the categories provided by a user is respected.
test_ohe_infrequent_two_levels_user_cats
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_encoders.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_encoders.py
BSD-3-Clause
def test_ohe_infrequent_three_levels_user_cats(): """Test that the order of the categories provided by a user is respected. In this case 'c' is encoded as the first category and 'b' is encoded as the second one.""" X_train = np.array( [["a"] * 5 + ["b"] * 20 + ["c"] * 10 + ["d"] * 3], dtype=obj...
Test that the order of the categories provided by a user is respected. In this case 'c' is encoded as the first category and 'b' is encoded as the second one.
test_ohe_infrequent_three_levels_user_cats
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_encoders.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_encoders.py
BSD-3-Clause
def test_ohe_infrequent_mixed(): """Test infrequent categories where feature 0 has infrequent categories, and feature 1 does not.""" # X[:, 0] 1 and 2 are infrequent # X[:, 1] nothing is infrequent X = np.c_[[0, 1, 3, 3, 3, 3, 2, 0, 3], [0, 0, 0, 0, 1, 1, 1, 1, 1]] ohe = OneHotEncoder(max_cate...
Test infrequent categories where feature 0 has infrequent categories, and feature 1 does not.
test_ohe_infrequent_mixed
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_encoders.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_encoders.py
BSD-3-Clause
def test_ohe_infrequent_multiple_categories(): """Test infrequent categories with feature matrix with 3 features.""" X = np.c_[ [0, 1, 3, 3, 3, 3, 2, 0, 3], [0, 0, 5, 1, 1, 10, 5, 5, 0], [1, 0, 1, 0, 1, 0, 1, 0, 1], ] ohe = OneHotEncoder( categories="auto", max_categori...
Test infrequent categories with feature matrix with 3 features.
test_ohe_infrequent_multiple_categories
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_encoders.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_encoders.py
BSD-3-Clause
def test_ohe_infrequent_multiple_categories_dtypes(): """Test infrequent categories with a pandas dataframe with multiple dtypes.""" pd = pytest.importorskip("pandas") X = pd.DataFrame( { "str": ["a", "f", "c", "f", "f", "a", "c", "b", "b"], "int": [5, 3, 0, 10, 10, 12, 0, 3...
Test infrequent categories with a pandas dataframe with multiple dtypes.
test_ohe_infrequent_multiple_categories_dtypes
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_encoders.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_encoders.py
BSD-3-Clause
def test_ohe_infrequent_one_level_errors(kwargs): """All user provided categories are infrequent.""" X_train = np.array([["a"] * 5 + ["b"] * 20 + ["c"] * 10 + ["d"] * 2]).T ohe = OneHotEncoder( handle_unknown="infrequent_if_exist", sparse_output=False, **kwargs ) ohe.fit(X_train) X_tra...
All user provided categories are infrequent.
test_ohe_infrequent_one_level_errors
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_encoders.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_encoders.py
BSD-3-Clause
def test_encoders_string_categories(input_dtype, category_dtype, array_type): """Check that encoding work with object, unicode, and byte string dtypes. Non-regression test for: https://github.com/scikit-learn/scikit-learn/issues/15616 https://github.com/scikit-learn/scikit-learn/issues/15726 https:/...
Check that encoding work with object, unicode, and byte string dtypes. Non-regression test for: https://github.com/scikit-learn/scikit-learn/issues/15616 https://github.com/scikit-learn/scikit-learn/issues/15726 https://github.com/scikit-learn/scikit-learn/issues/19677
test_encoders_string_categories
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_encoders.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_encoders.py
BSD-3-Clause
def test_mixed_string_bytes_categoricals(): """Check that this mixture of predefined categories and X raises an error. Categories defined as bytes can not easily be compared to data that is a string. """ # data as unicode X = np.array([["b"], ["a"]], dtype="U") # predefined categories as by...
Check that this mixture of predefined categories and X raises an error. Categories defined as bytes can not easily be compared to data that is a string.
test_mixed_string_bytes_categoricals
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_encoders.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_encoders.py
BSD-3-Clause
def test_ohe_drop_first_handle_unknown_ignore_warns(handle_unknown): """Check drop='first' and handle_unknown='ignore'/'infrequent_if_exist' during transform.""" X = [["a", 0], ["b", 2], ["b", 1]] ohe = OneHotEncoder( drop="first", sparse_output=False, handle_unknown=handle_unknown ) X_...
Check drop='first' and handle_unknown='ignore'/'infrequent_if_exist' during transform.
test_ohe_drop_first_handle_unknown_ignore_warns
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_encoders.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_encoders.py
BSD-3-Clause
def test_ohe_drop_if_binary_handle_unknown_ignore_warns(handle_unknown): """Check drop='if_binary' and handle_unknown='ignore' during transform.""" X = [["a", 0], ["b", 2], ["b", 1]] ohe = OneHotEncoder( drop="if_binary", sparse_output=False, handle_unknown=handle_unknown ) X_trans = ohe.fi...
Check drop='if_binary' and handle_unknown='ignore' during transform.
test_ohe_drop_if_binary_handle_unknown_ignore_warns
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_encoders.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_encoders.py
BSD-3-Clause
def test_ohe_drop_first_explicit_categories(handle_unknown): """Check drop='first' and handle_unknown='ignore'/'infrequent_if_exist' during fit with categories passed in.""" X = [["a", 0], ["b", 2], ["b", 1]] ohe = OneHotEncoder( drop="first", sparse_output=False, handle_unknow...
Check drop='first' and handle_unknown='ignore'/'infrequent_if_exist' during fit with categories passed in.
test_ohe_drop_first_explicit_categories
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_encoders.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_encoders.py
BSD-3-Clause
def test_ohe_more_informative_error_message(): """Raise informative error message when pandas output and sparse_output=True.""" pd = pytest.importorskip("pandas") df = pd.DataFrame({"a": [1, 2, 3], "b": ["z", "b", "b"]}, columns=["a", "b"]) ohe = OneHotEncoder(sparse_output=True) ohe.set_output(tra...
Raise informative error message when pandas output and sparse_output=True.
test_ohe_more_informative_error_message
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_encoders.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_encoders.py
BSD-3-Clause
def test_ordinal_encoder_passthrough_missing_values_float_errors_dtype(): """Test ordinal encoder with nan passthrough fails when dtype=np.int32.""" X = np.array([[np.nan, 3.0, 1.0, 3.0]]).T oe = OrdinalEncoder(dtype=np.int32) msg = ( r"There are missing values in features \[0\]. For OrdinalEn...
Test ordinal encoder with nan passthrough fails when dtype=np.int32.
test_ordinal_encoder_passthrough_missing_values_float_errors_dtype
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_encoders.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_encoders.py
BSD-3-Clause
def test_ordinal_encoder_passthrough_missing_values_float(encoded_missing_value): """Test ordinal encoder with nan on float dtypes.""" X = np.array([[np.nan, 3.0, 1.0, 3.0]], dtype=np.float64).T oe = OrdinalEncoder(encoded_missing_value=encoded_missing_value).fit(X) assert len(oe.categories_) == 1 ...
Test ordinal encoder with nan on float dtypes.
test_ordinal_encoder_passthrough_missing_values_float
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_encoders.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_encoders.py
BSD-3-Clause
def test_ordinal_encoder_missing_value_support_pandas_categorical( pd_nan_type, encoded_missing_value ): """Check ordinal encoder is compatible with pandas.""" # checks pandas dataframe with categorical features pd = pytest.importorskip("pandas") pd_missing_value = pd.NA if pd_nan_type == "pd.NA" e...
Check ordinal encoder is compatible with pandas.
test_ordinal_encoder_missing_value_support_pandas_categorical
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_encoders.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_encoders.py
BSD-3-Clause
def test_ordinal_encoder_specified_categories_missing_passthrough( X, X2, cats, cat_dtype ): """Test ordinal encoder for specified categories.""" oe = OrdinalEncoder(categories=cats) exp = np.array([[0.0], [np.nan]]) assert_array_equal(oe.fit_transform(X), exp) # manually specified categories sh...
Test ordinal encoder for specified categories.
test_ordinal_encoder_specified_categories_missing_passthrough
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_encoders.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_encoders.py
BSD-3-Clause
def test_encoder_duplicate_specified_categories(Encoder): """Test encoder for specified categories have duplicate values. Non-regression test for: https://github.com/scikit-learn/scikit-learn/issues/27088 """ cats = [np.array(["a", "b", "a"], dtype=object)] enc = Encoder(categories=cats) X ...
Test encoder for specified categories have duplicate values. Non-regression test for: https://github.com/scikit-learn/scikit-learn/issues/27088
test_encoder_duplicate_specified_categories
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_encoders.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_encoders.py
BSD-3-Clause
def test_ordinal_encoder_handle_missing_and_unknown(X, expected_X_trans, X_test): """Test the interaction between missing values and handle_unknown""" oe = OrdinalEncoder(handle_unknown="use_encoded_value", unknown_value=-1) X_trans = oe.fit_transform(X) assert_allclose(X_trans, expected_X_trans) ...
Test the interaction between missing values and handle_unknown
test_ordinal_encoder_handle_missing_and_unknown
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_encoders.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_encoders.py
BSD-3-Clause
def test_ordinal_encoder_sparse(csr_container): """Check that we raise proper error with sparse input in OrdinalEncoder. Non-regression test for: https://github.com/scikit-learn/scikit-learn/issues/19878 """ X = np.array([[3, 2, 1], [0, 1, 1]]) X_sparse = csr_container(X) encoder = OrdinalE...
Check that we raise proper error with sparse input in OrdinalEncoder. Non-regression test for: https://github.com/scikit-learn/scikit-learn/issues/19878
test_ordinal_encoder_sparse
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_encoders.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_encoders.py
BSD-3-Clause
def test_ordinal_encoder_fit_with_unseen_category(): """Check OrdinalEncoder.fit works with unseen category when `handle_unknown="use_encoded_value"`. Non-regression test for: https://github.com/scikit-learn/scikit-learn/issues/19872 """ X = np.array([0, 0, 1, 0, 2, 5])[:, np.newaxis] oe = O...
Check OrdinalEncoder.fit works with unseen category when `handle_unknown="use_encoded_value"`. Non-regression test for: https://github.com/scikit-learn/scikit-learn/issues/19872
test_ordinal_encoder_fit_with_unseen_category
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_encoders.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_encoders.py
BSD-3-Clause
def test_ordinal_encoder_handle_unknown_string_dtypes(X_train, X_test): """Checks that `OrdinalEncoder` transforms string dtypes. Non-regression test for: https://github.com/scikit-learn/scikit-learn/issues/19872 """ enc = OrdinalEncoder(handle_unknown="use_encoded_value", unknown_value=-9) enc....
Checks that `OrdinalEncoder` transforms string dtypes. Non-regression test for: https://github.com/scikit-learn/scikit-learn/issues/19872
test_ordinal_encoder_handle_unknown_string_dtypes
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_encoders.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_encoders.py
BSD-3-Clause
def test_ordinal_encoder_python_integer(): """Check that `OrdinalEncoder` accepts Python integers that are potentially larger than 64 bits. Non-regression test for: https://github.com/scikit-learn/scikit-learn/issues/20721 """ X = np.array( [ 44253463435747313673, ...
Check that `OrdinalEncoder` accepts Python integers that are potentially larger than 64 bits. Non-regression test for: https://github.com/scikit-learn/scikit-learn/issues/20721
test_ordinal_encoder_python_integer
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_encoders.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_encoders.py
BSD-3-Clause
def test_ordinal_encoder_features_names_out_pandas(): """Check feature names out is same as the input.""" pd = pytest.importorskip("pandas") names = ["b", "c", "a"] X = pd.DataFrame([[1, 2, 3]], columns=names) enc = OrdinalEncoder().fit(X) feature_names_out = enc.get_feature_names_out() as...
Check feature names out is same as the input.
test_ordinal_encoder_features_names_out_pandas
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_encoders.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_encoders.py
BSD-3-Clause
def test_ordinal_encoder_unknown_missing_interaction(): """Check interactions between encode_unknown and missing value encoding.""" X = np.array([["a"], ["b"], [np.nan]], dtype=object) oe = OrdinalEncoder( handle_unknown="use_encoded_value", unknown_value=np.nan, encoded_missing_va...
Check interactions between encode_unknown and missing value encoding.
test_ordinal_encoder_unknown_missing_interaction
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_encoders.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_encoders.py
BSD-3-Clause
def test_ordinal_encoder_encoded_missing_value_error(with_pandas): """Check OrdinalEncoder errors when encoded_missing_value is used by an known category.""" X = np.array([["a", "dog"], ["b", "cat"], ["c", np.nan]], dtype=object) # The 0-th feature has no missing values so it is not included in the lis...
Check OrdinalEncoder errors when encoded_missing_value is used by an known category.
test_ordinal_encoder_encoded_missing_value_error
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_encoders.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_encoders.py
BSD-3-Clause
def test_ordinal_encoder_unknown_missing_interaction_both_nan( X_train, X_test_trans_expected, X_roundtrip_expected ): """Check transform when unknown_value and encoded_missing_value is nan. Non-regression test for #24082. """ oe = OrdinalEncoder( handle_unknown="use_encoded_value", ...
Check transform when unknown_value and encoded_missing_value is nan. Non-regression test for #24082.
test_ordinal_encoder_unknown_missing_interaction_both_nan
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_encoders.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_encoders.py
BSD-3-Clause
def test_predefined_categories_dtype(): """Check that the categories_ dtype is `object` for string categories Regression test for gh-25171. """ categories = [["as", "mmas", "eas", "ras", "acs"], ["1", "2"]] enc = OneHotEncoder(categories=categories) enc.fit([["as", "1"]]) assert len(cate...
Check that the categories_ dtype is `object` for string categories Regression test for gh-25171.
test_predefined_categories_dtype
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_encoders.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_encoders.py
BSD-3-Clause
def test_ordinal_encoder_missing_unknown_encoding_max(): """Check missing value or unknown encoding can equal the cardinality.""" X = np.array([["dog"], ["cat"], [np.nan]], dtype=object) X_trans = OrdinalEncoder(encoded_missing_value=2).fit_transform(X) assert_allclose(X_trans, [[1], [0], [2]]) enc...
Check missing value or unknown encoding can equal the cardinality.
test_ordinal_encoder_missing_unknown_encoding_max
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_encoders.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_encoders.py
BSD-3-Clause
def test_drop_idx_infrequent_categories(): """Check drop_idx is defined correctly with infrequent categories. Non-regression test for gh-25550. """ X = np.array( [["a"] * 2 + ["b"] * 4 + ["c"] * 4 + ["d"] * 4 + ["e"] * 4], dtype=object ).T ohe = OneHotEncoder(min_frequency=4, sparse_out...
Check drop_idx is defined correctly with infrequent categories. Non-regression test for gh-25550.
test_drop_idx_infrequent_categories
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_encoders.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_encoders.py
BSD-3-Clause
def test_ordinal_encoder_infrequent_three_levels(kwargs): """Test parameters for grouping 'a', and 'd' into the infrequent category.""" X_train = np.array([["a"] * 5 + ["b"] * 20 + ["c"] * 10 + ["d"] * 3]).T ordinal = OrdinalEncoder( handle_unknown="use_encoded_value", unknown_value=-1, **kwargs ...
Test parameters for grouping 'a', and 'd' into the infrequent category.
test_ordinal_encoder_infrequent_three_levels
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_encoders.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_encoders.py
BSD-3-Clause
def test_ordinal_encoder_infrequent_three_levels_user_cats(): """Test that the order of the categories provided by a user is respected. In this case 'c' is encoded as the first category and 'b' is encoded as the second one. """ X_train = np.array( [["a"] * 5 + ["b"] * 20 + ["c"] * 10 + ["d...
Test that the order of the categories provided by a user is respected. In this case 'c' is encoded as the first category and 'b' is encoded as the second one.
test_ordinal_encoder_infrequent_three_levels_user_cats
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_encoders.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_encoders.py
BSD-3-Clause
def test_ordinal_encoder_infrequent_mixed(): """Test when feature 0 has infrequent categories and feature 1 does not.""" X = np.column_stack(([0, 1, 3, 3, 3, 3, 2, 0, 3], [0, 0, 0, 0, 1, 1, 1, 1, 1])) ordinal = OrdinalEncoder(max_categories=3).fit(X) assert_array_equal(ordinal.infrequent_categories_[...
Test when feature 0 has infrequent categories and feature 1 does not.
test_ordinal_encoder_infrequent_mixed
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_encoders.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_encoders.py
BSD-3-Clause
def test_ordinal_encoder_infrequent_multiple_categories_dtypes(): """Test infrequent categories with a pandas DataFrame with multiple dtypes.""" pd = pytest.importorskip("pandas") categorical_dtype = pd.CategoricalDtype(["bird", "cat", "dog", "snake"]) X = pd.DataFrame( { "str": ["a...
Test infrequent categories with a pandas DataFrame with multiple dtypes.
test_ordinal_encoder_infrequent_multiple_categories_dtypes
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_encoders.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_encoders.py
BSD-3-Clause
def test_ordinal_encoder_infrequent_custom_mapping(): """Check behavior of unknown_value and encoded_missing_value with infrequent.""" X_train = np.array( [["a"] * 5 + ["b"] * 20 + ["c"] * 10 + ["d"] * 3 + [np.nan]], dtype=object ).T ordinal = OrdinalEncoder( handle_unknown="use_encoded...
Check behavior of unknown_value and encoded_missing_value with infrequent.
test_ordinal_encoder_infrequent_custom_mapping
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_encoders.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_encoders.py
BSD-3-Clause
def test_ordinal_encoder_all_frequent(kwargs): """All categories are considered frequent have same encoding as default encoder.""" X_train = np.array( [["a"] * 5 + ["b"] * 20 + ["c"] * 10 + ["d"] * 3], dtype=object ).T adjusted_encoder = OrdinalEncoder( **kwargs, handle_unknown="use_enc...
All categories are considered frequent have same encoding as default encoder.
test_ordinal_encoder_all_frequent
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_encoders.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_encoders.py
BSD-3-Clause
def test_ordinal_encoder_all_infrequent(kwargs): """When all categories are infrequent, they are all encoded as zero.""" X_train = np.array( [["a"] * 5 + ["b"] * 20 + ["c"] * 10 + ["d"] * 3], dtype=object ).T encoder = OrdinalEncoder( **kwargs, handle_unknown="use_encoded_value", unknown...
When all categories are infrequent, they are all encoded as zero.
test_ordinal_encoder_all_infrequent
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_encoders.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_encoders.py
BSD-3-Clause
def test_ordinal_encoder_missing_appears_frequent(): """Check behavior when missing value appears frequently.""" X = np.array( [[np.nan] * 20 + ["dog"] * 10 + ["cat"] * 5 + ["snake"] + ["deer"]], dtype=object, ).T ordinal = OrdinalEncoder(max_categories=3).fit(X) X_test = np.array([...
Check behavior when missing value appears frequently.
test_ordinal_encoder_missing_appears_frequent
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_encoders.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_encoders.py
BSD-3-Clause
def test_ordinal_encoder_missing_appears_infrequent(): """Check behavior when missing value appears infrequently.""" # feature 0 has infrequent categories # feature 1 has no infrequent categories X = np.array( [ [np.nan] + ["dog"] * 10 + ["cat"] * 5 + ["snake"] + ["deer"], ...
Check behavior when missing value appears infrequently.
test_ordinal_encoder_missing_appears_infrequent
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_encoders.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_encoders.py
BSD-3-Clause
def test_encoder_not_fitted(Encoder): """Check that we raise a `NotFittedError` by calling transform before fit with the encoders. One could expect that the passing the `categories` argument to the encoder would make it stateless. However, `fit` is making a couple of check, such as the position of ...
Check that we raise a `NotFittedError` by calling transform before fit with the encoders. One could expect that the passing the `categories` argument to the encoder would make it stateless. However, `fit` is making a couple of check, such as the position of `np.nan`.
test_encoder_not_fitted
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_encoders.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_encoders.py
BSD-3-Clause
def test_function_transformer_raise_error_with_mixed_dtype(X_type): """Check that `FunctionTransformer.check_inverse` raises error on mixed dtype.""" mapping = {"one": 1, "two": 2, "three": 3, 5: "five", 6: "six"} inverse_mapping = {value: key for key, value in mapping.items()} dtype = "object" dat...
Check that `FunctionTransformer.check_inverse` raises error on mixed dtype.
test_function_transformer_raise_error_with_mixed_dtype
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_function_transformer.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_function_transformer.py
BSD-3-Clause
def test_function_transformer_support_all_nummerical_dataframes_check_inverse_True(): """Check support for dataframes with only numerical values.""" pd = pytest.importorskip("pandas") df = pd.DataFrame({"a": [1, 2, 3], "b": [4, 5, 6]}) transformer = FunctionTransformer( func=lambda x: x + 2, in...
Check support for dataframes with only numerical values.
test_function_transformer_support_all_nummerical_dataframes_check_inverse_True
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_function_transformer.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_function_transformer.py
BSD-3-Clause
def test_function_transformer_with_dataframe_and_check_inverse_True(): """Check error is raised when check_inverse=True. Non-regresion test for gh-25261. """ pd = pytest.importorskip("pandas") transformer = FunctionTransformer( func=lambda x: x, inverse_func=lambda x: x, check_inverse=True ...
Check error is raised when check_inverse=True. Non-regresion test for gh-25261.
test_function_transformer_with_dataframe_and_check_inverse_True
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_function_transformer.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_function_transformer.py
BSD-3-Clause
def test_function_transformer_validate_inverse(): """Test that function transformer does not reset estimator in `inverse_transform`.""" def add_constant_feature(X): X_one = np.ones((X.shape[0], 1)) return np.concatenate((X, X_one), axis=1) def inverse_add_constant(X): return X[...
Test that function transformer does not reset estimator in `inverse_transform`.
test_function_transformer_validate_inverse
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_function_transformer.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_function_transformer.py
BSD-3-Clause
def test_get_feature_names_out_dataframe_with_string_data( feature_names_out, expected, in_pipeline ): """Check that get_feature_names_out works with DataFrames with string data.""" pd = pytest.importorskip("pandas") X = pd.DataFrame({"pet": ["dog", "cat"], "color": ["red", "green"]}) def func(X): ...
Check that get_feature_names_out works with DataFrames with string data.
test_get_feature_names_out_dataframe_with_string_data
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_function_transformer.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_function_transformer.py
BSD-3-Clause
def test_set_output_func(): """Check behavior of set_output with different settings.""" pd = pytest.importorskip("pandas") X = pd.DataFrame({"a": [1, 2, 3], "b": [10, 20, 100]}) ft = FunctionTransformer(np.log, feature_names_out="one-to-one") # no warning is raised when feature_names_out is defin...
Check behavior of set_output with different settings.
test_set_output_func
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_function_transformer.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_function_transformer.py
BSD-3-Clause
def test_consistence_column_name_between_steps(): """Check that we have a consistence between the feature names out of `FunctionTransformer` and the feature names in of the next step in the pipeline. Non-regression test for: https://github.com/scikit-learn/scikit-learn/issues/27695 """ pd = pyt...
Check that we have a consistence between the feature names out of `FunctionTransformer` and the feature names in of the next step in the pipeline. Non-regression test for: https://github.com/scikit-learn/scikit-learn/issues/27695
test_consistence_column_name_between_steps
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_function_transformer.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_function_transformer.py
BSD-3-Clause
def test_function_transformer_overwrite_column_names(dataframe_lib, transform_output): """Check that we overwrite the column names when we should.""" lib = pytest.importorskip(dataframe_lib) if transform_output != "numpy": pytest.importorskip(transform_output) df = lib.DataFrame({"a": [1, 2, 3]...
Check that we overwrite the column names when we should.
test_function_transformer_overwrite_column_names
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_function_transformer.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_function_transformer.py
BSD-3-Clause
def test_function_transformer_overwrite_column_names_numerical(feature_names_out): """Check the same as `test_function_transformer_overwrite_column_names` but for the specific case of pandas where column names can be numerical.""" pd = pytest.importorskip("pandas") df = pd.DataFrame({0: [1, 2, 3], 1: [...
Check the same as `test_function_transformer_overwrite_column_names` but for the specific case of pandas where column names can be numerical.
test_function_transformer_overwrite_column_names_numerical
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_function_transformer.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_function_transformer.py
BSD-3-Clause
def test_function_transformer_error_column_inconsistent( dataframe_lib, feature_names_out ): """Check that we raise an error when `func` returns a dataframe with new column names that become inconsistent with `get_feature_names_out`.""" lib = pytest.importorskip(dataframe_lib) df = lib.DataFrame({"...
Check that we raise an error when `func` returns a dataframe with new column names that become inconsistent with `get_feature_names_out`.
test_function_transformer_error_column_inconsistent
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_function_transformer.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_function_transformer.py
BSD-3-Clause
def test_label_binarizer_pandas_nullable(dtype, unique_first): """Checks that LabelBinarizer works with pandas nullable dtypes. Non-regression test for gh-25637. """ pd = pytest.importorskip("pandas") y_true = pd.Series([1, 0, 0, 1, 0, 1, 1, 0, 1], dtype=dtype) if unique_first: # Calli...
Checks that LabelBinarizer works with pandas nullable dtypes. Non-regression test for gh-25637.
test_label_binarizer_pandas_nullable
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_label.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_label.py
BSD-3-Clause
def test_nan_label_encoder(): """Check that label encoder encodes nans in transform. Non-regression test for #22628. """ le = LabelEncoder() le.fit(["a", "a", "b", np.nan]) y_trans = le.transform([np.nan]) assert_array_equal(y_trans, [2])
Check that label encoder encodes nans in transform. Non-regression test for #22628.
test_nan_label_encoder
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_label.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_label.py
BSD-3-Clause
def test_label_encoders_do_not_have_set_output(encoder): """Check that label encoders do not define set_output and work with y as a kwarg. Non-regression test for #26854. """ assert not hasattr(encoder, "set_output") y_encoded_with_kwarg = encoder.fit_transform(y=["a", "b", "c"]) y_encoded_posi...
Check that label encoders do not define set_output and work with y as a kwarg. Non-regression test for #26854.
test_label_encoders_do_not_have_set_output
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_label.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_label.py
BSD-3-Clause
def test_polynomial_and_spline_array_order(est): """Test that output array has the given order.""" X = np.arange(10).reshape(5, 2) def is_c_contiguous(a): return np.isfortran(a.T) assert is_c_contiguous(est().fit_transform(X)) assert is_c_contiguous(est(order="C").fit_transform(X)) ass...
Test that output array has the given order.
test_polynomial_and_spline_array_order
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_polynomial.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_polynomial.py
BSD-3-Clause
def test_spline_transformer_input_validation(params, err_msg): """Test that we raise errors for invalid input in SplineTransformer.""" X = [[1], [2]] with pytest.raises(ValueError, match=err_msg): SplineTransformer(**params).fit(X)
Test that we raise errors for invalid input in SplineTransformer.
test_spline_transformer_input_validation
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_polynomial.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_polynomial.py
BSD-3-Clause
def test_spline_transformer_integer_knots(extrapolation): """Test that SplineTransformer accepts integer value knot positions.""" X = np.arange(20).reshape(10, 2) knots = [[0, 1], [1, 2], [5, 5], [11, 10], [12, 11]] _ = SplineTransformer( degree=3, knots=knots, extrapolation=extrapolation )....
Test that SplineTransformer accepts integer value knot positions.
test_spline_transformer_integer_knots
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_polynomial.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_polynomial.py
BSD-3-Clause
def test_spline_transformer_feature_names(): """Test that SplineTransformer generates correct features name.""" X = np.arange(20).reshape(10, 2) splt = SplineTransformer(n_knots=3, degree=3, include_bias=True).fit(X) feature_names = splt.get_feature_names_out() assert_array_equal( feature_na...
Test that SplineTransformer generates correct features name.
test_spline_transformer_feature_names
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_polynomial.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_polynomial.py
BSD-3-Clause
def test_split_transform_feature_names_extrapolation_degree(extrapolation, degree): """Test feature names are correct for different extrapolations and degree. Non-regression test for gh-25292. """ X = np.arange(20).reshape(10, 2) splt = SplineTransformer(degree=degree, extrapolation=extrapolation)....
Test feature names are correct for different extrapolations and degree. Non-regression test for gh-25292.
test_split_transform_feature_names_extrapolation_degree
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_polynomial.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_polynomial.py
BSD-3-Clause
def test_spline_transformer_unity_decomposition(degree, n_knots, knots, extrapolation): """Test that B-splines are indeed a decomposition of unity. Splines basis functions must sum up to 1 per row, if we stay in between boundaries. """ X = np.linspace(0, 1, 100)[:, None] # make the boundaries 0 and...
Test that B-splines are indeed a decomposition of unity. Splines basis functions must sum up to 1 per row, if we stay in between boundaries.
test_spline_transformer_unity_decomposition
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_polynomial.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_polynomial.py
BSD-3-Clause
def test_spline_transformer_linear_regression(bias, intercept): """Test that B-splines fit a sinusodial curve pretty well.""" X = np.linspace(0, 10, 100)[:, None] y = np.sin(X[:, 0]) + 2 # +2 to avoid the value 0 in assert_allclose pipe = Pipeline( steps=[ ( "spline"...
Test that B-splines fit a sinusodial curve pretty well.
test_spline_transformer_linear_regression
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_polynomial.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_polynomial.py
BSD-3-Clause
def test_spline_transformer_get_base_knot_positions( knots, n_knots, sample_weight, expected_knots ): """Check the behaviour to find knot positions with and without sample_weight.""" X = np.array([[0, 2], [0, 2], [2, 2], [3, 3], [4, 6], [5, 8], [6, 14]]) base_knots = SplineTransformer._get_base_knot_pos...
Check the behaviour to find knot positions with and without sample_weight.
test_spline_transformer_get_base_knot_positions
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_polynomial.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_polynomial.py
BSD-3-Clause
def test_spline_transformer_periodic_linear_regression(bias, intercept): """Test that B-splines fit a periodic curve pretty well.""" # "+ 3" to avoid the value 0 in assert_allclose def f(x): return np.sin(2 * np.pi * x) - np.sin(8 * np.pi * x) + 3 X = np.linspace(0, 1, 101)[:, None] pipe =...
Test that B-splines fit a periodic curve pretty well.
test_spline_transformer_periodic_linear_regression
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_polynomial.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_polynomial.py
BSD-3-Clause
def test_spline_transformer_periodic_spline_backport(): """Test that the backport of extrapolate="periodic" works correctly""" X = np.linspace(-2, 3.5, 10)[:, None] degree = 2 # Use periodic extrapolation backport in SplineTransformer transformer = SplineTransformer( degree=degree, extrapol...
Test that the backport of extrapolate="periodic" works correctly
test_spline_transformer_periodic_spline_backport
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_polynomial.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_polynomial.py
BSD-3-Clause
def test_spline_transformer_periodic_splines_periodicity(): """Test if shifted knots result in the same transformation up to permutation.""" X = np.linspace(0, 10, 101)[:, None] transformer_1 = SplineTransformer( degree=3, extrapolation="periodic", knots=[[0.0], [1.0], [3.0], [4.0],...
Test if shifted knots result in the same transformation up to permutation.
test_spline_transformer_periodic_splines_periodicity
python
scikit-learn/scikit-learn
sklearn/preprocessing/tests/test_polynomial.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/preprocessing/tests/test_polynomial.py
BSD-3-Clause