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 test_partial_dependence_kind_list(
pyplot,
clf_diabetes,
diabetes,
):
"""Check that we can provide a list of strings to kind parameter."""
matplotlib = pytest.importorskip("matplotlib")
disp = PartialDependenceDisplay.from_estimator(
clf_diabetes,
diabetes.data,
feat... | Check that we can provide a list of strings to kind parameter. | test_partial_dependence_kind_list | python | scikit-learn/scikit-learn | sklearn/inspection/_plot/tests/test_plot_partial_dependence.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/inspection/_plot/tests/test_plot_partial_dependence.py | BSD-3-Clause |
def test_partial_dependence_kind_error(
pyplot,
clf_diabetes,
diabetes,
features,
kind,
):
"""Check that we raise an informative error when 2-way PD is requested
together with 1-way PD/ICE"""
warn_msg = (
"ICE plot cannot be rendered for 2-way feature interactions. 2-way "
... | Check that we raise an informative error when 2-way PD is requested
together with 1-way PD/ICE | test_partial_dependence_kind_error | python | scikit-learn/scikit-learn | sklearn/inspection/_plot/tests/test_plot_partial_dependence.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/inspection/_plot/tests/test_plot_partial_dependence.py | BSD-3-Clause |
def test_plot_partial_dependence_lines_kw(
pyplot,
clf_diabetes,
diabetes,
line_kw,
pd_line_kw,
ice_lines_kw,
expected_colors,
):
"""Check that passing `pd_line_kw` and `ice_lines_kw` will act on the
specific lines in the plot.
"""
disp = PartialDependenceDisplay.from_estima... | Check that passing `pd_line_kw` and `ice_lines_kw` will act on the
specific lines in the plot.
| test_plot_partial_dependence_lines_kw | python | scikit-learn/scikit-learn | sklearn/inspection/_plot/tests/test_plot_partial_dependence.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/inspection/_plot/tests/test_plot_partial_dependence.py | BSD-3-Clause |
def test_partial_dependence_display_wrong_len_kind(
pyplot,
clf_diabetes,
diabetes,
):
"""Check that we raise an error when `kind` is a list with a wrong length.
This case can only be triggered using the `PartialDependenceDisplay.from_estimator`
method.
"""
disp = PartialDependenceDispl... | Check that we raise an error when `kind` is a list with a wrong length.
This case can only be triggered using the `PartialDependenceDisplay.from_estimator`
method.
| test_partial_dependence_display_wrong_len_kind | python | scikit-learn/scikit-learn | sklearn/inspection/_plot/tests/test_plot_partial_dependence.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/inspection/_plot/tests/test_plot_partial_dependence.py | BSD-3-Clause |
def test_partial_dependence_display_kind_centered_interaction(
pyplot,
kind,
clf_diabetes,
diabetes,
):
"""Check that we properly center ICE and PD when passing kind as a string and as a
list."""
disp = PartialDependenceDisplay.from_estimator(
clf_diabetes,
diabetes.data,
... | Check that we properly center ICE and PD when passing kind as a string and as a
list. | test_partial_dependence_display_kind_centered_interaction | python | scikit-learn/scikit-learn | sklearn/inspection/_plot/tests/test_plot_partial_dependence.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/inspection/_plot/tests/test_plot_partial_dependence.py | BSD-3-Clause |
def test_partial_dependence_display_with_constant_sample_weight(
pyplot,
clf_diabetes,
diabetes,
):
"""Check that the utilization of a constant sample weight maintains the
standard behavior.
"""
disp = PartialDependenceDisplay.from_estimator(
clf_diabetes,
diabetes.data,
... | Check that the utilization of a constant sample weight maintains the
standard behavior.
| test_partial_dependence_display_with_constant_sample_weight | python | scikit-learn/scikit-learn | sklearn/inspection/_plot/tests/test_plot_partial_dependence.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/inspection/_plot/tests/test_plot_partial_dependence.py | BSD-3-Clause |
def make_dataset(X, y, sample_weight, random_state=None):
"""Create ``Dataset`` abstraction for sparse and dense inputs.
This also returns the ``intercept_decay`` which is different
for sparse datasets.
Parameters
----------
X : array-like, shape (n_samples, n_features)
Training data
... | Create ``Dataset`` abstraction for sparse and dense inputs.
This also returns the ``intercept_decay`` which is different
for sparse datasets.
Parameters
----------
X : array-like, shape (n_samples, n_features)
Training data
y : array-like, shape (n_samples, )
Target values.
... | make_dataset | python | scikit-learn/scikit-learn | sklearn/linear_model/_base.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_base.py | BSD-3-Clause |
def _preprocess_data(
X,
y,
*,
fit_intercept,
copy=True,
copy_y=True,
sample_weight=None,
check_input=True,
):
"""Common data preprocessing for fitting linear models.
This helper is in charge of the following steps:
- Ensure that `sample_weight` is an array or `None`.
-... | Common data preprocessing for fitting linear models.
This helper is in charge of the following steps:
- Ensure that `sample_weight` is an array or `None`.
- If `check_input=True`, perform standard input validation of `X`, `y`.
- Perform copies if requested to avoid side-effects in case of inplace
... | _preprocess_data | python | scikit-learn/scikit-learn | sklearn/linear_model/_base.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_base.py | BSD-3-Clause |
def _rescale_data(X, y, sample_weight, inplace=False):
"""Rescale data sample-wise by square root of sample_weight.
For many linear models, this enables easy support for sample_weight because
(y - X w)' S (y - X w)
with S = diag(sample_weight) becomes
||y_rescaled - X_rescaled w||_2^2
... | Rescale data sample-wise by square root of sample_weight.
For many linear models, this enables easy support for sample_weight because
(y - X w)' S (y - X w)
with S = diag(sample_weight) becomes
||y_rescaled - X_rescaled w||_2^2
when setting
y_rescaled = sqrt(S) y
X_resc... | _rescale_data | python | scikit-learn/scikit-learn | sklearn/linear_model/_base.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_base.py | BSD-3-Clause |
def decision_function(self, X):
"""
Predict confidence scores for samples.
The confidence score for a sample is proportional to the signed
distance of that sample to the hyperplane.
Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_fea... |
Predict confidence scores for samples.
The confidence score for a sample is proportional to the signed
distance of that sample to the hyperplane.
Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_features)
The data matrix for whic... | decision_function | python | scikit-learn/scikit-learn | sklearn/linear_model/_base.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_base.py | BSD-3-Clause |
def predict(self, X):
"""
Predict class labels for samples in X.
Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_features)
The data matrix for which we want to get the predictions.
Returns
-------
y_pred : ndarray... |
Predict class labels for samples in X.
Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_features)
The data matrix for which we want to get the predictions.
Returns
-------
y_pred : ndarray of shape (n_samples,)
... | predict | python | scikit-learn/scikit-learn | sklearn/linear_model/_base.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_base.py | BSD-3-Clause |
def _predict_proba_lr(self, X):
"""Probability estimation for OvR logistic regression.
Positive class probabilities are computed as
1. / (1. + np.exp(-self.decision_function(X)));
multiclass is handled by normalizing that over all classes.
"""
prob = self.decision_functi... | Probability estimation for OvR logistic regression.
Positive class probabilities are computed as
1. / (1. + np.exp(-self.decision_function(X)));
multiclass is handled by normalizing that over all classes.
| _predict_proba_lr | python | scikit-learn/scikit-learn | sklearn/linear_model/_base.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_base.py | BSD-3-Clause |
def densify(self):
"""
Convert coefficient matrix to dense array format.
Converts the ``coef_`` member (back) to a numpy.ndarray. This is the
default format of ``coef_`` and is required for fitting, so calling
this method is only required on models that have previously been
... |
Convert coefficient matrix to dense array format.
Converts the ``coef_`` member (back) to a numpy.ndarray. This is the
default format of ``coef_`` and is required for fitting, so calling
this method is only required on models that have previously been
sparsified; otherwise, it ... | densify | python | scikit-learn/scikit-learn | sklearn/linear_model/_base.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_base.py | BSD-3-Clause |
def sparsify(self):
"""
Convert coefficient matrix to sparse format.
Converts the ``coef_`` member to a scipy.sparse matrix, which for
L1-regularized models can be much more memory- and storage-efficient
than the usual numpy.ndarray representation.
The ``intercept_`` me... |
Convert coefficient matrix to sparse format.
Converts the ``coef_`` member to a scipy.sparse matrix, which for
L1-regularized models can be much more memory- and storage-efficient
than the usual numpy.ndarray representation.
The ``intercept_`` member is not converted.
... | sparsify | python | scikit-learn/scikit-learn | sklearn/linear_model/_base.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_base.py | BSD-3-Clause |
def fit(self, X, y, sample_weight=None):
"""
Fit linear model.
Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_features)
Training data.
y : array-like of shape (n_samples,) or (n_samples, n_targets)
Target values. Wil... |
Fit linear model.
Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_features)
Training data.
y : array-like of shape (n_samples,) or (n_samples, n_targets)
Target values. Will be cast to X's dtype if necessary.
sample... | fit | python | scikit-learn/scikit-learn | sklearn/linear_model/_base.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_base.py | BSD-3-Clause |
def _check_precomputed_gram_matrix(
X, precompute, X_offset, X_scale, rtol=None, atol=1e-5
):
"""Computes a single element of the gram matrix and compares it to
the corresponding element of the user supplied gram matrix.
If the values do not match a ValueError will be thrown.
Parameters
------... | Computes a single element of the gram matrix and compares it to
the corresponding element of the user supplied gram matrix.
If the values do not match a ValueError will be thrown.
Parameters
----------
X : ndarray of shape (n_samples, n_features)
Data array.
precompute : array-like of... | _check_precomputed_gram_matrix | python | scikit-learn/scikit-learn | sklearn/linear_model/_base.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_base.py | BSD-3-Clause |
def _pre_fit(
X,
y,
Xy,
precompute,
fit_intercept,
copy,
check_input=True,
sample_weight=None,
):
"""Function used at beginning of fit in linear models with L1 or L0 penalty.
This function applies _preprocess_data and additionally computes the gram matrix
`precompute` as nee... | Function used at beginning of fit in linear models with L1 or L0 penalty.
This function applies _preprocess_data and additionally computes the gram matrix
`precompute` as needed as well as `Xy`.
| _pre_fit | python | scikit-learn/scikit-learn | sklearn/linear_model/_base.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_base.py | BSD-3-Clause |
def fit(self, X, y, sample_weight=None):
"""Fit the model.
Parameters
----------
X : ndarray of shape (n_samples, n_features)
Training data.
y : ndarray of shape (n_samples,)
Target values. Will be cast to X's dtype if necessary.
sample_weight : ... | Fit the model.
Parameters
----------
X : ndarray of shape (n_samples, n_features)
Training data.
y : ndarray of shape (n_samples,)
Target values. Will be cast to X's dtype if necessary.
sample_weight : ndarray of shape (n_samples,), default=None
... | fit | python | scikit-learn/scikit-learn | sklearn/linear_model/_bayes.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_bayes.py | BSD-3-Clause |
def predict(self, X, return_std=False):
"""Predict using the linear model.
In addition to the mean of the predictive distribution, also its
standard deviation can be returned.
Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_features)
... | Predict using the linear model.
In addition to the mean of the predictive distribution, also its
standard deviation can be returned.
Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_features)
Samples.
return_std : bool, default=F... | predict | python | scikit-learn/scikit-learn | sklearn/linear_model/_bayes.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_bayes.py | BSD-3-Clause |
def _update_coef_(
self, X, y, n_samples, n_features, XT_y, U, Vh, eigen_vals_, alpha_, lambda_
):
"""Update posterior mean and compute corresponding sse (sum of squared errors).
Posterior mean is given by coef_ = scaled_sigma_ * X.T * y where
scaled_sigma_ = (lambda_/alpha_ * np.ey... | Update posterior mean and compute corresponding sse (sum of squared errors).
Posterior mean is given by coef_ = scaled_sigma_ * X.T * y where
scaled_sigma_ = (lambda_/alpha_ * np.eye(n_features)
+ np.dot(X.T, X))^-1
| _update_coef_ | python | scikit-learn/scikit-learn | sklearn/linear_model/_bayes.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_bayes.py | BSD-3-Clause |
def fit(self, X, y):
"""Fit the model according to the given training data and parameters.
Iterative procedure to maximize the evidence
Parameters
----------
X : array-like of shape (n_samples, n_features)
Training vector, where `n_samples` is the number of samples ... | Fit the model according to the given training data and parameters.
Iterative procedure to maximize the evidence
Parameters
----------
X : array-like of shape (n_samples, n_features)
Training vector, where `n_samples` is the number of samples and
`n_features` is ... | fit | python | scikit-learn/scikit-learn | sklearn/linear_model/_bayes.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_bayes.py | BSD-3-Clause |
def _set_order(X, y, order="C"):
"""Change the order of X and y if necessary.
Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_features)
Training data.
y : ndarray of shape (n_samples,)
Target values.
order : {None, 'C', 'F'}
If 'C', dense a... | Change the order of X and y if necessary.
Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_features)
Training data.
y : ndarray of shape (n_samples,)
Target values.
order : {None, 'C', 'F'}
If 'C', dense arrays are returned as C-ordered, sparse ... | _set_order | python | scikit-learn/scikit-learn | sklearn/linear_model/_coordinate_descent.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_coordinate_descent.py | BSD-3-Clause |
def _alpha_grid(
X,
y,
Xy=None,
l1_ratio=1.0,
fit_intercept=True,
eps=1e-3,
n_alphas=100,
copy_X=True,
sample_weight=None,
):
"""Compute the grid of alpha values for elastic net parameter search
Parameters
----------
X : {array-like, sparse matrix} of shape (n_sample... | Compute the grid of alpha values for elastic net parameter search
Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_features)
Training data. Pass directly as Fortran-contiguous data to avoid
unnecessary memory duplication
y : ndarray of shape (n_samples,) or ... | _alpha_grid | python | scikit-learn/scikit-learn | sklearn/linear_model/_coordinate_descent.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_coordinate_descent.py | BSD-3-Clause |
def lasso_path(
X,
y,
*,
eps=1e-3,
n_alphas=100,
alphas=None,
precompute="auto",
Xy=None,
copy_X=True,
coef_init=None,
verbose=False,
return_n_iter=False,
positive=False,
**params,
):
"""Compute Lasso path with coordinate descent.
The Lasso optimization f... | Compute Lasso path with coordinate descent.
The Lasso optimization function varies for mono and multi-outputs.
For mono-output tasks it is::
(1 / (2 * n_samples)) * ||y - Xw||^2_2 + alpha * ||w||_1
For multi-output tasks it is::
(1 / (2 * n_samples)) * ||Y - XW||^2_Fro + alpha * ||W||_2... | lasso_path | python | scikit-learn/scikit-learn | sklearn/linear_model/_coordinate_descent.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_coordinate_descent.py | BSD-3-Clause |
def enet_path(
X,
y,
*,
l1_ratio=0.5,
eps=1e-3,
n_alphas=100,
alphas=None,
precompute="auto",
Xy=None,
copy_X=True,
coef_init=None,
verbose=False,
return_n_iter=False,
positive=False,
check_input=True,
**params,
):
"""Compute elastic net path with coor... | Compute elastic net path with coordinate descent.
The elastic net optimization function varies for mono and multi-outputs.
For mono-output tasks it is::
1 / (2 * n_samples) * ||y - Xw||^2_2
+ alpha * l1_ratio * ||w||_1
+ 0.5 * alpha * (1 - l1_ratio) * ||w||^2_2
For multi-output t... | enet_path | python | scikit-learn/scikit-learn | sklearn/linear_model/_coordinate_descent.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_coordinate_descent.py | BSD-3-Clause |
def fit(self, X, y, sample_weight=None, check_input=True):
"""Fit model with coordinate descent.
Parameters
----------
X : {ndarray, sparse matrix, sparse array} of (n_samples, n_features)
Data.
Note that large sparse matrices and arrays requiring `int64`
... | Fit model with coordinate descent.
Parameters
----------
X : {ndarray, sparse matrix, sparse array} of (n_samples, n_features)
Data.
Note that large sparse matrices and arrays requiring `int64`
indices are not accepted.
y : ndarray of shape (n_sampl... | fit | python | scikit-learn/scikit-learn | sklearn/linear_model/_coordinate_descent.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_coordinate_descent.py | BSD-3-Clause |
def _decision_function(self, X):
"""Decision function of the linear model.
Parameters
----------
X : numpy array or scipy.sparse matrix of shape (n_samples, n_features)
Returns
-------
T : ndarray of shape (n_samples,)
The predicted decision function... | Decision function of the linear model.
Parameters
----------
X : numpy array or scipy.sparse matrix of shape (n_samples, n_features)
Returns
-------
T : ndarray of shape (n_samples,)
The predicted decision function.
| _decision_function | python | scikit-learn/scikit-learn | sklearn/linear_model/_coordinate_descent.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_coordinate_descent.py | BSD-3-Clause |
def _path_residuals(
X,
y,
sample_weight,
train,
test,
fit_intercept,
path,
path_params,
alphas=None,
l1_ratio=1,
X_order=None,
dtype=None,
):
"""Returns the MSE for the models computed by 'path'.
Parameters
----------
X : {array-like, sparse matrix} of s... | Returns the MSE for the models computed by 'path'.
Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_features)
Training data.
y : array-like of shape (n_samples,) or (n_samples, n_targets)
Target values.
sample_weight : None or array-like of shape (n_sam... | _path_residuals | python | scikit-learn/scikit-learn | sklearn/linear_model/_coordinate_descent.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_coordinate_descent.py | BSD-3-Clause |
def fit(self, X, y, sample_weight=None, **params):
"""Fit linear model with coordinate descent.
Fit is on grid of alphas and best alpha estimated by cross-validation.
Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_features)
Training dat... | Fit linear model with coordinate descent.
Fit is on grid of alphas and best alpha estimated by cross-validation.
Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_features)
Training data. Pass directly as Fortran-contiguous data
to avo... | fit | python | scikit-learn/scikit-learn | sklearn/linear_model/_coordinate_descent.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_coordinate_descent.py | BSD-3-Clause |
def fit(self, X, y):
"""Fit MultiTaskElasticNet model with coordinate descent.
Parameters
----------
X : ndarray of shape (n_samples, n_features)
Data.
y : ndarray of shape (n_samples, n_targets)
Target. Will be cast to X's dtype if necessary.
Re... | Fit MultiTaskElasticNet model with coordinate descent.
Parameters
----------
X : ndarray of shape (n_samples, n_features)
Data.
y : ndarray of shape (n_samples, n_targets)
Target. Will be cast to X's dtype if necessary.
Returns
-------
se... | fit | python | scikit-learn/scikit-learn | sklearn/linear_model/_coordinate_descent.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_coordinate_descent.py | BSD-3-Clause |
def _huber_loss_and_gradient(w, X, y, epsilon, alpha, sample_weight=None):
"""Returns the Huber loss and the gradient.
Parameters
----------
w : ndarray, shape (n_features + 1,) or (n_features + 2,)
Feature vector.
w[:n_features] gives the coefficients
w[-1] gives the scale fact... | Returns the Huber loss and the gradient.
Parameters
----------
w : ndarray, shape (n_features + 1,) or (n_features + 2,)
Feature vector.
w[:n_features] gives the coefficients
w[-1] gives the scale factor and if the intercept is fit w[-2]
gives the intercept factor.
X : ... | _huber_loss_and_gradient | python | scikit-learn/scikit-learn | sklearn/linear_model/_huber.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_huber.py | BSD-3-Clause |
def fit(self, X, y, sample_weight=None):
"""Fit the model according to the given training data.
Parameters
----------
X : array-like, shape (n_samples, n_features)
Training vector, where `n_samples` is the number of samples and
`n_features` is the number of featu... | Fit the model according to the given training data.
Parameters
----------
X : array-like, shape (n_samples, n_features)
Training vector, where `n_samples` is the number of samples and
`n_features` is the number of features.
y : array-like, shape (n_samples,)
... | fit | python | scikit-learn/scikit-learn | sklearn/linear_model/_huber.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_huber.py | BSD-3-Clause |
def _fit(self, X, y, max_iter, alpha, fit_path, Xy=None):
"""Auxiliary method to fit the model using X, y as training data"""
n_features = X.shape[1]
X, y, X_offset, y_offset, X_scale = _preprocess_data(
X, y, fit_intercept=self.fit_intercept, copy=self.copy_X
)
if ... | Auxiliary method to fit the model using X, y as training data | _fit | python | scikit-learn/scikit-learn | sklearn/linear_model/_least_angle.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_least_angle.py | BSD-3-Clause |
def fit(self, X, y, Xy=None):
"""Fit the model using X, y as training data.
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.
Xy : a... | Fit the model using X, y as training data.
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.
Xy : array-like of shape (n_features,) or (n_fe... | fit | python | scikit-learn/scikit-learn | sklearn/linear_model/_least_angle.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_least_angle.py | BSD-3-Clause |
def _lars_path_residues(
X_train,
y_train,
X_test,
y_test,
Gram=None,
copy=True,
method="lar",
verbose=False,
fit_intercept=True,
max_iter=500,
eps=np.finfo(float).eps,
positive=False,
):
"""Compute the residues on left-out data for a full LARS path
Parameters
... | Compute the residues on left-out data for a full LARS path
Parameters
-----------
X_train : array-like of shape (n_samples, n_features)
The data to fit the LARS on
y_train : array-like of shape (n_samples,)
The target variable to fit LARS on
X_test : array-like of shape (n_samples... | _lars_path_residues | python | scikit-learn/scikit-learn | sklearn/linear_model/_least_angle.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_least_angle.py | BSD-3-Clause |
def fit(self, X, y, **params):
"""Fit the model using X, y as training data.
Parameters
----------
X : array-like of shape (n_samples, n_features)
Training data.
y : array-like of shape (n_samples,)
Target values.
**params : dict, default=None
... | Fit the model using X, y as training data.
Parameters
----------
X : array-like of shape (n_samples, n_features)
Training data.
y : array-like of shape (n_samples,)
Target values.
**params : dict, default=None
Parameters to be passed to the ... | fit | python | scikit-learn/scikit-learn | sklearn/linear_model/_least_angle.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_least_angle.py | BSD-3-Clause |
def fit(self, X, y, copy_X=None):
"""Fit the model using X, y as training data.
Parameters
----------
X : array-like of shape (n_samples, n_features)
Training data.
y : array-like of shape (n_samples,)
Target values. Will be cast to X's dtype if necessar... | Fit the model using X, y as training data.
Parameters
----------
X : array-like of shape (n_samples, n_features)
Training data.
y : array-like of shape (n_samples,)
Target values. Will be cast to X's dtype if necessary.
copy_X : bool, default=None
... | fit | python | scikit-learn/scikit-learn | sklearn/linear_model/_least_angle.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_least_angle.py | BSD-3-Clause |
def _estimate_noise_variance(self, X, y, positive):
"""Compute an estimate of the variance with an OLS model.
Parameters
----------
X : ndarray of shape (n_samples, n_features)
Data to be fitted by the OLS model. We expect the data to be
centered.
y : nd... | Compute an estimate of the variance with an OLS model.
Parameters
----------
X : ndarray of shape (n_samples, n_features)
Data to be fitted by the OLS model. We expect the data to be
centered.
y : ndarray of shape (n_samples,)
Associated target.
... | _estimate_noise_variance | python | scikit-learn/scikit-learn | sklearn/linear_model/_least_angle.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_least_angle.py | BSD-3-Clause |
def init_zero_coef(self, X, dtype=None):
"""Allocate coef of correct shape with zeros.
Parameters:
-----------
X : {array-like, sparse matrix} of shape (n_samples, n_features)
Training data.
dtype : data-type, default=None
Overrides the data type of coef.... | Allocate coef of correct shape with zeros.
Parameters:
-----------
X : {array-like, sparse matrix} of shape (n_samples, n_features)
Training data.
dtype : data-type, default=None
Overrides the data type of coef. With dtype=None, coef will have the same
... | init_zero_coef | python | scikit-learn/scikit-learn | sklearn/linear_model/_linear_loss.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_linear_loss.py | BSD-3-Clause |
def weight_intercept(self, coef):
"""Helper function to get coefficients and intercept.
Parameters
----------
coef : ndarray of shape (n_dof,), (n_classes, n_dof) or (n_classes * n_dof,)
Coefficients of a linear model.
If shape (n_classes * n_dof,), the classes o... | Helper function to get coefficients and intercept.
Parameters
----------
coef : ndarray of shape (n_dof,), (n_classes, n_dof) or (n_classes * n_dof,)
Coefficients of a linear model.
If shape (n_classes * n_dof,), the classes of one feature are contiguous,
i.e... | weight_intercept | python | scikit-learn/scikit-learn | sklearn/linear_model/_linear_loss.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_linear_loss.py | BSD-3-Clause |
def weight_intercept_raw(self, coef, X):
"""Helper function to get coefficients, intercept and raw_prediction.
Parameters
----------
coef : ndarray of shape (n_dof,), (n_classes, n_dof) or (n_classes * n_dof,)
Coefficients of a linear model.
If shape (n_classes *... | Helper function to get coefficients, intercept and raw_prediction.
Parameters
----------
coef : ndarray of shape (n_dof,), (n_classes, n_dof) or (n_classes * n_dof,)
Coefficients of a linear model.
If shape (n_classes * n_dof,), the classes of one feature are contiguous,... | weight_intercept_raw | python | scikit-learn/scikit-learn | sklearn/linear_model/_linear_loss.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_linear_loss.py | BSD-3-Clause |
def loss(
self,
coef,
X,
y,
sample_weight=None,
l2_reg_strength=0.0,
n_threads=1,
raw_prediction=None,
):
"""Compute the loss as weighted average over point-wise losses.
Parameters
----------
coef : ndarray of shape (n_... | Compute the loss as weighted average over point-wise losses.
Parameters
----------
coef : ndarray of shape (n_dof,), (n_classes, n_dof) or (n_classes * n_dof,)
Coefficients of a linear model.
If shape (n_classes * n_dof,), the classes of one feature are contiguous,
... | loss | python | scikit-learn/scikit-learn | sklearn/linear_model/_linear_loss.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_linear_loss.py | BSD-3-Clause |
def loss_gradient(
self,
coef,
X,
y,
sample_weight=None,
l2_reg_strength=0.0,
n_threads=1,
raw_prediction=None,
):
"""Computes the sum of loss and gradient w.r.t. coef.
Parameters
----------
coef : ndarray of shape (n_d... | Computes the sum of loss and gradient w.r.t. coef.
Parameters
----------
coef : ndarray of shape (n_dof,), (n_classes, n_dof) or (n_classes * n_dof,)
Coefficients of a linear model.
If shape (n_classes * n_dof,), the classes of one feature are contiguous,
i.e... | loss_gradient | python | scikit-learn/scikit-learn | sklearn/linear_model/_linear_loss.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_linear_loss.py | BSD-3-Clause |
def gradient(
self,
coef,
X,
y,
sample_weight=None,
l2_reg_strength=0.0,
n_threads=1,
raw_prediction=None,
):
"""Computes the gradient w.r.t. coef.
Parameters
----------
coef : ndarray of shape (n_dof,), (n_classes, n_d... | Computes the gradient w.r.t. coef.
Parameters
----------
coef : ndarray of shape (n_dof,), (n_classes, n_dof) or (n_classes * n_dof,)
Coefficients of a linear model.
If shape (n_classes * n_dof,), the classes of one feature are contiguous,
i.e. one reconstruc... | gradient | python | scikit-learn/scikit-learn | sklearn/linear_model/_linear_loss.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_linear_loss.py | BSD-3-Clause |
def gradient_hessian(
self,
coef,
X,
y,
sample_weight=None,
l2_reg_strength=0.0,
n_threads=1,
gradient_out=None,
hessian_out=None,
raw_prediction=None,
):
"""Computes gradient and hessian w.r.t. coef.
Parameters
... | Computes gradient and hessian w.r.t. coef.
Parameters
----------
coef : ndarray of shape (n_dof,), (n_classes, n_dof) or (n_classes * n_dof,)
Coefficients of a linear model.
If shape (n_classes * n_dof,), the classes of one feature are contiguous,
i.e. one re... | gradient_hessian | python | scikit-learn/scikit-learn | sklearn/linear_model/_linear_loss.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_linear_loss.py | BSD-3-Clause |
def gradient_hessian_product(
self, coef, X, y, sample_weight=None, l2_reg_strength=0.0, n_threads=1
):
"""Computes gradient and hessp (hessian product function) w.r.t. coef.
Parameters
----------
coef : ndarray of shape (n_dof,), (n_classes, n_dof) or (n_classes * n_dof,)
... | Computes gradient and hessp (hessian product function) w.r.t. coef.
Parameters
----------
coef : ndarray of shape (n_dof,), (n_classes, n_dof) or (n_classes * n_dof,)
Coefficients of a linear model.
If shape (n_classes * n_dof,), the classes of one feature are contiguous... | gradient_hessian_product | python | scikit-learn/scikit-learn | sklearn/linear_model/_linear_loss.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_linear_loss.py | BSD-3-Clause |
def _check_multi_class(multi_class, solver, n_classes):
"""Computes the multi class type, either "multinomial" or "ovr".
For `n_classes` > 2 and a solver that supports it, returns "multinomial".
For all other cases, in particular binary classification, return "ovr".
"""
if multi_class == "auto":
... | Computes the multi class type, either "multinomial" or "ovr".
For `n_classes` > 2 and a solver that supports it, returns "multinomial".
For all other cases, in particular binary classification, return "ovr".
| _check_multi_class | python | scikit-learn/scikit-learn | sklearn/linear_model/_logistic.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_logistic.py | BSD-3-Clause |
def _logistic_regression_path(
X,
y,
pos_class=None,
Cs=10,
fit_intercept=True,
max_iter=100,
tol=1e-4,
verbose=0,
solver="lbfgs",
coef=None,
class_weight=None,
dual=False,
penalty="l2",
intercept_scaling=1.0,
multi_class="auto",
random_state=None,
che... | Compute a Logistic Regression model for a list of regularization
parameters.
This is an implementation that uses the result of the previous model
to speed up computations along the set of solutions, making it faster
than sequentially calling LogisticRegression for the different parameters.
Note tha... | _logistic_regression_path | python | scikit-learn/scikit-learn | sklearn/linear_model/_logistic.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_logistic.py | BSD-3-Clause |
def _log_reg_scoring_path(
X,
y,
train,
test,
*,
pos_class,
Cs,
scoring,
fit_intercept,
max_iter,
tol,
class_weight,
verbose,
solver,
penalty,
dual,
intercept_scaling,
multi_class,
random_state,
max_squared_sum,
sample_weight,
l1_ra... | Computes scores across logistic_regression_path
Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_features)
Training data.
y : array-like of shape (n_samples,) or (n_samples, n_targets)
Target labels.
train : list of indices
The indices of the tr... | _log_reg_scoring_path | python | scikit-learn/scikit-learn | sklearn/linear_model/_logistic.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_logistic.py | BSD-3-Clause |
def fit(self, X, y, sample_weight=None):
"""
Fit the model according to the given training data.
Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_features)
Training vector, where `n_samples` is the number of samples and
`n_feat... |
Fit the model according to the given training data.
Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_features)
Training vector, where `n_samples` is the number of samples and
`n_features` is the number of features.
y : array-... | fit | python | scikit-learn/scikit-learn | sklearn/linear_model/_logistic.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_logistic.py | BSD-3-Clause |
def predict_proba(self, X):
"""
Probability estimates.
The returned estimates for all classes are ordered by the
label of classes.
For a multi_class problem, if multi_class is set to be "multinomial"
the softmax function is used to find the predicted probability of
... |
Probability estimates.
The returned estimates for all classes are ordered by the
label of classes.
For a multi_class problem, if multi_class is set to be "multinomial"
the softmax function is used to find the predicted probability of
each class.
Else use a one-... | predict_proba | python | scikit-learn/scikit-learn | sklearn/linear_model/_logistic.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_logistic.py | BSD-3-Clause |
def fit(self, X, y, sample_weight=None, **params):
"""Fit the model according to the given training data.
Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_features)
Training vector, where `n_samples` is the number of samples and
`n_fea... | Fit the model according to the given training data.
Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_features)
Training vector, where `n_samples` is the number of samples and
`n_features` is the number of features.
y : array-like of s... | fit | python | scikit-learn/scikit-learn | sklearn/linear_model/_logistic.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_logistic.py | BSD-3-Clause |
def score(self, X, y, sample_weight=None, **score_params):
"""Score using the `scoring` option on the given test data and labels.
Parameters
----------
X : array-like of shape (n_samples, n_features)
Test samples.
y : array-like of shape (n_samples,)
Tru... | Score using the `scoring` option on the given test data and labels.
Parameters
----------
X : array-like of shape (n_samples, n_features)
Test samples.
y : array-like of shape (n_samples,)
True labels for X.
sample_weight : array-like of shape (n_sample... | score | python | scikit-learn/scikit-learn | sklearn/linear_model/_logistic.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_logistic.py | BSD-3-Clause |
def _cholesky_omp(X, y, n_nonzero_coefs, tol=None, copy_X=True, return_path=False):
"""Orthogonal Matching Pursuit step using the Cholesky decomposition.
Parameters
----------
X : ndarray of shape (n_samples, n_features)
Input dictionary. Columns are assumed to have unit norm.
y : ndarray ... | Orthogonal Matching Pursuit step using the Cholesky decomposition.
Parameters
----------
X : ndarray of shape (n_samples, n_features)
Input dictionary. Columns are assumed to have unit norm.
y : ndarray of shape (n_samples,)
Input targets.
n_nonzero_coefs : int
Targeted nu... | _cholesky_omp | python | scikit-learn/scikit-learn | sklearn/linear_model/_omp.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_omp.py | BSD-3-Clause |
def _gram_omp(
Gram,
Xy,
n_nonzero_coefs,
tol_0=None,
tol=None,
copy_Gram=True,
copy_Xy=True,
return_path=False,
):
"""Orthogonal Matching Pursuit step on a precomputed Gram matrix.
This function uses the Cholesky decomposition method.
Parameters
----------
Gram : n... | Orthogonal Matching Pursuit step on a precomputed Gram matrix.
This function uses the Cholesky decomposition method.
Parameters
----------
Gram : ndarray of shape (n_features, n_features)
Gram matrix of the input data matrix.
Xy : ndarray of shape (n_features,)
Input targets.
... | _gram_omp | python | scikit-learn/scikit-learn | sklearn/linear_model/_omp.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_omp.py | BSD-3-Clause |
def orthogonal_mp(
X,
y,
*,
n_nonzero_coefs=None,
tol=None,
precompute=False,
copy_X=True,
return_path=False,
return_n_iter=False,
):
r"""Orthogonal Matching Pursuit (OMP).
Solves n_targets Orthogonal Matching Pursuit problems.
An instance of the problem has the form:
... | Orthogonal Matching Pursuit (OMP).
Solves n_targets Orthogonal Matching Pursuit problems.
An instance of the problem has the form:
When parametrized by the number of non-zero coefficients using
`n_nonzero_coefs`:
argmin ||y - X\gamma||^2 subject to ||\gamma||_0 <= n_{nonzero coefs}
When param... | orthogonal_mp | python | scikit-learn/scikit-learn | sklearn/linear_model/_omp.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_omp.py | BSD-3-Clause |
def orthogonal_mp_gram(
Gram,
Xy,
*,
n_nonzero_coefs=None,
tol=None,
norms_squared=None,
copy_Gram=True,
copy_Xy=True,
return_path=False,
return_n_iter=False,
):
"""Gram Orthogonal Matching Pursuit (OMP).
Solves n_targets Orthogonal Matching Pursuit problems using only
... | Gram Orthogonal Matching Pursuit (OMP).
Solves n_targets Orthogonal Matching Pursuit problems using only
the Gram matrix X.T * X and the product X.T * y.
Read more in the :ref:`User Guide <omp>`.
Parameters
----------
Gram : array-like of shape (n_features, n_features)
Gram matrix of ... | orthogonal_mp_gram | python | scikit-learn/scikit-learn | sklearn/linear_model/_omp.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_omp.py | BSD-3-Clause |
def fit(self, X, y):
"""Fit the model using X, y as training data.
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. Will be cast to X's dtyp... | Fit the model using X, y as training data.
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. Will be cast to X's dtype if necessary.
Returns... | fit | python | scikit-learn/scikit-learn | sklearn/linear_model/_omp.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_omp.py | BSD-3-Clause |
def _omp_path_residues(
X_train,
y_train,
X_test,
y_test,
copy=True,
fit_intercept=True,
max_iter=100,
):
"""Compute the residues on left-out data for a full LARS path.
Parameters
----------
X_train : ndarray of shape (n_samples, n_features)
The data to fit the LARS ... | Compute the residues on left-out data for a full LARS path.
Parameters
----------
X_train : ndarray of shape (n_samples, n_features)
The data to fit the LARS on.
y_train : ndarray of shape (n_samples)
The target variable to fit LARS on.
X_test : ndarray of shape (n_samples, n_feat... | _omp_path_residues | python | scikit-learn/scikit-learn | sklearn/linear_model/_omp.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_omp.py | BSD-3-Clause |
def fit(self, X, y, **fit_params):
"""Fit the model using X, y as training data.
Parameters
----------
X : array-like of shape (n_samples, n_features)
Training data.
y : array-like of shape (n_samples,)
Target values. Will be cast to X's dtype if necessa... | Fit the model using X, y as training data.
Parameters
----------
X : array-like of shape (n_samples, n_features)
Training data.
y : array-like of shape (n_samples,)
Target values. Will be cast to X's dtype if necessary.
**fit_params : dict
P... | fit | python | scikit-learn/scikit-learn | sklearn/linear_model/_omp.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_omp.py | BSD-3-Clause |
def fit(self, X, y, coef_init=None, intercept_init=None):
"""Fit linear model with Passive Aggressive algorithm.
Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_features)
Training data.
y : array-like of shape (n_samples,)
Ta... | Fit linear model with Passive Aggressive algorithm.
Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_features)
Training data.
y : array-like of shape (n_samples,)
Target values.
coef_init : ndarray of shape (n_classes, n_feat... | fit | python | scikit-learn/scikit-learn | sklearn/linear_model/_passive_aggressive.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_passive_aggressive.py | BSD-3-Clause |
def partial_fit(self, X, y):
"""Fit linear model with Passive Aggressive algorithm.
Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_features)
Subset of training data.
y : numpy array of shape [n_samples]
Subset of target valu... | Fit linear model with Passive Aggressive algorithm.
Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_features)
Subset of training data.
y : numpy array of shape [n_samples]
Subset of target values.
Returns
-------
... | partial_fit | python | scikit-learn/scikit-learn | sklearn/linear_model/_passive_aggressive.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_passive_aggressive.py | BSD-3-Clause |
def fit(self, X, y, coef_init=None, intercept_init=None):
"""Fit linear model with Passive Aggressive algorithm.
Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_features)
Training data.
y : numpy array of shape [n_samples]
Ta... | Fit linear model with Passive Aggressive algorithm.
Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_features)
Training data.
y : numpy array of shape [n_samples]
Target values.
coef_init : array, shape = [n_features]
... | fit | python | scikit-learn/scikit-learn | sklearn/linear_model/_passive_aggressive.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_passive_aggressive.py | BSD-3-Clause |
def fit(self, X, y, sample_weight=None):
"""Fit the model according to the given training data.
Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_features)
Training data.
y : array-like of shape (n_samples,)
Target values.
... | Fit the model according to the given training data.
Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_features)
Training data.
y : array-like of shape (n_samples,)
Target values.
sample_weight : array-like of shape (n_samples,... | fit | python | scikit-learn/scikit-learn | sklearn/linear_model/_quantile.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_quantile.py | BSD-3-Clause |
def _dynamic_max_trials(n_inliers, n_samples, min_samples, probability):
"""Determine number trials such that at least one outlier-free subset is
sampled for the given inlier/outlier ratio.
Parameters
----------
n_inliers : int
Number of inliers in the data.
n_samples : int
Tot... | Determine number trials such that at least one outlier-free subset is
sampled for the given inlier/outlier ratio.
Parameters
----------
n_inliers : int
Number of inliers in the data.
n_samples : int
Total number of samples in the data.
min_samples : int
Minimum number ... | _dynamic_max_trials | python | scikit-learn/scikit-learn | sklearn/linear_model/_ransac.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_ransac.py | BSD-3-Clause |
def fit(self, X, y, sample_weight=None, **fit_params):
"""Fit estimator using RANSAC algorithm.
Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_features)
Training data.
y : array-like of shape (n_samples,) or (n_samples, n_targets)
... | Fit estimator using RANSAC algorithm.
Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_features)
Training data.
y : array-like of shape (n_samples,) or (n_samples, n_targets)
Target values.
sample_weight : array-like of shape... | fit | python | scikit-learn/scikit-learn | sklearn/linear_model/_ransac.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_ransac.py | BSD-3-Clause |
def predict(self, X, **params):
"""Predict using the estimated model.
This is a wrapper for `estimator_.predict(X)`.
Parameters
----------
X : {array-like or sparse matrix} of shape (n_samples, n_features)
Input data.
**params : dict
Parameters ... | Predict using the estimated model.
This is a wrapper for `estimator_.predict(X)`.
Parameters
----------
X : {array-like or sparse matrix} of shape (n_samples, n_features)
Input data.
**params : dict
Parameters routed to the `predict` method of the sub-e... | predict | python | scikit-learn/scikit-learn | sklearn/linear_model/_ransac.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_ransac.py | BSD-3-Clause |
def score(self, X, y, **params):
"""Return the score of the prediction.
This is a wrapper for `estimator_.score(X, y)`.
Parameters
----------
X : (array-like or sparse matrix} of shape (n_samples, n_features)
Training data.
y : array-like of shape (n_sample... | Return the score of the prediction.
This is a wrapper for `estimator_.score(X, y)`.
Parameters
----------
X : (array-like or sparse matrix} of shape (n_samples, n_features)
Training data.
y : array-like of shape (n_samples,) or (n_samples, n_targets)
Ta... | score | python | scikit-learn/scikit-learn | sklearn/linear_model/_ransac.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_ransac.py | BSD-3-Clause |
def _get_rescaled_operator(X, X_offset, sample_weight_sqrt):
"""Create LinearOperator for matrix products with implicit centering.
Matrix product `LinearOperator @ coef` returns `(X - X_offset) @ coef`.
"""
def matvec(b):
return X.dot(b) - sample_weight_sqrt * b.dot(X_offset)
def rmatvec(... | Create LinearOperator for matrix products with implicit centering.
Matrix product `LinearOperator @ coef` returns `(X - X_offset) @ coef`.
| _get_rescaled_operator | python | scikit-learn/scikit-learn | sklearn/linear_model/_ridge.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_ridge.py | BSD-3-Clause |
def _solve_lsqr(
X,
y,
*,
alpha,
fit_intercept=True,
max_iter=None,
tol=1e-4,
X_offset=None,
X_scale=None,
sample_weight_sqrt=None,
):
"""Solve Ridge regression via LSQR.
We expect that y is always mean centered.
If X is dense, we expect it to be mean centered such t... | Solve Ridge regression via LSQR.
We expect that y is always mean centered.
If X is dense, we expect it to be mean centered such that we can solve
||y - Xw||_2^2 + alpha * ||w||_2^2
If X is sparse, we expect X_offset to be given such that we can solve
||y - (X - X_offset)w||_2^2 + alpha * |... | _solve_lsqr | python | scikit-learn/scikit-learn | sklearn/linear_model/_ridge.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_ridge.py | BSD-3-Clause |
def _solve_lbfgs(
X,
y,
alpha,
positive=True,
max_iter=None,
tol=1e-4,
X_offset=None,
X_scale=None,
sample_weight_sqrt=None,
):
"""Solve ridge regression with LBFGS.
The main purpose is fitting with forcing coefficients to be positive.
For unconstrained ridge regression,... | Solve ridge regression with LBFGS.
The main purpose is fitting with forcing coefficients to be positive.
For unconstrained ridge regression, there are faster dedicated solver methods.
Note that with positive bounds on the coefficients, LBFGS seems faster
than scipy.optimize.lsq_linear.
| _solve_lbfgs | python | scikit-learn/scikit-learn | sklearn/linear_model/_ridge.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_ridge.py | BSD-3-Clause |
def ridge_regression(
X,
y,
alpha,
*,
sample_weight=None,
solver="auto",
max_iter=None,
tol=1e-4,
verbose=0,
positive=False,
random_state=None,
return_n_iter=False,
return_intercept=False,
check_input=True,
):
"""Solve the ridge equation by the method of norma... | Solve the ridge equation by the method of normal equations.
Read more in the :ref:`User Guide <ridge_regression>`.
Parameters
----------
X : {array-like, sparse matrix, LinearOperator} of shape (n_samples, n_features)
Training data.
y : array-like of shape (n_samples,) or (n_sampl... | ridge_regression | python | scikit-learn/scikit-learn | sklearn/linear_model/_ridge.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_ridge.py | BSD-3-Clause |
def fit(self, X, y, sample_weight=None):
"""Fit Ridge regression model.
Parameters
----------
X : {ndarray, sparse matrix} of shape (n_samples, n_features)
Training data.
y : ndarray of shape (n_samples,) or (n_samples, n_targets)
Target values.
... | Fit Ridge regression model.
Parameters
----------
X : {ndarray, sparse matrix} of shape (n_samples, n_features)
Training data.
y : ndarray of shape (n_samples,) or (n_samples, n_targets)
Target values.
sample_weight : float or ndarray of shape (n_sample... | fit | python | scikit-learn/scikit-learn | sklearn/linear_model/_ridge.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_ridge.py | BSD-3-Clause |
def _prepare_data(self, X, y, sample_weight, solver):
"""Validate `X` and `y` and binarize `y`.
Parameters
----------
X : {ndarray, sparse matrix} of shape (n_samples, n_features)
Training data.
y : ndarray of shape (n_samples,)
Target values.
s... | Validate `X` and `y` and binarize `y`.
Parameters
----------
X : {ndarray, sparse matrix} of shape (n_samples, n_features)
Training data.
y : ndarray of shape (n_samples,)
Target values.
sample_weight : float or ndarray of shape (n_samples,), default=No... | _prepare_data | python | scikit-learn/scikit-learn | sklearn/linear_model/_ridge.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_ridge.py | BSD-3-Clause |
def predict(self, X):
"""Predict class labels for samples in `X`.
Parameters
----------
X : {array-like, spare matrix} of shape (n_samples, n_features)
The data matrix for which we want to predict the targets.
Returns
-------
y_pred : ndarray of shap... | Predict class labels for samples in `X`.
Parameters
----------
X : {array-like, spare matrix} of shape (n_samples, n_features)
The data matrix for which we want to predict the targets.
Returns
-------
y_pred : ndarray of shape (n_samples,) or (n_samples, n_o... | predict | python | scikit-learn/scikit-learn | sklearn/linear_model/_ridge.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_ridge.py | BSD-3-Clause |
def fit(self, X, y, sample_weight=None):
"""Fit Ridge classifier model.
Parameters
----------
X : {ndarray, sparse matrix} of shape (n_samples, n_features)
Training data.
y : ndarray of shape (n_samples,)
Target values.
sample_weight : float or ... | Fit Ridge classifier model.
Parameters
----------
X : {ndarray, sparse matrix} of shape (n_samples, n_features)
Training data.
y : ndarray of shape (n_samples,)
Target values.
sample_weight : float or ndarray of shape (n_samples,), default=None
... | fit | python | scikit-learn/scikit-learn | sklearn/linear_model/_ridge.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_ridge.py | BSD-3-Clause |
def _find_smallest_angle(query, vectors):
"""Find the column of vectors that is most aligned with the query.
Both query and the columns of vectors must have their l2 norm equal to 1.
Parameters
----------
query : ndarray of shape (n_samples,)
Normalized query vector.
vectors : ndarray... | Find the column of vectors that is most aligned with the query.
Both query and the columns of vectors must have their l2 norm equal to 1.
Parameters
----------
query : ndarray of shape (n_samples,)
Normalized query vector.
vectors : ndarray of shape (n_samples, n_features)
Vectors... | _find_smallest_angle | python | scikit-learn/scikit-learn | sklearn/linear_model/_ridge.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_ridge.py | BSD-3-Clause |
def _compute_gram(self, X, sqrt_sw):
"""Computes the Gram matrix XX^T with possible centering.
Parameters
----------
X : {ndarray, sparse matrix} of shape (n_samples, n_features)
The preprocessed design matrix.
sqrt_sw : ndarray of shape (n_samples,)
squ... | Computes the Gram matrix XX^T with possible centering.
Parameters
----------
X : {ndarray, sparse matrix} of shape (n_samples, n_features)
The preprocessed design matrix.
sqrt_sw : ndarray of shape (n_samples,)
square roots of sample weights
Returns
... | _compute_gram | python | scikit-learn/scikit-learn | sklearn/linear_model/_ridge.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_ridge.py | BSD-3-Clause |
def _compute_covariance(self, X, sqrt_sw):
"""Computes covariance matrix X^TX with possible centering.
Parameters
----------
X : sparse matrix of shape (n_samples, n_features)
The preprocessed design matrix.
sqrt_sw : ndarray of shape (n_samples,)
square... | Computes covariance matrix X^TX with possible centering.
Parameters
----------
X : sparse matrix of shape (n_samples, n_features)
The preprocessed design matrix.
sqrt_sw : ndarray of shape (n_samples,)
square roots of sample weights
Returns
----... | _compute_covariance | python | scikit-learn/scikit-learn | sklearn/linear_model/_ridge.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_ridge.py | BSD-3-Clause |
def _sparse_multidot_diag(self, X, A, X_mean, sqrt_sw):
"""Compute the diagonal of (X - X_mean).dot(A).dot((X - X_mean).T)
without explicitly centering X nor computing X.dot(A)
when X is sparse.
Parameters
----------
X : sparse matrix of shape (n_samples, n_features)
... | Compute the diagonal of (X - X_mean).dot(A).dot((X - X_mean).T)
without explicitly centering X nor computing X.dot(A)
when X is sparse.
Parameters
----------
X : sparse matrix of shape (n_samples, n_features)
A : ndarray of shape (n_features, n_features)
X_mean... | _sparse_multidot_diag | python | scikit-learn/scikit-learn | sklearn/linear_model/_ridge.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_ridge.py | BSD-3-Clause |
def _solve_eigen_gram(self, alpha, y, sqrt_sw, X_mean, eigvals, Q, QT_y):
"""Compute dual coefficients and diagonal of G^-1.
Used when we have a decomposition of X.X^T (n_samples <= n_features).
"""
w = 1.0 / (eigvals + alpha)
if self.fit_intercept:
# the vector cont... | Compute dual coefficients and diagonal of G^-1.
Used when we have a decomposition of X.X^T (n_samples <= n_features).
| _solve_eigen_gram | python | scikit-learn/scikit-learn | sklearn/linear_model/_ridge.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_ridge.py | BSD-3-Clause |
def _eigen_decompose_covariance(self, X, y, sqrt_sw):
"""Eigendecomposition of X^T.X, used when n_samples > n_features
and X is sparse.
"""
n_samples, n_features = X.shape
cov = np.empty((n_features + 1, n_features + 1), dtype=X.dtype)
cov[:-1, :-1], X_mean = self._comput... | Eigendecomposition of X^T.X, used when n_samples > n_features
and X is sparse.
| _eigen_decompose_covariance | python | scikit-learn/scikit-learn | sklearn/linear_model/_ridge.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_ridge.py | BSD-3-Clause |
def _solve_eigen_covariance_no_intercept(
self, alpha, y, sqrt_sw, X_mean, eigvals, V, X
):
"""Compute dual coefficients and diagonal of G^-1.
Used when we have a decomposition of X^T.X
(n_samples > n_features and X is sparse), and not fitting an intercept.
"""
w = 1... | Compute dual coefficients and diagonal of G^-1.
Used when we have a decomposition of X^T.X
(n_samples > n_features and X is sparse), and not fitting an intercept.
| _solve_eigen_covariance_no_intercept | python | scikit-learn/scikit-learn | sklearn/linear_model/_ridge.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_ridge.py | BSD-3-Clause |
def _solve_eigen_covariance_intercept(
self, alpha, y, sqrt_sw, X_mean, eigvals, V, X
):
"""Compute dual coefficients and diagonal of G^-1.
Used when we have a decomposition of X^T.X
(n_samples > n_features and X is sparse),
and we are fitting an intercept.
"""
... | Compute dual coefficients and diagonal of G^-1.
Used when we have a decomposition of X^T.X
(n_samples > n_features and X is sparse),
and we are fitting an intercept.
| _solve_eigen_covariance_intercept | python | scikit-learn/scikit-learn | sklearn/linear_model/_ridge.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_ridge.py | BSD-3-Clause |
def _solve_eigen_covariance(self, alpha, y, sqrt_sw, X_mean, eigvals, V, X):
"""Compute dual coefficients and diagonal of G^-1.
Used when we have a decomposition of X^T.X
(n_samples > n_features and X is sparse).
"""
if self.fit_intercept:
return self._solve_eigen_co... | Compute dual coefficients and diagonal of G^-1.
Used when we have a decomposition of X^T.X
(n_samples > n_features and X is sparse).
| _solve_eigen_covariance | python | scikit-learn/scikit-learn | sklearn/linear_model/_ridge.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_ridge.py | BSD-3-Clause |
def _solve_svd_design_matrix(self, alpha, y, sqrt_sw, X_mean, singvals_sq, U, UT_y):
"""Compute dual coefficients and diagonal of G^-1.
Used when we have an SVD decomposition of X
(n_samples > n_features and X is dense).
"""
w = ((singvals_sq + alpha) ** -1) - (alpha**-1)
... | Compute dual coefficients and diagonal of G^-1.
Used when we have an SVD decomposition of X
(n_samples > n_features and X is dense).
| _solve_svd_design_matrix | python | scikit-learn/scikit-learn | sklearn/linear_model/_ridge.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_ridge.py | BSD-3-Clause |
def fit(self, X, y, sample_weight=None, score_params=None):
"""Fit Ridge regression model with gcv.
Parameters
----------
X : {ndarray, sparse matrix} of shape (n_samples, n_features)
Training data. Will be cast to float64 if necessary.
y : ndarray of shape (n_sampl... | Fit Ridge regression model with gcv.
Parameters
----------
X : {ndarray, sparse matrix} of shape (n_samples, n_features)
Training data. Will be cast to float64 if necessary.
y : ndarray of shape (n_samples,) or (n_samples, n_targets)
Target values. Will be cast ... | fit | python | scikit-learn/scikit-learn | sklearn/linear_model/_ridge.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_ridge.py | BSD-3-Clause |
def _score_without_scorer(self, squared_errors):
"""Performs scoring using squared errors when the scorer is None."""
if self.alpha_per_target:
_score = -squared_errors.mean(axis=0)
else:
_score = -squared_errors.mean()
return _score | Performs scoring using squared errors when the scorer is None. | _score_without_scorer | python | scikit-learn/scikit-learn | sklearn/linear_model/_ridge.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_ridge.py | BSD-3-Clause |
def _score(self, *, predictions, y, n_y, scorer, score_params):
"""Performs scoring with the specified scorer using the
predictions and the true y values.
"""
if self.is_clf:
identity_estimator = _IdentityClassifier(classes=np.arange(n_y))
_score = scorer(
... | Performs scoring with the specified scorer using the
predictions and the true y values.
| _score | python | scikit-learn/scikit-learn | sklearn/linear_model/_ridge.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_ridge.py | BSD-3-Clause |
def fit(self, X, y, sample_weight=None, **params):
"""Fit Ridge regression model with cv.
Parameters
----------
X : ndarray of shape (n_samples, n_features)
Training data. If using GCV, will be cast to float64
if necessary.
y : ndarray of shape (n_sample... | Fit Ridge regression model with cv.
Parameters
----------
X : ndarray of shape (n_samples, n_features)
Training data. If using GCV, will be cast to float64
if necessary.
y : ndarray of shape (n_samples,) or (n_samples, n_targets)
Target values. Will ... | fit | python | scikit-learn/scikit-learn | sklearn/linear_model/_ridge.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_ridge.py | BSD-3-Clause |
def fit(self, X, y, sample_weight=None, **params):
"""Fit Ridge classifier with cv.
Parameters
----------
X : ndarray of shape (n_samples, n_features)
Training vectors, where `n_samples` is the number of samples
and `n_features` is the number of features. When us... | Fit Ridge classifier with cv.
Parameters
----------
X : ndarray of shape (n_samples, n_features)
Training vectors, where `n_samples` is the number of samples
and `n_features` is the number of features. When using GCV,
will be cast to float64 if necessary.
... | fit | python | scikit-learn/scikit-learn | sklearn/linear_model/_ridge.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_ridge.py | BSD-3-Clause |
def get_auto_step_size(
max_squared_sum, alpha_scaled, loss, fit_intercept, n_samples=None, is_saga=False
):
"""Compute automatic step size for SAG solver.
The step size is set to 1 / (alpha_scaled + L + fit_intercept) where L is
the max sum of squares for over all samples.
Parameters
--------... | Compute automatic step size for SAG solver.
The step size is set to 1 / (alpha_scaled + L + fit_intercept) where L is
the max sum of squares for over all samples.
Parameters
----------
max_squared_sum : float
Maximum squared sum of X over samples.
alpha_scaled : float
Constant... | get_auto_step_size | python | scikit-learn/scikit-learn | sklearn/linear_model/_sag.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_sag.py | BSD-3-Clause |
def sag_solver(
X,
y,
sample_weight=None,
loss="log",
alpha=1.0,
beta=0.0,
max_iter=1000,
tol=0.001,
verbose=0,
random_state=None,
check_input=True,
max_squared_sum=None,
warm_start_mem=None,
is_saga=False,
):
"""SAG solver for Ridge and LogisticRegression.
... | SAG solver for Ridge and LogisticRegression.
SAG stands for Stochastic Average Gradient: the gradient of the loss is
estimated each sample at a time and the model is updated along the way with
a constant learning rate.
IMPORTANT NOTE: 'sag' solver converges faster on columns that are on the
same s... | sag_solver | python | scikit-learn/scikit-learn | sklearn/linear_model/_sag.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_sag.py | BSD-3-Clause |
def _get_loss_function(self, loss):
"""Get concrete ``LossFunction`` object for str ``loss``."""
loss_ = self.loss_functions[loss]
loss_class, args = loss_[0], loss_[1:]
if loss in ("huber", "epsilon_insensitive", "squared_epsilon_insensitive"):
args = (self.epsilon,)
... | Get concrete ``LossFunction`` object for str ``loss``. | _get_loss_function | python | scikit-learn/scikit-learn | sklearn/linear_model/_stochastic_gradient.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_stochastic_gradient.py | BSD-3-Clause |
def _allocate_parameter_mem(
self,
n_classes,
n_features,
input_dtype,
coef_init=None,
intercept_init=None,
one_class=0,
):
"""Allocate mem for parameters; initialize if provided."""
if n_classes > 2:
# allocate coef_ for multi-clas... | Allocate mem for parameters; initialize if provided. | _allocate_parameter_mem | python | scikit-learn/scikit-learn | sklearn/linear_model/_stochastic_gradient.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_stochastic_gradient.py | BSD-3-Clause |
def _make_validation_split(self, y, sample_mask):
"""Split the dataset between training set and validation set.
Parameters
----------
y : ndarray of shape (n_samples, )
Target values.
sample_mask : ndarray of shape (n_samples, )
A boolean array indicatin... | Split the dataset between training set and validation set.
Parameters
----------
y : ndarray of shape (n_samples, )
Target values.
sample_mask : ndarray of shape (n_samples, )
A boolean array indicating whether each sample should be included
for vali... | _make_validation_split | python | scikit-learn/scikit-learn | sklearn/linear_model/_stochastic_gradient.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_stochastic_gradient.py | BSD-3-Clause |
def fit_binary(
est,
i,
X,
y,
alpha,
C,
learning_rate,
max_iter,
pos_weight,
neg_weight,
sample_weight,
validation_mask=None,
random_state=None,
):
"""Fit a single binary classifier.
The i'th class is considered the "positive" class.
Parameters
-----... | Fit a single binary classifier.
The i'th class is considered the "positive" class.
Parameters
----------
est : Estimator object
The estimator to fit
i : int
Index of the positive class
X : numpy array or sparse matrix of shape [n_samples,n_features]
Training data
... | fit_binary | python | scikit-learn/scikit-learn | sklearn/linear_model/_stochastic_gradient.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_stochastic_gradient.py | BSD-3-Clause |
def _fit_multiclass(self, X, y, alpha, C, learning_rate, sample_weight, max_iter):
"""Fit a multi-class classifier by combining binary classifiers
Each binary classifier predicts one class versus all others. This
strategy is called OvA (One versus All) or OvR (One versus Rest).
"""
... | Fit a multi-class classifier by combining binary classifiers
Each binary classifier predicts one class versus all others. This
strategy is called OvA (One versus All) or OvR (One versus Rest).
| _fit_multiclass | python | scikit-learn/scikit-learn | sklearn/linear_model/_stochastic_gradient.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_stochastic_gradient.py | BSD-3-Clause |
def fit(self, X, y, coef_init=None, intercept_init=None, sample_weight=None):
"""Fit linear model with Stochastic Gradient Descent.
Parameters
----------
X : {array-like, sparse matrix}, shape (n_samples, n_features)
Training data.
y : ndarray of shape (n_samples,)
... | Fit linear model with Stochastic Gradient Descent.
Parameters
----------
X : {array-like, sparse matrix}, shape (n_samples, n_features)
Training data.
y : ndarray of shape (n_samples,)
Target values.
coef_init : ndarray of shape (n_classes, n_features),... | fit | python | scikit-learn/scikit-learn | sklearn/linear_model/_stochastic_gradient.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_stochastic_gradient.py | BSD-3-Clause |
def partial_fit(self, X, y, sample_weight=None):
"""Perform one epoch of stochastic gradient descent on given samples.
Internally, this method uses ``max_iter = 1``. Therefore, it is not
guaranteed that a minimum of the cost function is reached after calling
it once. Matters such as obj... | Perform one epoch of stochastic gradient descent on given samples.
Internally, this method uses ``max_iter = 1``. Therefore, it is not
guaranteed that a minimum of the cost function is reached after calling
it once. Matters such as objective convergence and early stopping
should be hand... | partial_fit | python | scikit-learn/scikit-learn | sklearn/linear_model/_stochastic_gradient.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_stochastic_gradient.py | BSD-3-Clause |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.