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 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
Only used to validate feature names with the names seen in :meth:`fit`.
Returns
... | Get output feature names for transformation.
Parameters
----------
input_features : array-like of str or None, default=None
Only used to validate feature names with the names seen in :meth:`fit`.
Returns
-------
feature_names_out : ndarray of str objects
... | get_feature_names_out | python | scikit-learn/scikit-learn | sklearn/kernel_approximation.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/kernel_approximation.py | BSD-3-Clause |
def fit(self, X, y=None):
"""Fit estimator to data.
Samples a subset of training points, computes kernel
on these and computes normalization matrix.
Parameters
----------
X : array-like, shape (n_samples, n_features)
Training data, where `n_samples` is the n... | Fit estimator to data.
Samples a subset of training points, computes kernel
on these and computes normalization matrix.
Parameters
----------
X : array-like, shape (n_samples, n_features)
Training data, where `n_samples` is the number of samples
and `n_f... | fit | python | scikit-learn/scikit-learn | sklearn/kernel_approximation.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/kernel_approximation.py | BSD-3-Clause |
def transform(self, X):
"""Apply feature map to X.
Computes an approximate feature map using the kernel
between some training points and X.
Parameters
----------
X : array-like of shape (n_samples, n_features)
Data to transform.
Returns
----... | Apply feature map to X.
Computes an approximate feature map using the kernel
between some training points and X.
Parameters
----------
X : array-like of shape (n_samples, n_features)
Data to transform.
Returns
-------
X_transformed : ndarray... | transform | python | scikit-learn/scikit-learn | sklearn/kernel_approximation.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/kernel_approximation.py | BSD-3-Clause |
def fit(self, X, y, sample_weight=None):
"""Fit Kernel Ridge regression model.
Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_features)
Training data. If kernel == "precomputed" this is instead
a precomputed kernel matrix, of shape (... | Fit Kernel Ridge regression model.
Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_features)
Training data. If kernel == "precomputed" this is instead
a precomputed kernel matrix, of shape (n_samples, n_samples).
y : array-like of sh... | fit | python | scikit-learn/scikit-learn | sklearn/kernel_ridge.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/kernel_ridge.py | BSD-3-Clause |
def predict(self, X):
"""Predict using the kernel ridge model.
Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_features)
Samples. If kernel == "precomputed" this is instead a
precomputed kernel matrix, shape = [n_samples,
... | Predict using the kernel ridge model.
Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_features)
Samples. If kernel == "precomputed" this is instead a
precomputed kernel matrix, shape = [n_samples,
n_samples_fitted], where n_sample... | predict | python | scikit-learn/scikit-learn | sklearn/kernel_ridge.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/kernel_ridge.py | BSD-3-Clause |
def _predict_binary(estimator, X):
"""Make predictions using a single binary estimator."""
if is_regressor(estimator):
return estimator.predict(X)
try:
score = np.ravel(estimator.decision_function(X))
except (AttributeError, NotImplementedError):
# probabilities of the positive c... | Make predictions using a single binary estimator. | _predict_binary | python | scikit-learn/scikit-learn | sklearn/multiclass.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/multiclass.py | BSD-3-Clause |
def _threshold_for_binary_predict(estimator):
"""Threshold for predictions from binary estimator."""
if hasattr(estimator, "decision_function") and is_classifier(estimator):
return 0.0
else:
# predict_proba threshold
return 0.5 | Threshold for predictions from binary estimator. | _threshold_for_binary_predict | python | scikit-learn/scikit-learn | sklearn/multiclass.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/multiclass.py | BSD-3-Clause |
def _estimators_has(attr):
"""Check if self.estimator or self.estimators_[0] has attr.
If `self.estimators_[0]` has the attr, then its safe to assume that other
estimators have it too. We raise the original `AttributeError` if `attr`
does not exist. This function is used together with `available_if`.
... | Check if self.estimator or self.estimators_[0] has attr.
If `self.estimators_[0]` has the attr, then its safe to assume that other
estimators have it too. We raise the original `AttributeError` if `attr`
does not exist. This function is used together with `available_if`.
| _estimators_has | python | scikit-learn/scikit-learn | sklearn/multiclass.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/multiclass.py | BSD-3-Clause |
def fit(self, X, y, **fit_params):
"""Fit underlying estimators.
Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_features)
Data.
y : {array-like, sparse matrix} of shape (n_samples,) or (n_samples, n_classes)
Multi-class targ... | Fit underlying estimators.
Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_features)
Data.
y : {array-like, sparse matrix} of shape (n_samples,) or (n_samples, n_classes)
Multi-class targets. An indicator matrix turns on multilabel
... | fit | python | scikit-learn/scikit-learn | sklearn/multiclass.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/multiclass.py | BSD-3-Clause |
def predict(self, X):
"""Predict multi-class targets using underlying estimators.
Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_features)
Data.
Returns
-------
y : {array-like, sparse matrix} of shape (n_samples,) or (n... | Predict multi-class targets using underlying estimators.
Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_features)
Data.
Returns
-------
y : {array-like, sparse matrix} of shape (n_samples,) or (n_samples, n_classes)
... | predict | python | scikit-learn/scikit-learn | sklearn/multiclass.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/multiclass.py | BSD-3-Clause |
def predict_proba(self, X):
"""Probability estimates.
The returned estimates for all classes are ordered by label of classes.
Note that in the multilabel case, each sample can have any number of
labels. This returns the marginal probability that the given sample has
the label i... | Probability estimates.
The returned estimates for all classes are ordered by label of classes.
Note that in the multilabel case, each sample can have any number of
labels. This returns the marginal probability that the given sample has
the label in question. For example, it is entirely... | predict_proba | python | scikit-learn/scikit-learn | sklearn/multiclass.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/multiclass.py | BSD-3-Clause |
def decision_function(self, X):
"""Decision function for the OneVsRestClassifier.
Return the distance of each sample from the decision boundary for each
class. This can only be used with estimators which implement the
`decision_function` method.
Parameters
----------
... | Decision function for the OneVsRestClassifier.
Return the distance of each sample from the decision boundary for each
class. This can only be used with estimators which implement the
`decision_function` method.
Parameters
----------
X : array-like of shape (n_samples, n... | decision_function | python | scikit-learn/scikit-learn | sklearn/multiclass.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/multiclass.py | BSD-3-Clause |
def __sklearn_tags__(self):
"""Indicate if wrapped estimator is using a precomputed Gram matrix"""
tags = super().__sklearn_tags__()
tags.input_tags.pairwise = get_tags(self.estimator).input_tags.pairwise
tags.input_tags.sparse = get_tags(self.estimator).input_tags.sparse
return ... | Indicate if wrapped estimator is using a precomputed Gram matrix | __sklearn_tags__ | python | scikit-learn/scikit-learn | sklearn/multiclass.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/multiclass.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/multiclass.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/multiclass.py | BSD-3-Clause |
def _fit_ovo_binary(estimator, X, y, i, j, fit_params):
"""Fit a single binary estimator (one-vs-one)."""
cond = np.logical_or(y == i, y == j)
y = y[cond]
y_binary = np.empty(y.shape, int)
y_binary[y == i] = 0
y_binary[y == j] = 1
indcond = np.arange(_num_samples(X))[cond]
fit_params_su... | Fit a single binary estimator (one-vs-one). | _fit_ovo_binary | python | scikit-learn/scikit-learn | sklearn/multiclass.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/multiclass.py | BSD-3-Clause |
def _partial_fit_ovo_binary(estimator, X, y, i, j, partial_fit_params):
"""Partially fit a single binary estimator(one-vs-one)."""
cond = np.logical_or(y == i, y == j)
y = y[cond]
if len(y) != 0:
y_binary = np.zeros_like(y)
y_binary[y == j] = 1
partial_fit_params_subset = _check... | Partially fit a single binary estimator(one-vs-one). | _partial_fit_ovo_binary | python | scikit-learn/scikit-learn | sklearn/multiclass.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/multiclass.py | BSD-3-Clause |
def fit(self, X, y, **fit_params):
"""Fit underlying estimators.
Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_features)
Data.
y : array-like of shape (n_samples,)
Multi-class targets.
**fit_params : dict
... | Fit underlying estimators.
Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_features)
Data.
y : array-like of shape (n_samples,)
Multi-class targets.
**fit_params : dict
Parameters passed to the ``estimator.fit`` ... | fit | python | scikit-learn/scikit-learn | sklearn/multiclass.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/multiclass.py | BSD-3-Clause |
def predict(self, X):
"""Estimate the best class label for each sample in X.
This is implemented as ``argmax(decision_function(X), axis=1)`` which
will return the label of the class with most votes by estimators
predicting the outcome of a decision for each possible class pair.
... | Estimate the best class label for each sample in X.
This is implemented as ``argmax(decision_function(X), axis=1)`` which
will return the label of the class with most votes by estimators
predicting the outcome of a decision for each possible class pair.
Parameters
----------
... | predict | python | scikit-learn/scikit-learn | sklearn/multiclass.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/multiclass.py | BSD-3-Clause |
def decision_function(self, X):
"""Decision function for the OneVsOneClassifier.
The decision values for the samples are computed by adding the
normalized sum of pair-wise classification confidence levels to the
votes in order to disambiguate between the decision values when the
... | Decision function for the OneVsOneClassifier.
The decision values for the samples are computed by adding the
normalized sum of pair-wise classification confidence levels to the
votes in order to disambiguate between the decision values when the
votes for all the classes are equal leadin... | decision_function | python | scikit-learn/scikit-learn | sklearn/multiclass.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/multiclass.py | BSD-3-Clause |
def __sklearn_tags__(self):
"""Indicate if wrapped estimator is using a precomputed Gram matrix"""
tags = super().__sklearn_tags__()
tags.input_tags.pairwise = get_tags(self.estimator).input_tags.pairwise
tags.input_tags.sparse = get_tags(self.estimator).input_tags.sparse
return ... | Indicate if wrapped estimator is using a precomputed Gram matrix | __sklearn_tags__ | python | scikit-learn/scikit-learn | sklearn/multiclass.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/multiclass.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/multiclass.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/multiclass.py | BSD-3-Clause |
def fit(self, X, y, **fit_params):
"""Fit underlying estimators.
Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_features)
Data.
y : array-like of shape (n_samples,)
Multi-class targets.
**fit_params : dict
... | Fit underlying estimators.
Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_features)
Data.
y : array-like of shape (n_samples,)
Multi-class targets.
**fit_params : dict
Parameters passed to the ``estimator.fit`` ... | fit | python | scikit-learn/scikit-learn | sklearn/multiclass.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/multiclass.py | BSD-3-Clause |
def predict(self, X):
"""Predict multi-class targets using underlying estimators.
Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_features)
Data.
Returns
-------
y : ndarray of shape (n_samples,)
Predicted mul... | Predict multi-class targets using underlying estimators.
Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_features)
Data.
Returns
-------
y : ndarray of shape (n_samples,)
Predicted multi-class targets.
| predict | python | scikit-learn/scikit-learn | sklearn/multiclass.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/multiclass.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/multiclass.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/multiclass.py | BSD-3-Clause |
def _available_if_estimator_has(attr):
"""Return a function to check if the sub-estimator(s) has(have) `attr`.
Helper for Chain implementations.
"""
def _check(self):
if hasattr(self, "estimators_"):
return all(hasattr(est, attr) for est in self.estimators_)
if hasattr(sel... | Return a function to check if the sub-estimator(s) has(have) `attr`.
Helper for Chain implementations.
| _available_if_estimator_has | python | scikit-learn/scikit-learn | sklearn/multioutput.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/multioutput.py | BSD-3-Clause |
def fit(self, X, y, sample_weight=None, **fit_params):
"""Fit the model to data, separately for each output variable.
Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_features)
The input data.
y : {array-like, sparse matrix} of shape (n_s... | Fit the model to data, separately for each output variable.
Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_features)
The input data.
y : {array-like, sparse matrix} of shape (n_samples, n_outputs)
Multi-output targets. An indicator ... | fit | python | scikit-learn/scikit-learn | sklearn/multioutput.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/multioutput.py | BSD-3-Clause |
def predict(self, X):
"""Predict multi-output variable using model for each target variable.
Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_features)
The input data.
Returns
-------
y : {array-like, sparse matrix} of sha... | Predict multi-output variable using model for each target variable.
Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_features)
The input data.
Returns
-------
y : {array-like, sparse matrix} of shape (n_samples, n_outputs)
... | predict | python | scikit-learn/scikit-learn | sklearn/multioutput.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/multioutput.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.3
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.3
Returns
-------
routing : MetadataRouter
A :class:`~sklearn.utils.metadata_routing.MetadataRouter` encapsulating... | get_metadata_routing | python | scikit-learn/scikit-learn | sklearn/multioutput.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/multioutput.py | BSD-3-Clause |
def fit(self, X, Y, sample_weight=None, **fit_params):
"""Fit the model to data matrix X and targets Y.
Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_features)
The input data.
Y : array-like of shape (n_samples, n_classes)
... | Fit the model to data matrix X and targets Y.
Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_features)
The input data.
Y : array-like of shape (n_samples, n_classes)
The target values.
sample_weight : array-like of shape (n... | fit | python | scikit-learn/scikit-learn | sklearn/multioutput.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/multioutput.py | BSD-3-Clause |
def predict_proba(self, X):
"""Return prediction probabilities for each class of each output.
This method will raise a ``ValueError`` if any of the
estimators do not have ``predict_proba``.
Parameters
----------
X : array-like of shape (n_samples, n_features)
... | Return prediction probabilities for each class of each output.
This method will raise a ``ValueError`` if any of the
estimators do not have ``predict_proba``.
Parameters
----------
X : array-like of shape (n_samples, n_features)
The input data.
Returns
... | predict_proba | python | scikit-learn/scikit-learn | sklearn/multioutput.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/multioutput.py | BSD-3-Clause |
def score(self, X, y):
"""Return the mean accuracy 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, n_outputs)
True values for X.
Returns
... | Return the mean accuracy 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, n_outputs)
True values for X.
Returns
-------
scores : fl... | score | python | scikit-learn/scikit-learn | sklearn/multioutput.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/multioutput.py | BSD-3-Clause |
def _available_if_base_estimator_has(attr):
"""Return a function to check if `base_estimator` or `estimators_` has `attr`.
Helper for Chain implementations.
"""
def _check(self):
return hasattr(self._get_estimator(), attr) or all(
hasattr(est, attr) for est in self.estimators_
... | Return a function to check if `base_estimator` or `estimators_` has `attr`.
Helper for Chain implementations.
| _available_if_base_estimator_has | python | scikit-learn/scikit-learn | sklearn/multioutput.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/multioutput.py | BSD-3-Clause |
def _get_predictions(self, X, *, output_method):
"""Get predictions for each model in the chain."""
check_is_fitted(self)
X = validate_data(self, X, accept_sparse=True, reset=False)
Y_output_chain = np.zeros((X.shape[0], len(self.estimators_)))
Y_feature_chain = np.zeros((X.shape... | Get predictions for each model in the chain. | _get_predictions | python | scikit-learn/scikit-learn | sklearn/multioutput.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/multioutput.py | BSD-3-Clause |
def fit(self, X, Y, **fit_params):
"""Fit the model to data matrix X and targets Y.
Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_features)
The input data.
Y : array-like of shape (n_samples, n_classes)
The target values.
... | Fit the model to data matrix X and targets Y.
Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_features)
The input data.
Y : array-like of shape (n_samples, n_classes)
The target values.
**fit_params : dict of string -> objec... | fit | python | scikit-learn/scikit-learn | sklearn/multioutput.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/multioutput.py | BSD-3-Clause |
def fit(self, X, Y, **fit_params):
"""Fit the model to data matrix X and targets Y.
Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_features)
The input data.
Y : array-like of shape (n_samples, n_classes)
The target values.
... | Fit the model to data matrix X and targets Y.
Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_features)
The input data.
Y : array-like of shape (n_samples, n_classes)
The target values.
**fit_params : dict of string -> objec... | fit | python | scikit-learn/scikit-learn | sklearn/multioutput.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/multioutput.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.3
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.3
Returns
-------
routing : MetadataRouter
A :class:`~sklearn.utils.metadata_routing.MetadataRouter` encapsulating... | get_metadata_routing | python | scikit-learn/scikit-learn | sklearn/multioutput.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/multioutput.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.3
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.3
Returns
-------
routing : MetadataRouter
A :class:`~sklearn.utils.metadata_routing.MetadataRouter` encapsulating... | get_metadata_routing | python | scikit-learn/scikit-learn | sklearn/multioutput.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/multioutput.py | BSD-3-Clause |
def _joint_log_likelihood(self, X):
"""Compute the unnormalized posterior log probability of X
I.e. ``log P(c) + log P(x|c)`` for all rows x of X, as an array-like of
shape (n_samples, n_classes).
Public methods predict, predict_proba, predict_log_proba, and
predict_joint_log_p... | Compute the unnormalized posterior log probability of X
I.e. ``log P(c) + log P(x|c)`` for all rows x of X, as an array-like of
shape (n_samples, n_classes).
Public methods predict, predict_proba, predict_log_proba, and
predict_joint_log_proba pass the input through _check_X before han... | _joint_log_likelihood | python | scikit-learn/scikit-learn | sklearn/naive_bayes.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/naive_bayes.py | BSD-3-Clause |
def _check_X(self, X):
"""To be overridden in subclasses with the actual checks.
Only used in predict* methods.
""" | To be overridden in subclasses with the actual checks.
Only used in predict* methods.
| _check_X | python | scikit-learn/scikit-learn | sklearn/naive_bayes.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/naive_bayes.py | BSD-3-Clause |
def predict_joint_log_proba(self, X):
"""Return joint log probability estimates for the test vector X.
For each row x of X and class y, the joint log probability is given by
``log P(x, y) = log P(y) + log P(x|y),``
where ``log P(y)`` is the class prior probability and ``log P(x|y)`` is
... | Return joint log probability estimates for the test vector X.
For each row x of X and class y, the joint log probability is given by
``log P(x, y) = log P(y) + log P(x|y),``
where ``log P(y)`` is the class prior probability and ``log P(x|y)`` is
the class-conditional probability.
... | predict_joint_log_proba | python | scikit-learn/scikit-learn | sklearn/naive_bayes.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/naive_bayes.py | BSD-3-Clause |
def predict(self, X):
"""
Perform classification on an array of test vectors X.
Parameters
----------
X : array-like of shape (n_samples, n_features)
The input samples.
Returns
-------
C : ndarray of shape (n_samples,)
Predicted t... |
Perform classification on an array of test vectors X.
Parameters
----------
X : array-like of shape (n_samples, n_features)
The input samples.
Returns
-------
C : ndarray of shape (n_samples,)
Predicted target values for X.
| predict | python | scikit-learn/scikit-learn | sklearn/naive_bayes.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/naive_bayes.py | BSD-3-Clause |
def predict_log_proba(self, X):
"""
Return log-probability estimates for the test vector X.
Parameters
----------
X : array-like of shape (n_samples, n_features)
The input samples.
Returns
-------
C : array-like of shape (n_samples, n_classes... |
Return log-probability estimates for the test vector X.
Parameters
----------
X : array-like of shape (n_samples, n_features)
The input samples.
Returns
-------
C : array-like of shape (n_samples, n_classes)
Returns the log-probability o... | predict_log_proba | python | scikit-learn/scikit-learn | sklearn/naive_bayes.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/naive_bayes.py | BSD-3-Clause |
def fit(self, X, y, sample_weight=None):
"""Fit Gaussian Naive Bayes according to X, y.
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 features.
... | Fit Gaussian Naive Bayes according to X, y.
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 features.
y : array-like of shape (n_samples,)
... | fit | python | scikit-learn/scikit-learn | sklearn/naive_bayes.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/naive_bayes.py | BSD-3-Clause |
def _update_mean_variance(n_past, mu, var, X, sample_weight=None):
"""Compute online update of Gaussian mean and variance.
Given starting sample count, mean, and variance, a new set of
points X, and optionally sample weights, return the updated mean and
variance. (NB - each dimension (c... | Compute online update of Gaussian mean and variance.
Given starting sample count, mean, and variance, a new set of
points X, and optionally sample weights, return the updated mean and
variance. (NB - each dimension (column) in X is treated as independent
-- you get variance, not covaria... | _update_mean_variance | python | scikit-learn/scikit-learn | sklearn/naive_bayes.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/naive_bayes.py | BSD-3-Clause |
def _count(self, X, Y):
"""Update counts that are used to calculate probabilities.
The counts make up a sufficient statistic extracted from the data.
Accordingly, this method is called each time `fit` or `partial_fit`
update the model. `class_count_` and `feature_count_` must be updated... | Update counts that are used to calculate probabilities.
The counts make up a sufficient statistic extracted from the data.
Accordingly, this method is called each time `fit` or `partial_fit`
update the model. `class_count_` and `feature_count_` must be updated
here along with any model ... | _count | python | scikit-learn/scikit-learn | sklearn/naive_bayes.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/naive_bayes.py | BSD-3-Clause |
def _update_feature_log_prob(self, alpha):
"""Update feature log probabilities based on counts.
This method is called each time `fit` or `partial_fit` update the
model.
Parameters
----------
alpha : float
smoothing parameter. See :meth:`_check_alpha`.
... | Update feature log probabilities based on counts.
This method is called each time `fit` or `partial_fit` update the
model.
Parameters
----------
alpha : float
smoothing parameter. See :meth:`_check_alpha`.
| _update_feature_log_prob | python | scikit-learn/scikit-learn | sklearn/naive_bayes.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/naive_bayes.py | BSD-3-Clause |
def _update_class_log_prior(self, class_prior=None):
"""Update class log priors.
The class log priors are based on `class_prior`, class count or the
number of classes. This method is called each time `fit` or
`partial_fit` update the model.
"""
n_classes = len(self.class... | Update class log priors.
The class log priors are based on `class_prior`, class count or the
number of classes. This method is called each time `fit` or
`partial_fit` update the model.
| _update_class_log_prior | python | scikit-learn/scikit-learn | sklearn/naive_bayes.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/naive_bayes.py | BSD-3-Clause |
def fit(self, X, y, sample_weight=None):
"""Fit Naive Bayes classifier according to X, y.
Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_features)
Training vectors, where `n_samples` is the number of samples and
`n_features` is the n... | Fit Naive Bayes classifier according to X, y.
Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_features)
Training vectors, where `n_samples` is the number of samples and
`n_features` is the number of features.
y : array-like of shape ... | fit | python | scikit-learn/scikit-learn | sklearn/naive_bayes.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/naive_bayes.py | BSD-3-Clause |
def _update_feature_log_prob(self, alpha):
"""Apply smoothing to raw counts and recompute log probabilities"""
smoothed_fc = self.feature_count_ + alpha
smoothed_cc = smoothed_fc.sum(axis=1)
self.feature_log_prob_ = np.log(smoothed_fc) - np.log(
smoothed_cc.reshape(-1, 1)
... | Apply smoothing to raw counts and recompute log probabilities | _update_feature_log_prob | python | scikit-learn/scikit-learn | sklearn/naive_bayes.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/naive_bayes.py | BSD-3-Clause |
def _update_feature_log_prob(self, alpha):
"""Apply smoothing to raw counts and compute the weights."""
comp_count = self.feature_all_ + alpha - self.feature_count_
logged = np.log(comp_count / comp_count.sum(axis=1, keepdims=True))
# _BaseNB.predict uses argmax, but ComplementNB operate... | Apply smoothing to raw counts and compute the weights. | _update_feature_log_prob | python | scikit-learn/scikit-learn | sklearn/naive_bayes.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/naive_bayes.py | BSD-3-Clause |
def _joint_log_likelihood(self, X):
"""Calculate the class scores for the samples in X."""
jll = safe_sparse_dot(X, self.feature_log_prob_.T)
if len(self.classes_) == 1:
jll += self.class_log_prior_
return jll | Calculate the class scores for the samples in X. | _joint_log_likelihood | python | scikit-learn/scikit-learn | sklearn/naive_bayes.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/naive_bayes.py | BSD-3-Clause |
def _check_X(self, X):
"""Validate X, used only in predict* methods."""
X = super()._check_X(X)
if self.binarize is not None:
X = binarize(X, threshold=self.binarize)
return X | Validate X, used only in predict* methods. | _check_X | python | scikit-learn/scikit-learn | sklearn/naive_bayes.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/naive_bayes.py | BSD-3-Clause |
def _update_feature_log_prob(self, alpha):
"""Apply smoothing to raw counts and recompute log probabilities"""
smoothed_fc = self.feature_count_ + alpha
smoothed_cc = self.class_count_ + alpha * 2
self.feature_log_prob_ = np.log(smoothed_fc) - np.log(
smoothed_cc.reshape(-1,... | Apply smoothing to raw counts and recompute log probabilities | _update_feature_log_prob | python | scikit-learn/scikit-learn | sklearn/naive_bayes.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/naive_bayes.py | BSD-3-Clause |
def _check_X(self, X):
"""Validate X, used only in predict* methods."""
X = validate_data(
self,
X,
dtype="int",
accept_sparse=False,
ensure_all_finite=True,
reset=False,
)
check_non_negative(X, "CategoricalNB (input... | Validate X, used only in predict* methods. | _check_X | python | scikit-learn/scikit-learn | sklearn/naive_bayes.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/naive_bayes.py | BSD-3-Clause |
def _raise_or_warn_if_not_fitted(estimator):
"""A context manager to make sure a NotFittedError is raised, if a sub-estimator
raises the error.
Otherwise, we raise a warning if the pipeline is not fitted, with the deprecation.
TODO(1.8): remove this context manager and replace with check_is_fitted.
... | A context manager to make sure a NotFittedError is raised, if a sub-estimator
raises the error.
Otherwise, we raise a warning if the pipeline is not fitted, with the deprecation.
TODO(1.8): remove this context manager and replace with check_is_fitted.
| _raise_or_warn_if_not_fitted | python | scikit-learn/scikit-learn | sklearn/pipeline.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/pipeline.py | BSD-3-Clause |
def _final_estimator_has(attr):
"""Check that final_estimator has `attr`.
Used together with `available_if` in `Pipeline`."""
def check(self):
# raise original `AttributeError` if `attr` does not exist
getattr(self._final_estimator, attr)
return True
return check | Check that final_estimator has `attr`.
Used together with `available_if` in `Pipeline`. | _final_estimator_has | python | scikit-learn/scikit-learn | sklearn/pipeline.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/pipeline.py | BSD-3-Clause |
def _cached_transform(
sub_pipeline, *, cache, param_name, param_value, transform_params
):
"""Transform a parameter value using a sub-pipeline and cache the result.
Parameters
----------
sub_pipeline : Pipeline
The sub-pipeline to be used for transformation.
cache : dict
The ca... | Transform a parameter value using a sub-pipeline and cache the result.
Parameters
----------
sub_pipeline : Pipeline
The sub-pipeline to be used for transformation.
cache : dict
The cache dictionary to store the transformed values.
param_name : str
The name of the parameter ... | _cached_transform | python | scikit-learn/scikit-learn | sklearn/pipeline.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/pipeline.py | BSD-3-Clause |
def set_output(self, *, transform=None):
"""Set the output container when `"transform"` and `"fit_transform"` are called.
Calling `set_output` will set the output of all estimators in `steps`.
Parameters
----------
transform : {"default", "pandas", "polars"}, default=None
... | Set the output container when `"transform"` and `"fit_transform"` are called.
Calling `set_output` will set the output of all estimators in `steps`.
Parameters
----------
transform : {"default", "pandas", "polars"}, default=None
Configure output of `transform` and `fit_tran... | set_output | python | scikit-learn/scikit-learn | sklearn/pipeline.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/pipeline.py | BSD-3-Clause |
def _iter(self, with_final=True, filter_passthrough=True):
"""
Generate (idx, (name, trans)) tuples from self.steps
When filter_passthrough is True, 'passthrough' and None transformers
are filtered out.
"""
stop = len(self.steps)
if not with_final:
st... |
Generate (idx, (name, trans)) tuples from self.steps
When filter_passthrough is True, 'passthrough' and None transformers
are filtered out.
| _iter | python | scikit-learn/scikit-learn | sklearn/pipeline.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/pipeline.py | BSD-3-Clause |
def __getitem__(self, ind):
"""Returns a sub-pipeline or a single estimator in the pipeline
Indexing with an integer will return an estimator; using a slice
returns another Pipeline instance which copies a slice of this
Pipeline. This copy is shallow: modifying (or fitting) estimators i... | Returns a sub-pipeline or a single estimator in the pipeline
Indexing with an integer will return an estimator; using a slice
returns another Pipeline instance which copies a slice of this
Pipeline. This copy is shallow: modifying (or fitting) estimators in
the sub-pipeline will affect ... | __getitem__ | python | scikit-learn/scikit-learn | sklearn/pipeline.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/pipeline.py | BSD-3-Clause |
def _estimator_type(self):
"""Return the estimator type of the last step in the pipeline."""
if not self.steps:
return None
return self.steps[-1][1]._estimator_type | Return the estimator type of the last step in the pipeline. | _estimator_type | python | scikit-learn/scikit-learn | sklearn/pipeline.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/pipeline.py | BSD-3-Clause |
def _get_metadata_for_step(self, *, step_idx, step_params, all_params):
"""Get params (metadata) for step `name`.
This transforms the metadata up to this step if required, which is
indicated by the `transform_input` parameter.
If a param in `step_params` is included in the `transform_i... | Get params (metadata) for step `name`.
This transforms the metadata up to this step if required, which is
indicated by the `transform_input` parameter.
If a param in `step_params` is included in the `transform_input` list,
it will be transformed.
Parameters
----------
... | _get_metadata_for_step | python | scikit-learn/scikit-learn | sklearn/pipeline.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/pipeline.py | BSD-3-Clause |
def _fit(self, X, y=None, routed_params=None, raw_params=None):
"""Fit the pipeline except the last step.
routed_params is the output of `process_routing`
raw_params is the parameters passed by the user, used when `transform_input`
is set by the user, to transform metadata using a s... | Fit the pipeline except the last step.
routed_params is the output of `process_routing`
raw_params is the parameters passed by the user, used when `transform_input`
is set by the user, to transform metadata using a sub-pipeline.
| _fit | python | scikit-learn/scikit-learn | sklearn/pipeline.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/pipeline.py | BSD-3-Clause |
def fit(self, X, y=None, **params):
"""Fit the model.
Fit all the transformers one after the other and sequentially transform the
data. Finally, fit the transformed data using the final estimator.
Parameters
----------
X : iterable
Training data. Must fulfil... | Fit the model.
Fit all the transformers one after the other and sequentially transform the
data. Finally, fit the transformed data using the final estimator.
Parameters
----------
X : iterable
Training data. Must fulfill input requirements of first step of the
... | fit | python | scikit-learn/scikit-learn | sklearn/pipeline.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/pipeline.py | BSD-3-Clause |
def fit_transform(self, X, y=None, **params):
"""Fit the model and transform with the final estimator.
Fit all the transformers one after the other and sequentially transform
the data. Only valid if the final estimator either implements
`fit_transform` or `fit` and `transform`.
... | Fit the model and transform with the final estimator.
Fit all the transformers one after the other and sequentially transform
the data. Only valid if the final estimator either implements
`fit_transform` or `fit` and `transform`.
Parameters
----------
X : iterable
... | fit_transform | python | scikit-learn/scikit-learn | sklearn/pipeline.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/pipeline.py | BSD-3-Clause |
def predict(self, X, **params):
"""Transform the data, and apply `predict` with the final estimator.
Call `transform` of each transformer in the pipeline. The transformed
data are finally passed to the final estimator that calls `predict`
method. Only valid if the final estimator implem... | Transform the data, and apply `predict` with the final estimator.
Call `transform` of each transformer in the pipeline. The transformed
data are finally passed to the final estimator that calls `predict`
method. Only valid if the final estimator implements `predict`.
Parameters
... | predict | python | scikit-learn/scikit-learn | sklearn/pipeline.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/pipeline.py | BSD-3-Clause |
def fit_predict(self, X, y=None, **params):
"""Transform the data, and apply `fit_predict` with the final estimator.
Call `fit_transform` of each transformer in the pipeline. The
transformed data are finally passed to the final estimator that calls
`fit_predict` method. Only valid if th... | Transform the data, and apply `fit_predict` with the final estimator.
Call `fit_transform` of each transformer in the pipeline. The
transformed data are finally passed to the final estimator that calls
`fit_predict` method. Only valid if the final estimator implements
`fit_predict`.
... | fit_predict | python | scikit-learn/scikit-learn | sklearn/pipeline.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/pipeline.py | BSD-3-Clause |
def predict_proba(self, X, **params):
"""Transform the data, and apply `predict_proba` with the final estimator.
Call `transform` of each transformer in the pipeline. The transformed
data are finally passed to the final estimator that calls
`predict_proba` method. Only valid if the fina... | Transform the data, and apply `predict_proba` with the final estimator.
Call `transform` of each transformer in the pipeline. The transformed
data are finally passed to the final estimator that calls
`predict_proba` method. Only valid if the final estimator implements
`predict_proba`.
... | predict_proba | python | scikit-learn/scikit-learn | sklearn/pipeline.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/pipeline.py | BSD-3-Clause |
def decision_function(self, X, **params):
"""Transform the data, and apply `decision_function` with the final estimator.
Call `transform` of each transformer in the pipeline. The transformed
data are finally passed to the final estimator that calls
`decision_function` method. Only valid... | Transform the data, and apply `decision_function` with the final estimator.
Call `transform` of each transformer in the pipeline. The transformed
data are finally passed to the final estimator that calls
`decision_function` method. Only valid if the final estimator
implements `decision_... | decision_function | python | scikit-learn/scikit-learn | sklearn/pipeline.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/pipeline.py | BSD-3-Clause |
def score_samples(self, X):
"""Transform the data, and apply `score_samples` with the final estimator.
Call `transform` of each transformer in the pipeline. The transformed
data are finally passed to the final estimator that calls
`score_samples` method. Only valid if the final estimato... | Transform the data, and apply `score_samples` with the final estimator.
Call `transform` of each transformer in the pipeline. The transformed
data are finally passed to the final estimator that calls
`score_samples` method. Only valid if the final estimator implements
`score_samples`.
... | score_samples | python | scikit-learn/scikit-learn | sklearn/pipeline.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/pipeline.py | BSD-3-Clause |
def predict_log_proba(self, X, **params):
"""Transform the data, and apply `predict_log_proba` with the final estimator.
Call `transform` of each transformer in the pipeline. The transformed
data are finally passed to the final estimator that calls
`predict_log_proba` method. Only valid... | Transform the data, and apply `predict_log_proba` with the final estimator.
Call `transform` of each transformer in the pipeline. The transformed
data are finally passed to the final estimator that calls
`predict_log_proba` method. Only valid if the final estimator
implements `predict_l... | predict_log_proba | python | scikit-learn/scikit-learn | sklearn/pipeline.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/pipeline.py | BSD-3-Clause |
def transform(self, X, **params):
"""Transform the data, and apply `transform` with the final estimator.
Call `transform` of each transformer in the pipeline. The transformed
data are finally passed to the final estimator that calls
`transform` method. Only valid if the final estimator
... | Transform the data, and apply `transform` with the final estimator.
Call `transform` of each transformer in the pipeline. The transformed
data are finally passed to the final estimator that calls
`transform` method. Only valid if the final estimator
implements `transform`.
This... | transform | python | scikit-learn/scikit-learn | sklearn/pipeline.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/pipeline.py | BSD-3-Clause |
def inverse_transform(self, X, **params):
"""Apply `inverse_transform` for each step in a reverse order.
All estimators in the pipeline must support `inverse_transform`.
Parameters
----------
X : array-like of shape (n_samples, n_transformed_features)
Data samples, ... | Apply `inverse_transform` for each step in a reverse order.
All estimators in the pipeline must support `inverse_transform`.
Parameters
----------
X : array-like of shape (n_samples, n_transformed_features)
Data samples, where ``n_samples`` is the number of samples and
... | inverse_transform | python | scikit-learn/scikit-learn | sklearn/pipeline.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/pipeline.py | BSD-3-Clause |
def score(self, X, y=None, sample_weight=None, **params):
"""Transform the data, and apply `score` with the final estimator.
Call `transform` of each transformer in the pipeline. The transformed
data are finally passed to the final estimator that calls
`score` method. Only valid if the ... | Transform the data, and apply `score` with the final estimator.
Call `transform` of each transformer in the pipeline. The transformed
data are finally passed to the final estimator that calls
`score` method. Only valid if the final estimator implements `score`.
Parameters
-----... | score | python | scikit-learn/scikit-learn | sklearn/pipeline.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/pipeline.py | BSD-3-Clause |
def get_feature_names_out(self, input_features=None):
"""Get output feature names for transformation.
Transform input features using the pipeline.
Parameters
----------
input_features : array-like of str or None, default=None
Input features.
Returns
... | Get output feature names for transformation.
Transform input features using the pipeline.
Parameters
----------
input_features : array-like of str or None, default=None
Input features.
Returns
-------
feature_names_out : ndarray of str objects
... | get_feature_names_out | python | scikit-learn/scikit-learn | sklearn/pipeline.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/pipeline.py | BSD-3-Clause |
def __sklearn_is_fitted__(self):
"""Indicate whether pipeline has been fit.
This is done by checking whether the last non-`passthrough` step of the
pipeline is fitted.
An empty pipeline is considered fitted.
"""
# First find the last step that is not 'passthrough'
... | Indicate whether pipeline has been fit.
This is done by checking whether the last non-`passthrough` step of the
pipeline is fitted.
An empty pipeline is considered fitted.
| __sklearn_is_fitted__ | python | scikit-learn/scikit-learn | sklearn/pipeline.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/pipeline.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.
Returns
-------
routing : MetadataRouter
A :class:`~sklearn.utils.metadata_routing.MetadataRouter` e... | Get metadata routing of this object.
Please check :ref:`User Guide <metadata_routing>` on how the routing
mechanism works.
Returns
-------
routing : MetadataRouter
A :class:`~sklearn.utils.metadata_routing.MetadataRouter` encapsulating
routing informatio... | get_metadata_routing | python | scikit-learn/scikit-learn | sklearn/pipeline.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/pipeline.py | BSD-3-Clause |
def _transform_one(transformer, X, y, weight, params):
"""Call transform and apply weight to output.
Parameters
----------
transformer : estimator
Estimator to be used for transformation.
X : {array-like, sparse matrix} of shape (n_samples, n_features)
Input data to be transformed.... | Call transform and apply weight to output.
Parameters
----------
transformer : estimator
Estimator to be used for transformation.
X : {array-like, sparse matrix} of shape (n_samples, n_features)
Input data to be transformed.
y : ndarray of shape (n_samples,)
Ignored.
... | _transform_one | python | scikit-learn/scikit-learn | sklearn/pipeline.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/pipeline.py | BSD-3-Clause |
def _fit_transform_one(
transformer, X, y, weight, message_clsname="", message=None, params=None
):
"""
Fits ``transformer`` to ``X`` and ``y``. The transformed result is returned
with the fitted transformer. If ``weight`` is not ``None``, the result will
be multiplied by ``weight``.
``params``... |
Fits ``transformer`` to ``X`` and ``y``. The transformed result is returned
with the fitted transformer. If ``weight`` is not ``None``, the result will
be multiplied by ``weight``.
``params`` needs to be of the form ``process_routing()["step_name"]``.
| _fit_transform_one | python | scikit-learn/scikit-learn | sklearn/pipeline.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/pipeline.py | BSD-3-Clause |
def set_output(self, *, transform=None):
"""Set the output container when `"transform"` and `"fit_transform"` are called.
`set_output` will set the output of all estimators in `transformer_list`.
Parameters
----------
transform : {"default", "pandas", "polars"}, default=None
... | Set the output container when `"transform"` and `"fit_transform"` are called.
`set_output` will set the output of all estimators in `transformer_list`.
Parameters
----------
transform : {"default", "pandas", "polars"}, default=None
Configure output of `transform` and `fit_t... | set_output | python | scikit-learn/scikit-learn | sklearn/pipeline.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/pipeline.py | BSD-3-Clause |
def _iter(self):
"""
Generate (name, trans, weight) tuples excluding None and
'drop' transformers.
"""
get_weight = (self.transformer_weights or {}).get
for name, trans in self.transformer_list:
if trans == "drop":
continue
if tra... |
Generate (name, trans, weight) tuples excluding None and
'drop' transformers.
| _iter | python | scikit-learn/scikit-learn | sklearn/pipeline.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/pipeline.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.
Returns
-------
feature_names_out : ndarray of str ob... | Get output feature names for transformation.
Parameters
----------
input_features : array-like of str or None, default=None
Input features.
Returns
-------
feature_names_out : ndarray of str objects
Transformed feature names.
| get_feature_names_out | python | scikit-learn/scikit-learn | sklearn/pipeline.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/pipeline.py | BSD-3-Clause |
def _add_prefix_for_feature_names_out(self, transformer_with_feature_names_out):
"""Add prefix for feature names out that includes the transformer names.
Parameters
----------
transformer_with_feature_names_out : list of tuples of (str, array-like of str)
The tuple consisten... | Add prefix for feature names out that includes the transformer names.
Parameters
----------
transformer_with_feature_names_out : list of tuples of (str, array-like of str)
The tuple consistent of the transformer's name and its feature names out.
Returns
-------
... | _add_prefix_for_feature_names_out | python | scikit-learn/scikit-learn | sklearn/pipeline.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/pipeline.py | BSD-3-Clause |
def fit(self, X, y=None, **fit_params):
"""Fit all transformers using X.
Parameters
----------
X : iterable or array-like, depending on transformers
Input data, used to fit transformers.
y : array-like of shape (n_samples, n_outputs), default=None
Target... | Fit all transformers using X.
Parameters
----------
X : iterable or array-like, depending on transformers
Input data, used to fit transformers.
y : array-like of shape (n_samples, n_outputs), default=None
Targets for supervised learning.
**fit_params : ... | fit | python | scikit-learn/scikit-learn | sklearn/pipeline.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/pipeline.py | BSD-3-Clause |
def fit_transform(self, X, y=None, **params):
"""Fit all transformers, transform the data and concatenate results.
Parameters
----------
X : iterable or array-like, depending on transformers
Input data to be transformed.
y : array-like of shape (n_samples, n_outputs... | Fit all transformers, transform the data and concatenate results.
Parameters
----------
X : iterable or array-like, depending on transformers
Input data to be transformed.
y : array-like of shape (n_samples, n_outputs), default=None
Targets for supervised learni... | fit_transform | python | scikit-learn/scikit-learn | sklearn/pipeline.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/pipeline.py | BSD-3-Clause |
def _parallel_func(self, X, y, func, routed_params):
"""Runs func in parallel on X and y"""
self.transformer_list = list(self.transformer_list)
self._validate_transformers()
self._validate_transformer_weights()
transformers = list(self._iter())
return Parallel(n_jobs=sel... | Runs func in parallel on X and y | _parallel_func | python | scikit-learn/scikit-learn | sklearn/pipeline.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/pipeline.py | BSD-3-Clause |
def transform(self, X, **params):
"""Transform X separately by each transformer, concatenate results.
Parameters
----------
X : iterable or array-like, depending on transformers
Input data to be transformed.
**params : dict, default=None
Parameters rout... | Transform X separately by each transformer, concatenate results.
Parameters
----------
X : iterable or array-like, depending on transformers
Input data to be transformed.
**params : dict, default=None
Parameters routed to the `transform` method of the sub-trans... | transform | python | scikit-learn/scikit-learn | sklearn/pipeline.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/pipeline.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.5
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.5
Returns
-------
routing : MetadataRouter
A :class:`~sklearn.utils.metadata_routing.MetadataRouter` encapsulating... | get_metadata_routing | python | scikit-learn/scikit-learn | sklearn/pipeline.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/pipeline.py | BSD-3-Clause |
def johnson_lindenstrauss_min_dim(n_samples, *, eps=0.1):
"""Find a 'safe' number of components to randomly project to.
The distortion introduced by a random projection `p` only changes the
distance between two points by a factor (1 +- eps) in a euclidean space
with good probability. The projection `p`... | Find a 'safe' number of components to randomly project to.
The distortion introduced by a random projection `p` only changes the
distance between two points by a factor (1 +- eps) in a euclidean space
with good probability. The projection `p` is an eps-embedding as defined
by:
.. code-block:: text... | johnson_lindenstrauss_min_dim | python | scikit-learn/scikit-learn | sklearn/random_projection.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/random_projection.py | BSD-3-Clause |
def _check_density(density, n_features):
"""Factorize density check according to Li et al."""
if density == "auto":
density = 1 / np.sqrt(n_features)
elif density <= 0 or density > 1:
raise ValueError("Expected density in range ]0, 1], got: %r" % density)
return density | Factorize density check according to Li et al. | _check_density | python | scikit-learn/scikit-learn | sklearn/random_projection.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/random_projection.py | BSD-3-Clause |
def _check_input_size(n_components, n_features):
"""Factorize argument checking for random matrix generation."""
if n_components <= 0:
raise ValueError(
"n_components must be strictly positive, got %d" % n_components
)
if n_features <= 0:
raise ValueError("n_features must... | Factorize argument checking for random matrix generation. | _check_input_size | python | scikit-learn/scikit-learn | sklearn/random_projection.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/random_projection.py | BSD-3-Clause |
def _gaussian_random_matrix(n_components, n_features, random_state=None):
"""Generate a dense Gaussian random matrix.
The components of the random matrix are drawn from
N(0, 1.0 / n_components).
Read more in the :ref:`User Guide <gaussian_random_matrix>`.
Parameters
----------
n_comp... | Generate a dense Gaussian random matrix.
The components of the random matrix are drawn from
N(0, 1.0 / n_components).
Read more in the :ref:`User Guide <gaussian_random_matrix>`.
Parameters
----------
n_components : int,
Dimensionality of the target projection space.
n_featu... | _gaussian_random_matrix | python | scikit-learn/scikit-learn | sklearn/random_projection.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/random_projection.py | BSD-3-Clause |
def _make_random_matrix(self, n_components, n_features):
"""Generate the random projection matrix.
Parameters
----------
n_components : int,
Dimensionality of the target projection space.
n_features : int,
Dimensionality of the original source space.
... | Generate the random projection matrix.
Parameters
----------
n_components : int,
Dimensionality of the target projection space.
n_features : int,
Dimensionality of the original source space.
Returns
-------
components : {ndarray, sparse ... | _make_random_matrix | python | scikit-learn/scikit-learn | sklearn/random_projection.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/random_projection.py | BSD-3-Clause |
def _compute_inverse_components(self):
"""Compute the pseudo-inverse of the (densified) components."""
components = self.components_
if sp.issparse(components):
components = components.toarray()
return linalg.pinv(components, check_finite=False) | Compute the pseudo-inverse of the (densified) components. | _compute_inverse_components | python | scikit-learn/scikit-learn | sklearn/random_projection.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/random_projection.py | BSD-3-Clause |
def fit(self, X, y=None):
"""Generate a sparse random projection matrix.
Parameters
----------
X : {ndarray, sparse matrix} of shape (n_samples, n_features)
Training set: only the shape is used to find optimal random
matrix dimensions based on the theory referenc... | Generate a sparse random projection matrix.
Parameters
----------
X : {ndarray, sparse matrix} of shape (n_samples, n_features)
Training set: only the shape is used to find optimal random
matrix dimensions based on the theory referenced in the
afore mentioned... | fit | python | scikit-learn/scikit-learn | sklearn/random_projection.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/random_projection.py | BSD-3-Clause |
def inverse_transform(self, X):
"""Project data back to its original space.
Returns an array X_original whose transform would be X. Note that even
if X is sparse, X_original is dense: this may use a lot of RAM.
If `compute_inverse_components` is False, the inverse of the components is
... | Project data back to its original space.
Returns an array X_original whose transform would be X. Note that even
if X is sparse, X_original is dense: this may use a lot of RAM.
If `compute_inverse_components` is False, the inverse of the components is
computed during each call to `inver... | inverse_transform | python | scikit-learn/scikit-learn | sklearn/random_projection.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/random_projection.py | BSD-3-Clause |
def _make_random_matrix(self, n_components, n_features):
"""Generate the random projection matrix.
Parameters
----------
n_components : int,
Dimensionality of the target projection space.
n_features : int,
Dimensionality of the original source space.
... | Generate the random projection matrix.
Parameters
----------
n_components : int,
Dimensionality of the target projection space.
n_features : int,
Dimensionality of the original source space.
Returns
-------
components : ndarray of shape ... | _make_random_matrix | python | scikit-learn/scikit-learn | sklearn/random_projection.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/random_projection.py | BSD-3-Clause |
def transform(self, X):
"""Project the data by using matrix product with the random matrix.
Parameters
----------
X : {ndarray, sparse matrix} of shape (n_samples, n_features)
The input data to project into a smaller dimensional space.
Returns
-------
... | Project the data by using matrix product with the random matrix.
Parameters
----------
X : {ndarray, sparse matrix} of shape (n_samples, n_features)
The input data to project into a smaller dimensional space.
Returns
-------
X_new : ndarray of shape (n_sampl... | transform | python | scikit-learn/scikit-learn | sklearn/random_projection.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/random_projection.py | BSD-3-Clause |
def _make_random_matrix(self, n_components, n_features):
"""Generate the random projection matrix
Parameters
----------
n_components : int
Dimensionality of the target projection space.
n_features : int
Dimensionality of the original source space.
... | Generate the random projection matrix
Parameters
----------
n_components : int
Dimensionality of the target projection space.
n_features : int
Dimensionality of the original source space.
Returns
-------
components : sparse matrix of sha... | _make_random_matrix | python | scikit-learn/scikit-learn | sklearn/random_projection.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/random_projection.py | BSD-3-Clause |
def transform(self, X):
"""Project the data by using matrix product with the random matrix.
Parameters
----------
X : {ndarray, sparse matrix} of shape (n_samples, n_features)
The input data to project into a smaller dimensional space.
Returns
-------
... | Project the data by using matrix product with the random matrix.
Parameters
----------
X : {ndarray, sparse matrix} of shape (n_samples, n_features)
The input data to project into a smaller dimensional space.
Returns
-------
X_new : {ndarray, sparse matrix} ... | transform | python | scikit-learn/scikit-learn | sklearn/random_projection.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/random_projection.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.