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 inverse_transform(self, X):
"""Reverse the transformation operation.
Parameters
----------
X : array of shape [n_samples, n_selected_features]
The input samples.
Returns
-------
X_original : array of shape [n_samples, n_original_features]
... | Reverse the transformation operation.
Parameters
----------
X : array of shape [n_samples, n_selected_features]
The input samples.
Returns
-------
X_original : array of shape [n_samples, n_original_features]
`X` with columns of zeros inserted whe... | inverse_transform | python | scikit-learn/scikit-learn | sklearn/feature_selection/_base.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/feature_selection/_base.py | BSD-3-Clause |
def get_feature_names_out(self, input_features=None):
"""Mask feature names according to selected features.
Parameters
----------
input_features : array-like of str or None, default=None
Input features.
- If `input_features` is `None`, then `feature_names_in_` i... | Mask feature names according to selected features.
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_` ... | get_feature_names_out | python | scikit-learn/scikit-learn | sklearn/feature_selection/_base.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/feature_selection/_base.py | BSD-3-Clause |
def _get_feature_importances(estimator, getter, transform_func=None, norm_order=1):
"""
Retrieve and aggregate (ndim > 1) the feature importances
from an estimator. Also optionally applies transformation.
Parameters
----------
estimator : estimator
A scikit-learn estimator from which w... |
Retrieve and aggregate (ndim > 1) the feature importances
from an estimator. Also optionally applies transformation.
Parameters
----------
estimator : estimator
A scikit-learn estimator from which we want to get the feature
importances.
getter : "auto", str or callable
... | _get_feature_importances | python | scikit-learn/scikit-learn | sklearn/feature_selection/_base.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/feature_selection/_base.py | BSD-3-Clause |
def fit(self, X, y=None, **fit_params):
"""Fit the SelectFromModel meta-transformer.
Parameters
----------
X : array-like of shape (n_samples, n_features)
The training input samples.
y : array-like of shape (n_samples,), default=None
The target values (i... | Fit the SelectFromModel meta-transformer.
Parameters
----------
X : array-like of shape (n_samples, n_features)
The training input samples.
y : array-like of shape (n_samples,), default=None
The target values (integers that correspond to classes in
c... | fit | python | scikit-learn/scikit-learn | sklearn/feature_selection/_from_model.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/feature_selection/_from_model.py | BSD-3-Clause |
def threshold_(self):
"""Threshold value used for feature selection."""
scores = _get_feature_importances(
estimator=self.estimator_,
getter=self.importance_getter,
transform_func="norm",
norm_order=self.norm_order,
)
return _calculate_thre... | Threshold value used for feature selection. | threshold_ | python | scikit-learn/scikit-learn | sklearn/feature_selection/_from_model.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/feature_selection/_from_model.py | BSD-3-Clause |
def partial_fit(self, X, y=None, **partial_fit_params):
"""Fit the SelectFromModel meta-transformer only once.
Parameters
----------
X : array-like of shape (n_samples, n_features)
The training input samples.
y : array-like of shape (n_samples,), default=None
... | Fit the SelectFromModel meta-transformer only once.
Parameters
----------
X : array-like of shape (n_samples, n_features)
The training input samples.
y : array-like of shape (n_samples,), default=None
The target values (integers that correspond to classes in
... | partial_fit | python | scikit-learn/scikit-learn | sklearn/feature_selection/_from_model.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/feature_selection/_from_model.py | BSD-3-Clause |
def n_features_in_(self):
"""Number of features seen during `fit`."""
# For consistency with other estimators we raise a AttributeError so
# that hasattr() fails if the estimator isn't fitted.
try:
check_is_fitted(self)
except NotFittedError as nfe:
raise ... | Number of features seen during `fit`. | n_features_in_ | python | scikit-learn/scikit-learn | sklearn/feature_selection/_from_model.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/feature_selection/_from_model.py | BSD-3-Clause |
def get_metadata_routing(self):
"""Get metadata routing of this object.
Please check :ref:`User Guide <metadata_routing>` on how the routing
mechanism works.
.. versionadded:: 1.4
Returns
-------
routing : MetadataRouter
A :class:`~sklearn.utils.met... | Get metadata routing of this object.
Please check :ref:`User Guide <metadata_routing>` on how the routing
mechanism works.
.. versionadded:: 1.4
Returns
-------
routing : MetadataRouter
A :class:`~sklearn.utils.metadata_routing.MetadataRouter` encapsulating... | get_metadata_routing | python | scikit-learn/scikit-learn | sklearn/feature_selection/_from_model.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/feature_selection/_from_model.py | BSD-3-Clause |
def _compute_mi_cc(x, y, n_neighbors):
"""Compute mutual information between two continuous variables.
Parameters
----------
x, y : ndarray, shape (n_samples,)
Samples of two continuous random variables, must have an identical
shape.
n_neighbors : int
Number of nearest neig... | Compute mutual information between two continuous variables.
Parameters
----------
x, y : ndarray, shape (n_samples,)
Samples of two continuous random variables, must have an identical
shape.
n_neighbors : int
Number of nearest neighbors to search for each point, see [1]_.
... | _compute_mi_cc | python | scikit-learn/scikit-learn | sklearn/feature_selection/_mutual_info.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/feature_selection/_mutual_info.py | BSD-3-Clause |
def _compute_mi_cd(c, d, n_neighbors):
"""Compute mutual information between continuous and discrete variables.
Parameters
----------
c : ndarray, shape (n_samples,)
Samples of a continuous random variable.
d : ndarray, shape (n_samples,)
Samples of a discrete random variable.
... | Compute mutual information between continuous and discrete variables.
Parameters
----------
c : ndarray, shape (n_samples,)
Samples of a continuous random variable.
d : ndarray, shape (n_samples,)
Samples of a discrete random variable.
n_neighbors : int
Number of nearest n... | _compute_mi_cd | python | scikit-learn/scikit-learn | sklearn/feature_selection/_mutual_info.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/feature_selection/_mutual_info.py | BSD-3-Clause |
def _compute_mi(x, y, x_discrete, y_discrete, n_neighbors=3):
"""Compute mutual information between two variables.
This is a simple wrapper which selects a proper function to call based on
whether `x` and `y` are discrete or not.
"""
if x_discrete and y_discrete:
return mutual_info_score(x,... | Compute mutual information between two variables.
This is a simple wrapper which selects a proper function to call based on
whether `x` and `y` are discrete or not.
| _compute_mi | python | scikit-learn/scikit-learn | sklearn/feature_selection/_mutual_info.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/feature_selection/_mutual_info.py | BSD-3-Clause |
def _iterate_columns(X, columns=None):
"""Iterate over columns of a matrix.
Parameters
----------
X : ndarray or csc_matrix, shape (n_samples, n_features)
Matrix over which to iterate.
columns : iterable or None, default=None
Indices of columns to iterate over. If None, iterate ove... | Iterate over columns of a matrix.
Parameters
----------
X : ndarray or csc_matrix, shape (n_samples, n_features)
Matrix over which to iterate.
columns : iterable or None, default=None
Indices of columns to iterate over. If None, iterate over all columns.
Yields
------
x : ... | _iterate_columns | python | scikit-learn/scikit-learn | sklearn/feature_selection/_mutual_info.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/feature_selection/_mutual_info.py | BSD-3-Clause |
def _estimate_mi(
X,
y,
*,
discrete_features="auto",
discrete_target=False,
n_neighbors=3,
copy=True,
random_state=None,
n_jobs=None,
):
"""Estimate mutual information between the features and the target.
Parameters
----------
X : array-like or sparse matrix, shape (... | Estimate mutual information between the features and the target.
Parameters
----------
X : array-like or sparse matrix, shape (n_samples, n_features)
Feature matrix.
y : array-like of shape (n_samples,)
Target vector.
discrete_features : {'auto', bool, array-like}, default='auto'
... | _estimate_mi | python | scikit-learn/scikit-learn | sklearn/feature_selection/_mutual_info.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/feature_selection/_mutual_info.py | BSD-3-Clause |
def mutual_info_regression(
X,
y,
*,
discrete_features="auto",
n_neighbors=3,
copy=True,
random_state=None,
n_jobs=None,
):
"""Estimate mutual information for a continuous target variable.
Mutual information (MI) [1]_ between two random variables is a non-negative
value, whi... | Estimate mutual information for a continuous target variable.
Mutual information (MI) [1]_ between two random variables is a non-negative
value, which measures the dependency between the variables. It is equal
to zero if and only if two random variables are independent, and higher
values mean higher de... | mutual_info_regression | python | scikit-learn/scikit-learn | sklearn/feature_selection/_mutual_info.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/feature_selection/_mutual_info.py | BSD-3-Clause |
def mutual_info_classif(
X,
y,
*,
discrete_features="auto",
n_neighbors=3,
copy=True,
random_state=None,
n_jobs=None,
):
"""Estimate mutual information for a discrete target variable.
Mutual information (MI) [1]_ between two random variables is a non-negative
value, which me... | Estimate mutual information for a discrete target variable.
Mutual information (MI) [1]_ between two random variables is a non-negative
value, which measures the dependency between the variables. It is equal
to zero if and only if two random variables are independent, and higher
values mean higher depe... | mutual_info_classif | python | scikit-learn/scikit-learn | sklearn/feature_selection/_mutual_info.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/feature_selection/_mutual_info.py | BSD-3-Clause |
def _rfe_single_fit(rfe, estimator, X, y, train, test, scorer, routed_params):
"""
Return the score and n_features per step for a fit across one fold.
"""
X_train, y_train = _safe_split(estimator, X, y, train)
X_test, y_test = _safe_split(estimator, X, y, test, train)
fit_params = _check_method_... |
Return the score and n_features per step for a fit across one fold.
| _rfe_single_fit | python | scikit-learn/scikit-learn | sklearn/feature_selection/_rfe.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/feature_selection/_rfe.py | BSD-3-Clause |
def fit(self, X, y, **fit_params):
"""Fit the RFE model and then the underlying estimator on the selected features.
Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_features)
The training input samples.
y : array-like of shape (n_samples,... | Fit the RFE model and then the underlying estimator on the selected features.
Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_features)
The training input samples.
y : array-like of shape (n_samples,)
The target values.
**fi... | fit | python | scikit-learn/scikit-learn | sklearn/feature_selection/_rfe.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/feature_selection/_rfe.py | BSD-3-Clause |
def predict(self, X, **predict_params):
"""Reduce X to the selected features and predict using the estimator.
Parameters
----------
X : array of shape [n_samples, n_features]
The input samples.
**predict_params : dict
Parameters to route to the ``predict... | Reduce X to the selected features and predict using the estimator.
Parameters
----------
X : array of shape [n_samples, n_features]
The input samples.
**predict_params : dict
Parameters to route to the ``predict`` method of the
underlying estimator.
... | predict | python | scikit-learn/scikit-learn | sklearn/feature_selection/_rfe.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/feature_selection/_rfe.py | BSD-3-Clause |
def score(self, X, y, **score_params):
"""Reduce X to the selected features and return the score of the estimator.
Parameters
----------
X : array of shape [n_samples, n_features]
The input samples.
y : array of shape [n_samples]
The target values.
... | Reduce X to the selected features and return the score of the estimator.
Parameters
----------
X : array of shape [n_samples, n_features]
The input samples.
y : array of shape [n_samples]
The target values.
**score_params : dict
- If `enable... | score | python | scikit-learn/scikit-learn | sklearn/feature_selection/_rfe.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/feature_selection/_rfe.py | BSD-3-Clause |
def get_metadata_routing(self):
"""Get metadata routing of this object.
Please check :ref:`User Guide <metadata_routing>` on how the routing
mechanism works.
.. versionadded:: 1.6
Returns
-------
routing : MetadataRouter
A :class:`~sklearn.utils.met... | Get metadata routing of this object.
Please check :ref:`User Guide <metadata_routing>` on how the routing
mechanism works.
.. versionadded:: 1.6
Returns
-------
routing : MetadataRouter
A :class:`~sklearn.utils.metadata_routing.MetadataRouter` encapsulating... | get_metadata_routing | python | scikit-learn/scikit-learn | sklearn/feature_selection/_rfe.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/feature_selection/_rfe.py | BSD-3-Clause |
def fit(self, X, y, *, groups=None, **params):
"""Fit the RFE model and automatically tune the number of selected features.
Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_features)
Training vector, where `n_samples` is the number of samples and
... | Fit the RFE model and automatically tune the number of selected features.
Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_features)
Training vector, where `n_samples` is the number of samples and
`n_features` is the total number of features.
... | fit | python | scikit-learn/scikit-learn | sklearn/feature_selection/_rfe.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/feature_selection/_rfe.py | BSD-3-Clause |
def score(self, X, y, **score_params):
"""Score using the `scoring` option on the given test data and labels.
Parameters
----------
X : array-like of shape (n_samples, n_features)
Test samples.
y : array-like of shape (n_samples,)
True labels for X.
... | Score using the `scoring` option on the given test data and labels.
Parameters
----------
X : array-like of shape (n_samples, n_features)
Test samples.
y : array-like of shape (n_samples,)
True labels for X.
**score_params : dict
Parameters ... | score | python | scikit-learn/scikit-learn | sklearn/feature_selection/_rfe.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/feature_selection/_rfe.py | BSD-3-Clause |
def get_metadata_routing(self):
"""Get metadata routing of this object.
Please check :ref:`User Guide <metadata_routing>` on how the routing
mechanism works.
.. versionadded:: 1.6
Returns
-------
routing : MetadataRouter
A :class:`~sklearn.utils.met... | Get metadata routing of this object.
Please check :ref:`User Guide <metadata_routing>` on how the routing
mechanism works.
.. versionadded:: 1.6
Returns
-------
routing : MetadataRouter
A :class:`~sklearn.utils.metadata_routing.MetadataRouter` encapsulating... | get_metadata_routing | python | scikit-learn/scikit-learn | sklearn/feature_selection/_rfe.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/feature_selection/_rfe.py | BSD-3-Clause |
def fit(self, X, y=None, **params):
"""Learn the features to select from X.
Parameters
----------
X : array-like of shape (n_samples, n_features)
Training vectors, where `n_samples` is the number of samples and
`n_features` is the number of predictors.
y... | Learn the features to select from X.
Parameters
----------
X : array-like of shape (n_samples, n_features)
Training vectors, where `n_samples` is the number of samples and
`n_features` is the number of predictors.
y : array-like of shape (n_samples,), default=No... | fit | python | scikit-learn/scikit-learn | sklearn/feature_selection/_sequential.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/feature_selection/_sequential.py | BSD-3-Clause |
def get_metadata_routing(self):
"""Get metadata routing of this object.
Please check :ref:`User Guide <metadata_routing>` on how the routing
mechanism works.
.. versionadded:: 1.6
Returns
-------
routing : MetadataRouter
A :class:`~sklearn.utils.met... | Get metadata routing of this object.
Please check :ref:`User Guide <metadata_routing>` on how the routing
mechanism works.
.. versionadded:: 1.6
Returns
-------
routing : MetadataRouter
A :class:`~sklearn.utils.metadata_routing.MetadataRouter` encapsulating... | get_metadata_routing | python | scikit-learn/scikit-learn | sklearn/feature_selection/_sequential.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/feature_selection/_sequential.py | BSD-3-Clause |
def _clean_nans(scores):
"""
Fixes Issue #1240: NaNs can't be properly compared, so change them to the
smallest value of scores's dtype. -inf seems to be unreliable.
"""
# XXX where should this function be called? fit? scoring functions
# themselves?
scores = as_float_array(scores, copy=True... |
Fixes Issue #1240: NaNs can't be properly compared, so change them to the
smallest value of scores's dtype. -inf seems to be unreliable.
| _clean_nans | python | scikit-learn/scikit-learn | sklearn/feature_selection/_univariate_selection.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/feature_selection/_univariate_selection.py | BSD-3-Clause |
def f_oneway(*args):
"""Perform a 1-way ANOVA.
The one-way ANOVA tests the null hypothesis that 2 or more groups have
the same population mean. The test is applied to samples from two or
more groups, possibly with differing sizes.
Read more in the :ref:`User Guide <univariate_feature_selection>`.
... | Perform a 1-way ANOVA.
The one-way ANOVA tests the null hypothesis that 2 or more groups have
the same population mean. The test is applied to samples from two or
more groups, possibly with differing sizes.
Read more in the :ref:`User Guide <univariate_feature_selection>`.
Parameters
--------... | f_oneway | python | scikit-learn/scikit-learn | sklearn/feature_selection/_univariate_selection.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/feature_selection/_univariate_selection.py | BSD-3-Clause |
def f_classif(X, y):
"""Compute the ANOVA F-value for the provided sample.
Read more in the :ref:`User Guide <univariate_feature_selection>`.
Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_features)
The set of regressors that will be tested sequentially.
... | Compute the ANOVA F-value for the provided sample.
Read more in the :ref:`User Guide <univariate_feature_selection>`.
Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_features)
The set of regressors that will be tested sequentially.
y : array-like of shape (n_s... | f_classif | python | scikit-learn/scikit-learn | sklearn/feature_selection/_univariate_selection.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/feature_selection/_univariate_selection.py | BSD-3-Clause |
def _chisquare(f_obs, f_exp):
"""Fast replacement for scipy.stats.chisquare.
Version from https://github.com/scipy/scipy/pull/2525 with additional
optimizations.
"""
f_obs = np.asarray(f_obs, dtype=np.float64)
k = len(f_obs)
# Reuse f_obs for chi-squared statistics
chisq = f_obs
ch... | Fast replacement for scipy.stats.chisquare.
Version from https://github.com/scipy/scipy/pull/2525 with additional
optimizations.
| _chisquare | python | scikit-learn/scikit-learn | sklearn/feature_selection/_univariate_selection.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/feature_selection/_univariate_selection.py | BSD-3-Clause |
def chi2(X, y):
"""Compute chi-squared stats between each non-negative feature and class.
This score can be used to select the `n_features` features with the
highest values for the test chi-squared statistic from X, which must
contain only **non-negative integer feature values** such as booleans or fre... | Compute chi-squared stats between each non-negative feature and class.
This score can be used to select the `n_features` features with the
highest values for the test chi-squared statistic from X, which must
contain only **non-negative integer feature values** such as booleans or frequencies
(e.g., ter... | chi2 | python | scikit-learn/scikit-learn | sklearn/feature_selection/_univariate_selection.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/feature_selection/_univariate_selection.py | BSD-3-Clause |
def r_regression(X, y, *, center=True, force_finite=True):
"""Compute Pearson's r for each features and the target.
Pearson's r is also known as the Pearson correlation coefficient.
Linear model for testing the individual effect of each of many regressors.
This is a scoring function to be used in a fe... | Compute Pearson's r for each features and the target.
Pearson's r is also known as the Pearson correlation coefficient.
Linear model for testing the individual effect of each of many regressors.
This is a scoring function to be used in a feature selection procedure, not
a free standing feature selecti... | r_regression | python | scikit-learn/scikit-learn | sklearn/feature_selection/_univariate_selection.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/feature_selection/_univariate_selection.py | BSD-3-Clause |
def f_regression(X, y, *, center=True, force_finite=True):
"""Univariate linear regression tests returning F-statistic and p-values.
Quick linear model for testing the effect of a single regressor,
sequentially for many regressors.
This is done in 2 steps:
1. The cross correlation between each re... | Univariate linear regression tests returning F-statistic and p-values.
Quick linear model for testing the effect of a single regressor,
sequentially for many regressors.
This is done in 2 steps:
1. The cross correlation between each regressor and the target is computed
using :func:`r_regressio... | f_regression | python | scikit-learn/scikit-learn | sklearn/feature_selection/_univariate_selection.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/feature_selection/_univariate_selection.py | BSD-3-Clause |
def fit(self, X, y=None):
"""Run score function on (X, y) and get the appropriate features.
Parameters
----------
X : array-like of shape (n_samples, n_features)
The training input samples.
y : array-like of shape (n_samples,) or None
The target values (... | Run score function on (X, y) and get the appropriate features.
Parameters
----------
X : array-like of shape (n_samples, n_features)
The training input samples.
y : array-like of shape (n_samples,) or None
The target values (class labels in classification, real ... | fit | python | scikit-learn/scikit-learn | sklearn/feature_selection/_univariate_selection.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/feature_selection/_univariate_selection.py | BSD-3-Clause |
def fit(self, X, y=None):
"""Learn empirical variances from X.
Parameters
----------
X : {array-like, sparse matrix}, shape (n_samples, n_features)
Data from which to compute variances, where `n_samples` is
the number of samples and `n_features` is the number of ... | Learn empirical variances from X.
Parameters
----------
X : {array-like, sparse matrix}, shape (n_samples, n_features)
Data from which to compute variances, where `n_samples` is
the number of samples and `n_features` is the number of features.
y : any, default=N... | fit | python | scikit-learn/scikit-learn | sklearn/feature_selection/_variance_threshold.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/feature_selection/_variance_threshold.py | BSD-3-Clause |
def test_output_dataframe():
"""Check output dtypes for dataframes is consistent with the input dtypes."""
pd = pytest.importorskip("pandas")
X = pd.DataFrame(
{
"a": pd.Series([1.0, 2.4, 4.5], dtype=np.float32),
"b": pd.Series(["a", "b", "a"], dtype="category"),
... | Check output dtypes for dataframes is consistent with the input dtypes. | test_output_dataframe | python | scikit-learn/scikit-learn | sklearn/feature_selection/tests/test_base.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/feature_selection/tests/test_base.py | BSD-3-Clause |
def test_r_regression_force_finite(X, y, expected_corr_coef, force_finite):
"""Check the behaviour of `force_finite` for some corner cases with `r_regression`.
Non-regression test for:
https://github.com/scikit-learn/scikit-learn/issues/15672
"""
with warnings.catch_warnings():
warnings.sim... | Check the behaviour of `force_finite` for some corner cases with `r_regression`.
Non-regression test for:
https://github.com/scikit-learn/scikit-learn/issues/15672
| test_r_regression_force_finite | python | scikit-learn/scikit-learn | sklearn/feature_selection/tests/test_feature_select.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/feature_selection/tests/test_feature_select.py | BSD-3-Clause |
def test_f_regression_corner_case(
X, y, expected_f_statistic, expected_p_values, force_finite
):
"""Check the behaviour of `force_finite` for some corner cases with `f_regression`.
Non-regression test for:
https://github.com/scikit-learn/scikit-learn/issues/15672
"""
with warnings.catch_warnin... | Check the behaviour of `force_finite` for some corner cases with `f_regression`.
Non-regression test for:
https://github.com/scikit-learn/scikit-learn/issues/15672
| test_f_regression_corner_case | python | scikit-learn/scikit-learn | sklearn/feature_selection/tests/test_feature_select.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/feature_selection/tests/test_feature_select.py | BSD-3-Clause |
def test_dataframe_output_dtypes():
"""Check that the output datafarme dtypes are the same as the input.
Non-regression test for gh-24860.
"""
pd = pytest.importorskip("pandas")
X, y = load_iris(return_X_y=True, as_frame=True)
X = X.astype(
{
"petal length (cm)": np.float32... | Check that the output datafarme dtypes are the same as the input.
Non-regression test for gh-24860.
| test_dataframe_output_dtypes | python | scikit-learn/scikit-learn | sklearn/feature_selection/tests/test_feature_select.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/feature_selection/tests/test_feature_select.py | BSD-3-Clause |
def test_unsupervised_filter(selector):
"""Check support for unsupervised feature selection for the filter that could
require only `X`.
"""
rng = np.random.RandomState(0)
X = rng.randn(10, 5)
def score_func(X, y=None):
return np.array([1, 1, 1, 1, 0])
selector.set_params(score_func... | Check support for unsupervised feature selection for the filter that could
require only `X`.
| test_unsupervised_filter | python | scikit-learn/scikit-learn | sklearn/feature_selection/tests/test_feature_select.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/feature_selection/tests/test_feature_select.py | BSD-3-Clause |
def test_inferred_max_features_integer(max_features):
"""Check max_features_ and output shape for integer max_features."""
clf = RandomForestClassifier(n_estimators=5, random_state=0)
transformer = SelectFromModel(
estimator=clf, max_features=max_features, threshold=-np.inf
)
X_trans = trans... | Check max_features_ and output shape for integer max_features. | test_inferred_max_features_integer | python | scikit-learn/scikit-learn | sklearn/feature_selection/tests/test_from_model.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/feature_selection/tests/test_from_model.py | BSD-3-Clause |
def test_inferred_max_features_callable(max_features):
"""Check max_features_ and output shape for callable max_features."""
clf = RandomForestClassifier(n_estimators=5, random_state=0)
transformer = SelectFromModel(
estimator=clf, max_features=max_features, threshold=-np.inf
)
X_trans = tra... | Check max_features_ and output shape for callable max_features. | test_inferred_max_features_callable | python | scikit-learn/scikit-learn | sklearn/feature_selection/tests/test_from_model.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/feature_selection/tests/test_from_model.py | BSD-3-Clause |
def test_max_features_callable_data(max_features):
"""Tests that the callable passed to `fit` is called on X."""
clf = RandomForestClassifier(n_estimators=50, random_state=0)
m = Mock(side_effect=max_features)
transformer = SelectFromModel(estimator=clf, max_features=m, threshold=-np.inf)
transforme... | Tests that the callable passed to `fit` is called on X. | test_max_features_callable_data | python | scikit-learn/scikit-learn | sklearn/feature_selection/tests/test_from_model.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/feature_selection/tests/test_from_model.py | BSD-3-Clause |
def test_prefit_max_features():
"""Check the interaction between `prefit` and `max_features`."""
# case 1: an error should be raised at `transform` if `fit` was not called to
# validate the attributes
estimator = RandomForestClassifier(n_estimators=5, random_state=0)
estimator.fit(data, y)
model... | Check the interaction between `prefit` and `max_features`. | test_prefit_max_features | python | scikit-learn/scikit-learn | sklearn/feature_selection/tests/test_from_model.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/feature_selection/tests/test_from_model.py | BSD-3-Clause |
def test_get_feature_names_out_elasticnetcv():
"""Check if ElasticNetCV works with a list of floats.
Non-regression test for #30936."""
X, y = make_regression(n_features=5, n_informative=3, random_state=0)
estimator = ElasticNetCV(l1_ratio=[0.25, 0.5, 0.75], random_state=0)
selector = SelectFromMod... | Check if ElasticNetCV works with a list of floats.
Non-regression test for #30936. | test_get_feature_names_out_elasticnetcv | python | scikit-learn/scikit-learn | sklearn/feature_selection/tests/test_from_model.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/feature_selection/tests/test_from_model.py | BSD-3-Clause |
def test_prefit_get_feature_names_out():
"""Check the interaction between prefit and the feature names."""
clf = RandomForestClassifier(n_estimators=2, random_state=0)
clf.fit(data, y)
model = SelectFromModel(clf, prefit=True, max_features=1)
name = type(model).__name__
err_msg = (
f"Th... | Check the interaction between prefit and the feature names. | test_prefit_get_feature_names_out | python | scikit-learn/scikit-learn | sklearn/feature_selection/tests/test_from_model.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/feature_selection/tests/test_from_model.py | BSD-3-Clause |
def test_select_from_model_pls(PLSEstimator):
"""Check the behaviour of SelectFromModel with PLS estimators.
Non-regression test for:
https://github.com/scikit-learn/scikit-learn/issues/12410
"""
X, y = make_friedman1(n_samples=50, n_features=10, random_state=0)
estimator = PLSEstimator(n_compo... | Check the behaviour of SelectFromModel with PLS estimators.
Non-regression test for:
https://github.com/scikit-learn/scikit-learn/issues/12410
| test_select_from_model_pls | python | scikit-learn/scikit-learn | sklearn/feature_selection/tests/test_from_model.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/feature_selection/tests/test_from_model.py | BSD-3-Clause |
def test_estimator_does_not_support_feature_names():
"""SelectFromModel works with estimators that do not support feature_names_in_.
Non-regression test for #21949.
"""
pytest.importorskip("pandas")
X, y = datasets.load_iris(as_frame=True, return_X_y=True)
all_feature_names = set(X.columns)
... | SelectFromModel works with estimators that do not support feature_names_in_.
Non-regression test for #21949.
| test_estimator_does_not_support_feature_names | python | scikit-learn/scikit-learn | sklearn/feature_selection/tests/test_from_model.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/feature_selection/tests/test_from_model.py | BSD-3-Clause |
def test_from_model_estimator_attribute_error():
"""Check that we raise the proper AttributeError when the estimator
does not implement the `partial_fit` method, which is decorated with
`available_if`.
Non-regression test for:
https://github.com/scikit-learn/scikit-learn/issues/28108
"""
# ... | Check that we raise the proper AttributeError when the estimator
does not implement the `partial_fit` method, which is decorated with
`available_if`.
Non-regression test for:
https://github.com/scikit-learn/scikit-learn/issues/28108
| test_from_model_estimator_attribute_error | python | scikit-learn/scikit-learn | sklearn/feature_selection/tests/test_from_model.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/feature_selection/tests/test_from_model.py | BSD-3-Clause |
def test_mutual_information_symmetry_classif_regression(correlated, global_random_seed):
"""Check that `mutual_info_classif` and `mutual_info_regression` are
symmetric by switching the target `y` as `feature` in `X` and vice
versa.
Non-regression test for:
https://github.com/scikit-learn/scikit-lea... | Check that `mutual_info_classif` and `mutual_info_regression` are
symmetric by switching the target `y` as `feature` in `X` and vice
versa.
Non-regression test for:
https://github.com/scikit-learn/scikit-learn/issues/23720
| test_mutual_information_symmetry_classif_regression | python | scikit-learn/scikit-learn | sklearn/feature_selection/tests/test_mutual_info.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/feature_selection/tests/test_mutual_info.py | BSD-3-Clause |
def test_mutual_info_regression_X_int_dtype(global_random_seed):
"""Check that results agree when X is integer dtype and float dtype.
Non-regression test for Issue #26696.
"""
rng = np.random.RandomState(global_random_seed)
X = rng.randint(100, size=(100, 10))
X_float = X.astype(np.float64, cop... | Check that results agree when X is integer dtype and float dtype.
Non-regression test for Issue #26696.
| test_mutual_info_regression_X_int_dtype | python | scikit-learn/scikit-learn | sklearn/feature_selection/tests/test_mutual_info.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/feature_selection/tests/test_mutual_info.py | BSD-3-Clause |
def test_mutual_info_n_jobs(global_random_seed, mutual_info_func, data_generator):
"""Check that results are consistent with different `n_jobs`."""
X, y = data_generator(random_state=global_random_seed)
single_job = mutual_info_func(X, y, random_state=global_random_seed, n_jobs=1)
multi_job = mutual_inf... | Check that results are consistent with different `n_jobs`. | test_mutual_info_n_jobs | python | scikit-learn/scikit-learn | sklearn/feature_selection/tests/test_mutual_info.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/feature_selection/tests/test_mutual_info.py | BSD-3-Clause |
def test_pipeline_with_nans(ClsRFE):
"""Check that RFE works with pipeline that accept nans.
Non-regression test for gh-21743.
"""
X, y = load_iris(return_X_y=True)
X[0, 0] = np.nan
pipe = make_pipeline(
SimpleImputer(),
StandardScaler(),
LogisticRegression(),
)
... | Check that RFE works with pipeline that accept nans.
Non-regression test for gh-21743.
| test_pipeline_with_nans | python | scikit-learn/scikit-learn | sklearn/feature_selection/tests/test_rfe.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/feature_selection/tests/test_rfe.py | BSD-3-Clause |
def test_rfe_pls(ClsRFE, PLSEstimator):
"""Check the behaviour of RFE with PLS estimators.
Non-regression test for:
https://github.com/scikit-learn/scikit-learn/issues/12410
"""
X, y = make_friedman1(n_samples=50, n_features=10, random_state=0)
estimator = PLSEstimator(n_components=1)
selec... | Check the behaviour of RFE with PLS estimators.
Non-regression test for:
https://github.com/scikit-learn/scikit-learn/issues/12410
| test_rfe_pls | python | scikit-learn/scikit-learn | sklearn/feature_selection/tests/test_rfe.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/feature_selection/tests/test_rfe.py | BSD-3-Clause |
def test_rfe_estimator_attribute_error():
"""Check that we raise the proper AttributeError when the estimator
does not implement the `decision_function` method, which is decorated with
`available_if`.
Non-regression test for:
https://github.com/scikit-learn/scikit-learn/issues/28108
"""
iri... | Check that we raise the proper AttributeError when the estimator
does not implement the `decision_function` method, which is decorated with
`available_if`.
Non-regression test for:
https://github.com/scikit-learn/scikit-learn/issues/28108
| test_rfe_estimator_attribute_error | python | scikit-learn/scikit-learn | sklearn/feature_selection/tests/test_rfe.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/feature_selection/tests/test_rfe.py | BSD-3-Clause |
def test_rfe_n_features_to_select_warning(ClsRFE, param):
"""Check if the correct warning is raised when trying to initialize a RFE
object with a n_features_to_select attribute larger than the number of
features present in the X variable that is passed to the fit method
"""
X, y = make_classificatio... | Check if the correct warning is raised when trying to initialize a RFE
object with a n_features_to_select attribute larger than the number of
features present in the X variable that is passed to the fit method
| test_rfe_n_features_to_select_warning | python | scikit-learn/scikit-learn | sklearn/feature_selection/tests/test_rfe.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/feature_selection/tests/test_rfe.py | BSD-3-Clause |
def test_rfe_with_sample_weight():
"""Test that `RFE` works correctly with sample weights."""
X, y = make_classification(random_state=0)
n_samples = X.shape[0]
# Assign the first half of the samples with twice the weight
sample_weight = np.ones_like(y)
sample_weight[: n_samples // 2] = 2
#... | Test that `RFE` works correctly with sample weights. | test_rfe_with_sample_weight | python | scikit-learn/scikit-learn | sklearn/feature_selection/tests/test_rfe.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/feature_selection/tests/test_rfe.py | BSD-3-Clause |
def test_results_per_cv_in_rfecv(global_random_seed):
"""
Test that the results of RFECV are consistent across the different folds
in terms of length of the arrays.
"""
X, y = make_classification(random_state=global_random_seed)
clf = LogisticRegression()
rfecv = RFECV(
estimator=cl... |
Test that the results of RFECV are consistent across the different folds
in terms of length of the arrays.
| test_results_per_cv_in_rfecv | python | scikit-learn/scikit-learn | sklearn/feature_selection/tests/test_rfe.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/feature_selection/tests/test_rfe.py | BSD-3-Clause |
def test_n_features_to_select_auto(direction):
"""Check the behaviour of `n_features_to_select="auto"` with different
values for the parameter `tol`.
"""
n_features = 10
tol = 1e-3
X, y = make_regression(n_features=n_features, random_state=0)
sfs = SequentialFeatureSelector(
LinearR... | Check the behaviour of `n_features_to_select="auto"` with different
values for the parameter `tol`.
| test_n_features_to_select_auto | python | scikit-learn/scikit-learn | sklearn/feature_selection/tests/test_sequential.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/feature_selection/tests/test_sequential.py | BSD-3-Clause |
def test_n_features_to_select_stopping_criterion(direction):
"""Check the behaviour stopping criterion for feature selection
depending on the values of `n_features_to_select` and `tol`.
When `direction` is `'forward'`, select a new features at random
among those not currently selected in selector.suppo... | Check the behaviour stopping criterion for feature selection
depending on the values of `n_features_to_select` and `tol`.
When `direction` is `'forward'`, select a new features at random
among those not currently selected in selector.support_,
build a new version of the data that includes all the featu... | test_n_features_to_select_stopping_criterion | python | scikit-learn/scikit-learn | sklearn/feature_selection/tests/test_sequential.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/feature_selection/tests/test_sequential.py | BSD-3-Clause |
def test_forward_neg_tol_error():
"""Check that we raise an error when tol<0 and direction='forward'"""
X, y = make_regression(n_features=10, random_state=0)
sfs = SequentialFeatureSelector(
LinearRegression(),
n_features_to_select="auto",
direction="forward",
tol=-1e-3,
... | Check that we raise an error when tol<0 and direction='forward' | test_forward_neg_tol_error | python | scikit-learn/scikit-learn | sklearn/feature_selection/tests/test_sequential.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/feature_selection/tests/test_sequential.py | BSD-3-Clause |
def test_backward_neg_tol():
"""Check that SequentialFeatureSelector works negative tol
non-regression test for #25525
"""
X, y = make_regression(n_features=10, random_state=0)
lr = LinearRegression()
initial_score = lr.fit(X, y).score(X, y)
sfs = SequentialFeatureSelector(
lr,
... | Check that SequentialFeatureSelector works negative tol
non-regression test for #25525
| test_backward_neg_tol | python | scikit-learn/scikit-learn | sklearn/feature_selection/tests/test_sequential.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/feature_selection/tests/test_sequential.py | BSD-3-Clause |
def test_cv_generator_support():
"""Check that no exception raised when cv is generator
non-regression test for #25957
"""
X, y = make_classification(random_state=0)
groups = np.zeros_like(y, dtype=int)
groups[y.size // 2 :] = 1
cv = LeaveOneGroupOut()
splits = cv.split(X, y, groups=g... | Check that no exception raised when cv is generator
non-regression test for #25957
| test_cv_generator_support | python | scikit-learn/scikit-learn | sklearn/feature_selection/tests/test_sequential.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/feature_selection/tests/test_sequential.py | BSD-3-Clause |
def _estimator_has(attr):
"""Check that final_estimator has `attr`.
Used together with `available_if`.
"""
def check(self):
# raise original `AttributeError` if `attr` does not exist
getattr(self.estimator, attr)
return True
return check | Check that final_estimator has `attr`.
Used together with `available_if`.
| _estimator_has | python | scikit-learn/scikit-learn | sklearn/frozen/_frozen.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/frozen/_frozen.py | BSD-3-Clause |
def set_params(self, **kwargs):
"""Set the parameters of this estimator.
The only valid key here is `estimator`. You cannot set the parameters of the
inner estimator.
Parameters
----------
**kwargs : dict
Estimator parameters.
Returns
------... | Set the parameters of this estimator.
The only valid key here is `estimator`. You cannot set the parameters of the
inner estimator.
Parameters
----------
**kwargs : dict
Estimator parameters.
Returns
-------
self : FrozenEstimator
... | set_params | python | scikit-learn/scikit-learn | sklearn/frozen/_frozen.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/frozen/_frozen.py | BSD-3-Clause |
def test_frozen_methods(estimator, dataset, request, method):
"""Test that frozen.fit doesn't do anything, and that all other methods are
exposed by the frozen estimator and return the same values as the estimator.
"""
X, y = request.getfixturevalue(dataset)
set_random_state(estimator)
estimator... | Test that frozen.fit doesn't do anything, and that all other methods are
exposed by the frozen estimator and return the same values as the estimator.
| test_frozen_methods | python | scikit-learn/scikit-learn | sklearn/frozen/tests/test_frozen.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/frozen/tests/test_frozen.py | BSD-3-Clause |
def test_frozen_metadata_routing(regression_dataset):
"""Test that metadata routing works with frozen estimators."""
class ConsumesMetadata(BaseEstimator):
def __init__(self, on_fit=None, on_predict=None):
self.on_fit = on_fit
self.on_predict = on_predict
def fit(self, ... | Test that metadata routing works with frozen estimators. | test_frozen_metadata_routing | python | scikit-learn/scikit-learn | sklearn/frozen/tests/test_frozen.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/frozen/tests/test_frozen.py | BSD-3-Clause |
def test_composite_fit(classification_dataset):
"""Test that calling fit_transform and fit_predict doesn't call fit."""
class Estimator(BaseEstimator):
def fit(self, X, y):
try:
self._fit_counter += 1
except AttributeError:
self._fit_counter = 1
... | Test that calling fit_transform and fit_predict doesn't call fit. | test_composite_fit | python | scikit-learn/scikit-learn | sklearn/frozen/tests/test_frozen.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/frozen/tests/test_frozen.py | BSD-3-Clause |
def test_clone_frozen(regression_dataset):
"""Test that cloning a frozen estimator keeps the frozen state."""
X, y = regression_dataset
estimator = LinearRegression().fit(X, y)
frozen = FrozenEstimator(estimator)
cloned = clone(frozen)
assert cloned.estimator is estimator | Test that cloning a frozen estimator keeps the frozen state. | test_clone_frozen | python | scikit-learn/scikit-learn | sklearn/frozen/tests/test_frozen.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/frozen/tests/test_frozen.py | BSD-3-Clause |
def test_check_is_fitted(regression_dataset):
"""Test that check_is_fitted works on frozen estimators."""
X, y = regression_dataset
estimator = LinearRegression()
frozen = FrozenEstimator(estimator)
with pytest.raises(NotFittedError):
check_is_fitted(frozen)
estimator = LinearRegressio... | Test that check_is_fitted works on frozen estimators. | test_check_is_fitted | python | scikit-learn/scikit-learn | sklearn/frozen/tests/test_frozen.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/frozen/tests/test_frozen.py | BSD-3-Clause |
def test_frozen_tags():
"""Test that frozen estimators have the same tags as the original estimator
except for the skip_test tag."""
class Estimator(BaseEstimator):
def __sklearn_tags__(self):
tags = super().__sklearn_tags__()
tags.input_tags.categorical = True
r... | Test that frozen estimators have the same tags as the original estimator
except for the skip_test tag. | test_frozen_tags | python | scikit-learn/scikit-learn | sklearn/frozen/tests/test_frozen.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/frozen/tests/test_frozen.py | BSD-3-Clause |
def test_frozen_params():
"""Test that FrozenEstimator only exposes the estimator parameter."""
est = LogisticRegression()
frozen = FrozenEstimator(est)
with pytest.raises(ValueError, match="You cannot set parameters of the inner"):
frozen.set_params(estimator__C=1)
assert frozen.get_param... | Test that FrozenEstimator only exposes the estimator parameter. | test_frozen_params | python | scikit-learn/scikit-learn | sklearn/frozen/tests/test_frozen.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/frozen/tests/test_frozen.py | BSD-3-Clause |
def get_params(self, deep=True):
"""Get parameters of this kernel.
Parameters
----------
deep : bool, default=True
If True, will return the parameters for this estimator and
contained subobjects that are estimators.
Returns
-------
params... | Get parameters of this kernel.
Parameters
----------
deep : bool, default=True
If True, will return the parameters for this estimator and
contained subobjects that are estimators.
Returns
-------
params : dict
Parameter names mapped t... | get_params | python | scikit-learn/scikit-learn | sklearn/gaussian_process/kernels.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/gaussian_process/kernels.py | BSD-3-Clause |
def set_params(self, **params):
"""Set the parameters of this kernel.
The method works on simple kernels as well as on nested kernels.
The latter have parameters of the form ``<component>__<parameter>``
so that it's possible to update each component of a nested object.
Returns
... | Set the parameters of this kernel.
The method works on simple kernels as well as on nested kernels.
The latter have parameters of the form ``<component>__<parameter>``
so that it's possible to update each component of a nested object.
Returns
-------
self
| set_params | python | scikit-learn/scikit-learn | sklearn/gaussian_process/kernels.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/gaussian_process/kernels.py | BSD-3-Clause |
def clone_with_theta(self, theta):
"""Returns a clone of self with given hyperparameters theta.
Parameters
----------
theta : ndarray of shape (n_dims,)
The hyperparameters
"""
cloned = clone(self)
cloned.theta = theta
return cloned | Returns a clone of self with given hyperparameters theta.
Parameters
----------
theta : ndarray of shape (n_dims,)
The hyperparameters
| clone_with_theta | python | scikit-learn/scikit-learn | sklearn/gaussian_process/kernels.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/gaussian_process/kernels.py | BSD-3-Clause |
def hyperparameters(self):
"""Returns a list of all hyperparameter specifications."""
r = [
getattr(self, attr)
for attr in dir(self)
if attr.startswith("hyperparameter_")
]
return r | Returns a list of all hyperparameter specifications. | hyperparameters | python | scikit-learn/scikit-learn | sklearn/gaussian_process/kernels.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/gaussian_process/kernels.py | BSD-3-Clause |
def theta(self):
"""Returns the (flattened, log-transformed) non-fixed hyperparameters.
Note that theta are typically the log-transformed values of the
kernel's hyperparameters as this representation of the search space
is more amenable for hyperparameter search, as hyperparameters like... | Returns the (flattened, log-transformed) non-fixed hyperparameters.
Note that theta are typically the log-transformed values of the
kernel's hyperparameters as this representation of the search space
is more amenable for hyperparameter search, as hyperparameters like
length-scales natur... | theta | python | scikit-learn/scikit-learn | sklearn/gaussian_process/kernels.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/gaussian_process/kernels.py | BSD-3-Clause |
def theta(self, theta):
"""Sets the (flattened, log-transformed) non-fixed hyperparameters.
Parameters
----------
theta : ndarray of shape (n_dims,)
The non-fixed, log-transformed hyperparameters of the kernel
"""
params = self.get_params()
i = 0
... | Sets the (flattened, log-transformed) non-fixed hyperparameters.
Parameters
----------
theta : ndarray of shape (n_dims,)
The non-fixed, log-transformed hyperparameters of the kernel
| theta | python | scikit-learn/scikit-learn | sklearn/gaussian_process/kernels.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/gaussian_process/kernels.py | BSD-3-Clause |
def bounds(self):
"""Returns the log-transformed bounds on the theta.
Returns
-------
bounds : ndarray of shape (n_dims, 2)
The log-transformed bounds on the kernel's hyperparameters theta
"""
bounds = [
hyperparameter.bounds
for hyper... | Returns the log-transformed bounds on the theta.
Returns
-------
bounds : ndarray of shape (n_dims, 2)
The log-transformed bounds on the kernel's hyperparameters theta
| bounds | python | scikit-learn/scikit-learn | sklearn/gaussian_process/kernels.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/gaussian_process/kernels.py | BSD-3-Clause |
def diag(self, X):
"""Returns the diagonal of the kernel k(X, X).
The result of this method is identical to np.diag(self(X)); however,
it can be evaluated more efficiently since only the diagonal is
evaluated.
Parameters
----------
X : array-like of shape (n_sam... | Returns the diagonal of the kernel k(X, X).
The result of this method is identical to np.diag(self(X)); however,
it can be evaluated more efficiently since only the diagonal is
evaluated.
Parameters
----------
X : array-like of shape (n_samples,)
Left argume... | diag | python | scikit-learn/scikit-learn | sklearn/gaussian_process/kernels.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/gaussian_process/kernels.py | BSD-3-Clause |
def _check_bounds_params(self):
"""Called after fitting to warn if bounds may have been too tight."""
list_close = np.isclose(self.bounds, np.atleast_2d(self.theta).T)
idx = 0
for hyp in self.hyperparameters:
if hyp.fixed:
continue
for dim in range... | Called after fitting to warn if bounds may have been too tight. | _check_bounds_params | python | scikit-learn/scikit-learn | sklearn/gaussian_process/kernels.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/gaussian_process/kernels.py | BSD-3-Clause |
def theta(self, theta):
"""Sets the (flattened, log-transformed) non-fixed hyperparameters.
Parameters
----------
theta : array of shape (n_dims,)
The non-fixed, log-transformed hyperparameters of the kernel
"""
k_dims = self.k1.n_dims
for i, kernel i... | Sets the (flattened, log-transformed) non-fixed hyperparameters.
Parameters
----------
theta : array of shape (n_dims,)
The non-fixed, log-transformed hyperparameters of the kernel
| theta | python | scikit-learn/scikit-learn | sklearn/gaussian_process/kernels.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/gaussian_process/kernels.py | BSD-3-Clause |
def __call__(self, X, Y=None, eval_gradient=False):
"""Return the kernel k(X, Y) and optionally its gradient.
Note that this compound kernel returns the results of all simple kernel
stacked along an additional axis.
Parameters
----------
X : array-like of shape (n_sampl... | Return the kernel k(X, Y) and optionally its gradient.
Note that this compound kernel returns the results of all simple kernel
stacked along an additional axis.
Parameters
----------
X : array-like of shape (n_samples_X, n_features) or list of object, default=None
... | __call__ | python | scikit-learn/scikit-learn | sklearn/gaussian_process/kernels.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/gaussian_process/kernels.py | BSD-3-Clause |
def get_params(self, deep=True):
"""Get parameters of this kernel.
Parameters
----------
deep : bool, default=True
If True, will return the parameters for this estimator and
contained subobjects that are estimators.
Returns
-------
params... | Get parameters of this kernel.
Parameters
----------
deep : bool, default=True
If True, will return the parameters for this estimator and
contained subobjects that are estimators.
Returns
-------
params : dict
Parameter names mapped t... | get_params | python | scikit-learn/scikit-learn | sklearn/gaussian_process/kernels.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/gaussian_process/kernels.py | BSD-3-Clause |
def theta(self, theta):
"""Sets the (flattened, log-transformed) non-fixed hyperparameters.
Parameters
----------
theta : ndarray of shape (n_dims,)
The non-fixed, log-transformed hyperparameters of the kernel
"""
k1_dims = self.k1.n_dims
self.k1.thet... | Sets the (flattened, log-transformed) non-fixed hyperparameters.
Parameters
----------
theta : ndarray of shape (n_dims,)
The non-fixed, log-transformed hyperparameters of the kernel
| theta | python | scikit-learn/scikit-learn | sklearn/gaussian_process/kernels.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/gaussian_process/kernels.py | BSD-3-Clause |
def bounds(self):
"""Returns the log-transformed bounds on the theta.
Returns
-------
bounds : ndarray of shape (n_dims, 2)
The log-transformed bounds on the kernel's hyperparameters theta
"""
if self.k1.bounds.size == 0:
return self.k2.bounds
... | Returns the log-transformed bounds on the theta.
Returns
-------
bounds : ndarray of shape (n_dims, 2)
The log-transformed bounds on the kernel's hyperparameters theta
| bounds | python | scikit-learn/scikit-learn | sklearn/gaussian_process/kernels.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/gaussian_process/kernels.py | BSD-3-Clause |
def __call__(self, X, Y=None, eval_gradient=False):
"""Return the kernel k(X, Y) and optionally its gradient.
Parameters
----------
X : array-like of shape (n_samples_X, n_features) or list of object
Left argument of the returned kernel k(X, Y)
Y : array-like of sha... | Return the kernel k(X, Y) and optionally its gradient.
Parameters
----------
X : array-like of shape (n_samples_X, n_features) or list of object
Left argument of the returned kernel k(X, Y)
Y : array-like of shape (n_samples_X, n_features) or list of object, ... | __call__ | python | scikit-learn/scikit-learn | sklearn/gaussian_process/kernels.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/gaussian_process/kernels.py | BSD-3-Clause |
def __call__(self, X, Y=None, eval_gradient=False):
"""Return the kernel k(X, Y) and optionally its gradient.
Parameters
----------
X : array-like of shape (n_samples_X, n_features) or list of object
Left argument of the returned kernel k(X, Y)
Y : array-like of sha... | Return the kernel k(X, Y) and optionally its gradient.
Parameters
----------
X : array-like of shape (n_samples_X, n_features) or list of object
Left argument of the returned kernel k(X, Y)
Y : array-like of shape (n_samples_Y, n_features) or list of object, defa... | __call__ | python | scikit-learn/scikit-learn | sklearn/gaussian_process/kernels.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/gaussian_process/kernels.py | BSD-3-Clause |
def get_params(self, deep=True):
"""Get parameters of this kernel.
Parameters
----------
deep : bool, default=True
If True, will return the parameters for this estimator and
contained subobjects that are estimators.
Returns
-------
params... | Get parameters of this kernel.
Parameters
----------
deep : bool, default=True
If True, will return the parameters for this estimator and
contained subobjects that are estimators.
Returns
-------
params : dict
Parameter names mapped t... | get_params | python | scikit-learn/scikit-learn | sklearn/gaussian_process/kernels.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/gaussian_process/kernels.py | BSD-3-Clause |
def __call__(self, X, Y=None, eval_gradient=False):
"""Return the kernel k(X, Y) and optionally its gradient.
Parameters
----------
X : array-like of shape (n_samples_X, n_features) or list of object
Left argument of the returned kernel k(X, Y)
Y : array-like of sha... | Return the kernel k(X, Y) and optionally its gradient.
Parameters
----------
X : array-like of shape (n_samples_X, n_features) or list of object
Left argument of the returned kernel k(X, Y)
Y : array-like of shape (n_samples_Y, n_features) or list of object, defa... | __call__ | python | scikit-learn/scikit-learn | sklearn/gaussian_process/kernels.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/gaussian_process/kernels.py | BSD-3-Clause |
def __call__(self, X, Y=None, eval_gradient=False):
"""Return the kernel k(X, Y) and optionally its gradient.
Parameters
----------
X : array-like of shape (n_samples_X, n_features) or list of object
Left argument of the returned kernel k(X, Y)
Y : array-like of sha... | Return the kernel k(X, Y) and optionally its gradient.
Parameters
----------
X : array-like of shape (n_samples_X, n_features) or list of object
Left argument of the returned kernel k(X, Y)
Y : array-like of shape (n_samples_X, n_features) or list of object, def... | __call__ | python | scikit-learn/scikit-learn | sklearn/gaussian_process/kernels.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/gaussian_process/kernels.py | BSD-3-Clause |
def diag(self, X):
"""Returns the diagonal of the kernel k(X, X).
The result of this method is identical to np.diag(self(X)); however,
it can be evaluated more efficiently since only the diagonal is
evaluated.
Parameters
----------
X : array-like of shape (n_sam... | Returns the diagonal of the kernel k(X, X).
The result of this method is identical to np.diag(self(X)); however,
it can be evaluated more efficiently since only the diagonal is
evaluated.
Parameters
----------
X : array-like of shape (n_samples_X, n_features) or list of... | diag | python | scikit-learn/scikit-learn | sklearn/gaussian_process/kernels.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/gaussian_process/kernels.py | BSD-3-Clause |
def __call__(self, X, Y=None, eval_gradient=False):
"""Return the kernel k(X, Y) and optionally its gradient.
Parameters
----------
X : array-like of shape (n_samples_X, n_features) or list of object
Left argument of the returned kernel k(X, Y)
Y : array-like of sha... | Return the kernel k(X, Y) and optionally its gradient.
Parameters
----------
X : array-like of shape (n_samples_X, n_features) or list of object
Left argument of the returned kernel k(X, Y)
Y : array-like of shape (n_samples_X, n_features) or list of object, defa... | __call__ | python | scikit-learn/scikit-learn | sklearn/gaussian_process/kernels.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/gaussian_process/kernels.py | BSD-3-Clause |
def diag(self, X):
"""Returns the diagonal of the kernel k(X, X).
The result of this method is identical to np.diag(self(X)); however,
it can be evaluated more efficiently since only the diagonal is
evaluated.
Parameters
----------
X : array-like of shape (n_sam... | Returns the diagonal of the kernel k(X, X).
The result of this method is identical to np.diag(self(X)); however,
it can be evaluated more efficiently since only the diagonal is
evaluated.
Parameters
----------
X : array-like of shape (n_samples_X, n_features) or list of... | diag | python | scikit-learn/scikit-learn | sklearn/gaussian_process/kernels.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/gaussian_process/kernels.py | BSD-3-Clause |
def __call__(self, X, Y=None, eval_gradient=False):
"""Return the kernel k(X, Y) and optionally its gradient.
Parameters
----------
X : ndarray of shape (n_samples_X, n_features)
Left argument of the returned kernel k(X, Y)
Y : ndarray of shape (n_samples_Y, n_featu... | Return the kernel k(X, Y) and optionally its gradient.
Parameters
----------
X : ndarray of shape (n_samples_X, n_features)
Left argument of the returned kernel k(X, Y)
Y : ndarray of shape (n_samples_Y, n_features), default=None
Right argument of the returned k... | __call__ | python | scikit-learn/scikit-learn | sklearn/gaussian_process/kernels.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/gaussian_process/kernels.py | BSD-3-Clause |
def __call__(self, X, Y=None, eval_gradient=False):
"""Return the kernel k(X, Y) and optionally its gradient.
Parameters
----------
X : ndarray of shape (n_samples_X, n_features)
Left argument of the returned kernel k(X, Y)
Y : ndarray of shape (n_samples_Y, n_featu... | Return the kernel k(X, Y) and optionally its gradient.
Parameters
----------
X : ndarray of shape (n_samples_X, n_features)
Left argument of the returned kernel k(X, Y)
Y : ndarray of shape (n_samples_Y, n_features), default=None
Right argument of the returned k... | __call__ | python | scikit-learn/scikit-learn | sklearn/gaussian_process/kernels.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/gaussian_process/kernels.py | BSD-3-Clause |
def __call__(self, X, Y=None, eval_gradient=False):
"""Return the kernel k(X, Y) and optionally its gradient.
Parameters
----------
X : ndarray of shape (n_samples_X, n_features)
Left argument of the returned kernel k(X, Y)
Y : ndarray of shape (n_samples_Y, n_featu... | Return the kernel k(X, Y) and optionally its gradient.
Parameters
----------
X : ndarray of shape (n_samples_X, n_features)
Left argument of the returned kernel k(X, Y)
Y : ndarray of shape (n_samples_Y, n_features), default=None
Right argument of the returned k... | __call__ | python | scikit-learn/scikit-learn | sklearn/gaussian_process/kernels.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/gaussian_process/kernels.py | BSD-3-Clause |
def __call__(self, X, Y=None, eval_gradient=False):
"""Return the kernel k(X, Y) and optionally its gradient.
Parameters
----------
X : ndarray of shape (n_samples_X, n_features)
Left argument of the returned kernel k(X, Y)
Y : ndarray of shape (n_samples_Y, n_featu... | Return the kernel k(X, Y) and optionally its gradient.
Parameters
----------
X : ndarray of shape (n_samples_X, n_features)
Left argument of the returned kernel k(X, Y)
Y : ndarray of shape (n_samples_Y, n_features), default=None
Right argument of the returned k... | __call__ | python | scikit-learn/scikit-learn | sklearn/gaussian_process/kernels.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/gaussian_process/kernels.py | BSD-3-Clause |
def __call__(self, X, Y=None, eval_gradient=False):
"""Return the kernel k(X, Y) and optionally its gradient.
Parameters
----------
X : ndarray of shape (n_samples_X, n_features)
Left argument of the returned kernel k(X, Y)
Y : ndarray of shape (n_samples_Y, n_featu... | Return the kernel k(X, Y) and optionally its gradient.
Parameters
----------
X : ndarray of shape (n_samples_X, n_features)
Left argument of the returned kernel k(X, Y)
Y : ndarray of shape (n_samples_Y, n_features), default=None
Right argument of the returned k... | __call__ | python | scikit-learn/scikit-learn | sklearn/gaussian_process/kernels.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/gaussian_process/kernels.py | BSD-3-Clause |
def __call__(self, X, Y=None, eval_gradient=False):
"""Return the kernel k(X, Y) and optionally its gradient.
Parameters
----------
X : ndarray of shape (n_samples_X, n_features)
Left argument of the returned kernel k(X, Y)
Y : ndarray of shape (n_samples_Y, n_featu... | Return the kernel k(X, Y) and optionally its gradient.
Parameters
----------
X : ndarray of shape (n_samples_X, n_features)
Left argument of the returned kernel k(X, Y)
Y : ndarray of shape (n_samples_Y, n_features), default=None
Right argument of the returned k... | __call__ | python | scikit-learn/scikit-learn | sklearn/gaussian_process/kernels.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/gaussian_process/kernels.py | BSD-3-Clause |
def diag(self, X):
"""Returns the diagonal of the kernel k(X, X).
The result of this method is identical to np.diag(self(X)); however,
it can be evaluated more efficiently since only the diagonal is
evaluated.
Parameters
----------
X : ndarray of shape (n_sample... | Returns the diagonal of the kernel k(X, X).
The result of this method is identical to np.diag(self(X)); however,
it can be evaluated more efficiently since only the diagonal is
evaluated.
Parameters
----------
X : ndarray of shape (n_samples_X, n_features)
L... | diag | python | scikit-learn/scikit-learn | sklearn/gaussian_process/kernels.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/gaussian_process/kernels.py | BSD-3-Clause |
Subsets and Splits
Django Code with Docstrings
Filters Python code examples from Django repository that contain Django-related code, helping identify relevant code snippets for understanding Django framework usage patterns.
SQL Console for Shuu12121/python-treesitter-filtered-datasetsV2
Retrieves Python code examples from Django repository that contain 'django' in the code, which helps identify Django-specific code snippets but provides limited analytical insights beyond basic filtering.
SQL Console for Shuu12121/python-treesitter-filtered-datasetsV2
Retrieves specific code examples from the Flask repository but doesn't provide meaningful analysis or patterns beyond basic data retrieval.
HTTPX Repo Code and Docstrings
Retrieves specific code examples from the httpx repository, which is useful for understanding how particular libraries are used but doesn't provide broader analytical insights about the dataset.
Requests Repo Docstrings & Code
Retrieves code examples with their docstrings and file paths from the requests repository, providing basic filtering but limited analytical value beyond finding specific code samples.
Quart Repo Docstrings & Code
Retrieves code examples with their docstrings from the Quart repository, providing basic code samples but offering limited analytical value for understanding broader patterns or relationships in the dataset.