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 _class_cov(X, y, priors, shrinkage=None, covariance_estimator=None):
"""Compute weighted within-class covariance matrix.
The per-class covariance are weighted by the class priors.
Parameters
----------
X : array-like of shape (n_samples, n_features)
Input data.
y : array-like of s... | Compute weighted within-class covariance matrix.
The per-class covariance are weighted by the class priors.
Parameters
----------
X : array-like of shape (n_samples, n_features)
Input data.
y : array-like of shape (n_samples,) or (n_samples, n_targets)
Target values.
priors :... | _class_cov | python | scikit-learn/scikit-learn | sklearn/discriminant_analysis.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/discriminant_analysis.py | BSD-3-Clause |
def decision_function(self, X):
"""Apply decision function to an array of samples.
Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_features)
Array of samples (test vectors).
Returns
-------
y_scores : ndarray of shape (n_... | Apply decision function to an array of samples.
Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_features)
Array of samples (test vectors).
Returns
-------
y_scores : ndarray of shape (n_samples,) or (n_samples, n_classes)
... | decision_function | python | scikit-learn/scikit-learn | sklearn/discriminant_analysis.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/discriminant_analysis.py | BSD-3-Clause |
def predict_log_proba(self, X):
"""Estimate log class probabilities.
Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_features)
Input data.
Returns
-------
y_log_proba : ndarray of shape (n_samples, n_classes)
... | Estimate log class probabilities.
Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_features)
Input data.
Returns
-------
y_log_proba : ndarray of shape (n_samples, n_classes)
Estimated log probabilities.
| predict_log_proba | python | scikit-learn/scikit-learn | sklearn/discriminant_analysis.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/discriminant_analysis.py | BSD-3-Clause |
def _solve_lstsq(self, X, y, shrinkage, covariance_estimator):
"""Least squares solver.
The least squares solver computes a straightforward solution of the
optimal decision rule based directly on the discriminant functions. It
can only be used for classification (with any covariance est... | Least squares solver.
The least squares solver computes a straightforward solution of the
optimal decision rule based directly on the discriminant functions. It
can only be used for classification (with any covariance estimator),
because
estimation of eigenvectors is not perform... | _solve_lstsq | python | scikit-learn/scikit-learn | sklearn/discriminant_analysis.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/discriminant_analysis.py | BSD-3-Clause |
def _solve_eigen(self, X, y, shrinkage, covariance_estimator):
"""Eigenvalue solver.
The eigenvalue solver computes the optimal solution of the Rayleigh
coefficient (basically the ratio of between class scatter to within
class scatter). This solver supports both classification and
... | Eigenvalue solver.
The eigenvalue solver computes the optimal solution of the Rayleigh
coefficient (basically the ratio of between class scatter to within
class scatter). This solver supports both classification and
dimensionality reduction (with any covariance estimator).
Para... | _solve_eigen | python | scikit-learn/scikit-learn | sklearn/discriminant_analysis.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/discriminant_analysis.py | BSD-3-Clause |
def _solve_svd(self, X, y):
"""SVD solver.
Parameters
----------
X : array-like of shape (n_samples, n_features)
Training data.
y : array-like of shape (n_samples,) or (n_samples, n_targets)
Target values.
"""
xp, is_array_api_compliant =... | SVD solver.
Parameters
----------
X : array-like of shape (n_samples, n_features)
Training data.
y : array-like of shape (n_samples,) or (n_samples, n_targets)
Target values.
| _solve_svd | python | scikit-learn/scikit-learn | sklearn/discriminant_analysis.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/discriminant_analysis.py | BSD-3-Clause |
def fit(self, X, y):
"""Fit the Linear Discriminant Analysis model.
.. versionchanged:: 0.19
`store_covariance` and `tol` has been moved to main constructor.
Parameters
----------
X : array-like of shape (n_samples, n_features)
Training data.
y ... | Fit the Linear Discriminant Analysis model.
.. versionchanged:: 0.19
`store_covariance` and `tol` has been moved to main constructor.
Parameters
----------
X : array-like of shape (n_samples, n_features)
Training data.
y : array-like of shape (n_samples... | fit | python | scikit-learn/scikit-learn | sklearn/discriminant_analysis.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/discriminant_analysis.py | BSD-3-Clause |
def transform(self, X):
"""Project data to maximize class separation.
Parameters
----------
X : array-like of shape (n_samples, n_features)
Input data.
Returns
-------
X_new : ndarray of shape (n_samples, n_components) or \
(n_samples, mi... | Project data to maximize class separation.
Parameters
----------
X : array-like of shape (n_samples, n_features)
Input data.
Returns
-------
X_new : ndarray of shape (n_samples, n_components) or (n_samples, min(rank, n_components))
Tr... | transform | python | scikit-learn/scikit-learn | sklearn/discriminant_analysis.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/discriminant_analysis.py | BSD-3-Clause |
def predict_proba(self, X):
"""Estimate probability.
Parameters
----------
X : array-like of shape (n_samples, n_features)
Input data.
Returns
-------
C : ndarray of shape (n_samples, n_classes)
Estimated probabilities.
"""
... | Estimate probability.
Parameters
----------
X : array-like of shape (n_samples, n_features)
Input data.
Returns
-------
C : ndarray of shape (n_samples, n_classes)
Estimated probabilities.
| predict_proba | python | scikit-learn/scikit-learn | sklearn/discriminant_analysis.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/discriminant_analysis.py | BSD-3-Clause |
def predict_log_proba(self, X):
"""Estimate log probability.
Parameters
----------
X : array-like of shape (n_samples, n_features)
Input data.
Returns
-------
C : ndarray of shape (n_samples, n_classes)
Estimated log probabilities.
... | Estimate log probability.
Parameters
----------
X : array-like of shape (n_samples, n_features)
Input data.
Returns
-------
C : ndarray of shape (n_samples, n_classes)
Estimated log probabilities.
| predict_log_proba | python | scikit-learn/scikit-learn | sklearn/discriminant_analysis.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/discriminant_analysis.py | BSD-3-Clause |
def fit(self, X, y):
"""Fit the model according to the given training data and parameters.
.. versionchanged:: 0.19
``store_covariances`` has been moved to main constructor as
``store_covariance``.
.. versionchanged:: 0.19
``tol`` has been moved to main cons... | Fit the model according to the given training data and parameters.
.. versionchanged:: 0.19
``store_covariances`` has been moved to main constructor as
``store_covariance``.
.. versionchanged:: 0.19
``tol`` has been moved to main constructor.
Parameters
... | fit | python | scikit-learn/scikit-learn | sklearn/discriminant_analysis.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/discriminant_analysis.py | BSD-3-Clause |
def predict_proba(self, X):
"""Return posterior probabilities of classification.
Parameters
----------
X : array-like of shape (n_samples, n_features)
Array of samples/test vectors.
Returns
-------
C : ndarray of shape (n_samples, n_classes)
... | Return posterior probabilities of classification.
Parameters
----------
X : array-like of shape (n_samples, n_features)
Array of samples/test vectors.
Returns
-------
C : ndarray of shape (n_samples, n_classes)
Posterior probabilities of classifi... | predict_proba | python | scikit-learn/scikit-learn | sklearn/discriminant_analysis.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/discriminant_analysis.py | BSD-3-Clause |
def fit(self, X, y, sample_weight=None):
"""Fit the baseline classifier.
Parameters
----------
X : array-like of shape (n_samples, n_features)
Training data.
y : array-like of shape (n_samples,) or (n_samples, n_outputs)
Target values.
sample_we... | Fit the baseline classifier.
Parameters
----------
X : array-like of shape (n_samples, n_features)
Training data.
y : array-like of shape (n_samples,) or (n_samples, n_outputs)
Target values.
sample_weight : array-like of shape (n_samples,), default=Non... | fit | python | scikit-learn/scikit-learn | sklearn/dummy.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/dummy.py | BSD-3-Clause |
def predict(self, X):
"""Perform classification on test vectors X.
Parameters
----------
X : array-like of shape (n_samples, n_features)
Test data.
Returns
-------
y : array-like of shape (n_samples,) or (n_samples, n_outputs)
Predicted t... | Perform classification on test vectors X.
Parameters
----------
X : array-like of shape (n_samples, n_features)
Test data.
Returns
-------
y : array-like of shape (n_samples,) or (n_samples, n_outputs)
Predicted target values for X.
| predict | python | scikit-learn/scikit-learn | sklearn/dummy.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/dummy.py | BSD-3-Clause |
def predict_proba(self, X):
"""
Return probability estimates for the test vectors X.
Parameters
----------
X : array-like of shape (n_samples, n_features)
Test data.
Returns
-------
P : ndarray of shape (n_samples, n_classes) or list of such ... |
Return probability estimates for the test vectors X.
Parameters
----------
X : array-like of shape (n_samples, n_features)
Test data.
Returns
-------
P : ndarray of shape (n_samples, n_classes) or list of such arrays
Returns the probabil... | predict_proba | python | scikit-learn/scikit-learn | sklearn/dummy.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/dummy.py | BSD-3-Clause |
def predict_log_proba(self, X):
"""
Return log probability estimates for the test vectors X.
Parameters
----------
X : {array-like, object with finite length or shape}
Training data.
Returns
-------
P : ndarray of shape (n_samples, n_classes)... |
Return log probability estimates for the test vectors X.
Parameters
----------
X : {array-like, object with finite length or shape}
Training data.
Returns
-------
P : ndarray of shape (n_samples, n_classes) or list of such arrays
Returns... | predict_log_proba | python | scikit-learn/scikit-learn | sklearn/dummy.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/dummy.py | BSD-3-Clause |
def score(self, X, y, sample_weight=None):
"""Return the mean accuracy on the given test data and labels.
In multi-label classification, this is the subset accuracy
which is a harsh metric since you require for each sample that
each label set be correctly predicted.
Parameters
... | Return the mean accuracy on the given test data and labels.
In multi-label classification, this is the subset accuracy
which is a harsh metric since you require for each sample that
each label set be correctly predicted.
Parameters
----------
X : None or array-like of s... | score | python | scikit-learn/scikit-learn | sklearn/dummy.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/dummy.py | BSD-3-Clause |
def fit(self, X, y, sample_weight=None):
"""Fit the baseline regressor.
Parameters
----------
X : array-like of shape (n_samples, n_features)
Training data.
y : array-like of shape (n_samples,) or (n_samples, n_outputs)
Target values.
sample_wei... | Fit the baseline regressor.
Parameters
----------
X : array-like of shape (n_samples, n_features)
Training data.
y : array-like of shape (n_samples,) or (n_samples, n_outputs)
Target values.
sample_weight : array-like of shape (n_samples,), default=None... | fit | python | scikit-learn/scikit-learn | sklearn/dummy.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/dummy.py | BSD-3-Clause |
def predict(self, X, return_std=False):
"""Perform classification on test vectors X.
Parameters
----------
X : array-like of shape (n_samples, n_features)
Test data.
return_std : bool, default=False
Whether to return the standard deviation of posterior p... | Perform classification on test vectors X.
Parameters
----------
X : array-like of shape (n_samples, n_features)
Test data.
return_std : bool, default=False
Whether to return the standard deviation of posterior prediction.
All zeros in this case.
... | predict | python | scikit-learn/scikit-learn | sklearn/dummy.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/dummy.py | BSD-3-Clause |
def score(self, X, y, sample_weight=None):
"""Return the coefficient of determination R^2 of the prediction.
The coefficient R^2 is defined as `(1 - u/v)`, where `u` is the
residual sum of squares `((y_true - y_pred) ** 2).sum()` and `v` is the
total sum of squares `((y_true - y_true.me... | Return the coefficient of determination R^2 of the prediction.
The coefficient R^2 is defined as `(1 - u/v)`, where `u` is the
residual sum of squares `((y_true - y_pred) ** 2).sum()` and `v` is the
total sum of squares `((y_true - y_true.mean()) ** 2).sum()`. The best
possible score is... | score | python | scikit-learn/scikit-learn | sklearn/dummy.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/dummy.py | BSD-3-Clause |
def check_increasing(x, y):
"""Determine whether y is monotonically correlated with x.
y is found increasing or decreasing with respect to x based on a Spearman
correlation test.
Parameters
----------
x : array-like of shape (n_samples,)
Training data.
y : array-like of shape ... | Determine whether y is monotonically correlated with x.
y is found increasing or decreasing with respect to x based on a Spearman
correlation test.
Parameters
----------
x : array-like of shape (n_samples,)
Training data.
y : array-like of shape (n_samples,)
Training targe... | check_increasing | python | scikit-learn/scikit-learn | sklearn/isotonic.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/isotonic.py | BSD-3-Clause |
def isotonic_regression(
y, *, sample_weight=None, y_min=None, y_max=None, increasing=True
):
"""Solve the isotonic regression model.
Read more in the :ref:`User Guide <isotonic>`.
Parameters
----------
y : array-like of shape (n_samples,)
The data.
sample_weight : array-like of s... | Solve the isotonic regression model.
Read more in the :ref:`User Guide <isotonic>`.
Parameters
----------
y : array-like of shape (n_samples,)
The data.
sample_weight : array-like of shape (n_samples,), default=None
Weights on each point of the regression.
If None, weight ... | isotonic_regression | python | scikit-learn/scikit-learn | sklearn/isotonic.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/isotonic.py | BSD-3-Clause |
def fit(self, X, y, sample_weight=None):
"""Fit the model using X, y as training data.
Parameters
----------
X : array-like of shape (n_samples,) or (n_samples, 1)
Training data.
.. versionchanged:: 0.24
Also accepts 2d array with 1 feature.
... | Fit the model using X, y as training data.
Parameters
----------
X : array-like of shape (n_samples,) or (n_samples, 1)
Training data.
.. versionchanged:: 0.24
Also accepts 2d array with 1 feature.
y : array-like of shape (n_samples,)
... | fit | python | scikit-learn/scikit-learn | sklearn/isotonic.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/isotonic.py | BSD-3-Clause |
def _transform(self, T):
"""`_transform` is called by both `transform` and `predict` methods.
Since `transform` is wrapped to output arrays of specific types (e.g.
NumPy arrays, pandas DataFrame), we cannot make `predict` call `transform`
directly.
The above behaviour could be ... | `_transform` is called by both `transform` and `predict` methods.
Since `transform` is wrapped to output arrays of specific types (e.g.
NumPy arrays, pandas DataFrame), we cannot make `predict` call `transform`
directly.
The above behaviour could be changed in the future, if we decide ... | _transform | python | scikit-learn/scikit-learn | sklearn/isotonic.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/isotonic.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
Ignored.
Returns
-------
feature_names_out : ndarray of str objects
... | Get output feature names for transformation.
Parameters
----------
input_features : array-like of str or None, default=None
Ignored.
Returns
-------
feature_names_out : ndarray of str objects
An ndarray with one string i.e. ["isotonicregression0"... | get_feature_names_out | python | scikit-learn/scikit-learn | sklearn/isotonic.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/isotonic.py | BSD-3-Clause |
def __getstate__(self):
"""Pickle-protocol - return state of the estimator."""
state = super().__getstate__()
# remove interpolation method
state.pop("f_", None)
return state | Pickle-protocol - return state of the estimator. | __getstate__ | python | scikit-learn/scikit-learn | sklearn/isotonic.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/isotonic.py | BSD-3-Clause |
def __setstate__(self, state):
"""Pickle-protocol - set state of the estimator.
We need to rebuild the interpolation function.
"""
super().__setstate__(state)
if hasattr(self, "X_thresholds_") and hasattr(self, "y_thresholds_"):
self._build_f(self.X_thresholds_, self... | Pickle-protocol - set state of the estimator.
We need to rebuild the interpolation function.
| __setstate__ | python | scikit-learn/scikit-learn | sklearn/isotonic.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/isotonic.py | BSD-3-Clause |
def fit(self, X, y=None):
"""Fit the model with X.
Initializes the internal variables. The method needs no information
about the distribution of data, so we only care about n_features in X.
Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_fea... | Fit the model with X.
Initializes the internal variables. The method needs no information
about the distribution of data, so we only care about n_features in X.
Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_features)
Training data, whe... | 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):
"""Generate the feature map approximation for X.
Parameters
----------
X : {array-like}, shape (n_samples, n_features)
New data, where `n_samples` is the number of samples
and `n_features` is the number of features.
Returns
... | Generate the feature map approximation for X.
Parameters
----------
X : {array-like}, shape (n_samples, n_features)
New data, where `n_samples` is the number of samples
and `n_features` is the number of features.
Returns
-------
X_new : array-lik... | 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=None):
"""Fit the model with X.
Samples random projection according to n_features.
Parameters
----------
X : {array-like, sparse matrix}, shape (n_samples, n_features)
Training data, where `n_samples` is the number of samples
and `n_fe... | Fit the model with X.
Samples random projection according to n_features.
Parameters
----------
X : {array-like, sparse matrix}, shape (n_samples, n_features)
Training data, where `n_samples` is the number of samples
and `n_features` is the number of features.
... | 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 the approximate feature map to X.
Parameters
----------
X : {array-like, sparse matrix}, shape (n_samples, n_features)
New data, where `n_samples` is the number of samples
and `n_features` is the number of features.
Retur... | Apply the approximate feature map to X.
Parameters
----------
X : {array-like, sparse matrix}, shape (n_samples, n_features)
New data, where `n_samples` is the number of samples
and `n_features` is the number of features.
Returns
-------
X_new : ... | 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=None):
"""Fit the model with X.
Samples random projection according to n_features.
Parameters
----------
X : array-like, shape (n_samples, n_features)
Training data, where `n_samples` is the number of samples
and `n_features` is the nu... | Fit the model with X.
Samples random projection according to n_features.
Parameters
----------
X : array-like, shape (n_samples, n_features)
Training data, where `n_samples` is the number of samples
and `n_features` is the number of features.
y : array-... | 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 the approximate feature map to X.
Parameters
----------
X : array-like, shape (n_samples, n_features)
New data, where `n_samples` is the number of samples
and `n_features` is the number of features. All values of X must be
... | Apply the approximate feature map to X.
Parameters
----------
X : array-like, shape (n_samples, n_features)
New data, where `n_samples` is the number of samples
and `n_features` is the number of features. All values of X must be
strictly greater than "-skewed... | 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=None):
"""Only validates estimator's parameters.
This method allows to: (i) validate the estimator's parameters and
(ii) be consistent with the scikit-learn transformer API.
Parameters
----------
X : array-like, shape (n_samples, n_features)
... | Only validates estimator's parameters.
This method allows to: (i) validate the estimator's parameters and
(ii) be consistent with the scikit-learn transformer API.
Parameters
----------
X : array-like, shape (n_samples, n_features)
Training data, where `n_samples` i... | 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 approximate feature map to X.
Parameters
----------
X : {array-like, sparse matrix}, shape (n_samples, n_features)
Training data, where `n_samples` is the number of samples
and `n_features` is the number of features.
Retu... | Apply approximate feature map to X.
Parameters
----------
X : {array-like, sparse matrix}, shape (n_samples, n_features)
Training data, where `n_samples` is the number of samples
and `n_features` is the number of features.
Returns
-------
X_new :... | 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 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 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 _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 _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 _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 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.