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 _plot_ice_lines( self, preds, feature_values, n_ice_to_plot, ax, pd_plot_idx, n_total_lines_by_plot, individual_line_kw, ): """Plot the ICE lines. Parameters ---------- preds : ndarray of shape \ (n_...
Plot the ICE lines. Parameters ---------- preds : ndarray of shape (n_instances, n_grid_points) The predictions computed for all points of `feature_values` for a given feature for all samples in `X`. feature_values : ndarray of shape (n_grid_point...
_plot_ice_lines
python
scikit-learn/scikit-learn
sklearn/inspection/_plot/partial_dependence.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/inspection/_plot/partial_dependence.py
BSD-3-Clause
def _plot_average_dependence( self, avg_preds, feature_values, ax, pd_line_idx, line_kw, categorical, bar_kw, ): """Plot the average partial dependence. Parameters ---------- avg_preds : ndarray of shape (n_grid_points,...
Plot the average partial dependence. Parameters ---------- avg_preds : ndarray of shape (n_grid_points,) The average predictions for all points of `feature_values` for a given feature for all samples in `X`. feature_values : ndarray of shape (n_grid_points,) ...
_plot_average_dependence
python
scikit-learn/scikit-learn
sklearn/inspection/_plot/partial_dependence.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/inspection/_plot/partial_dependence.py
BSD-3-Clause
def _plot_two_way_partial_dependence( self, avg_preds, feature_values, feature_idx, ax, pd_plot_idx, Z_level, contour_kw, categorical, heatmap_kw, ): """Plot 2-way partial dependence. Parameters ---------- ...
Plot 2-way partial dependence. Parameters ---------- avg_preds : ndarray of shape (n_instances, n_grid_points, n_grid_points) The average predictions for all points of `feature_values[0]` and `feature_values[1]` for some given features for all samples in ...
_plot_two_way_partial_dependence
python
scikit-learn/scikit-learn
sklearn/inspection/_plot/partial_dependence.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/inspection/_plot/partial_dependence.py
BSD-3-Clause
def test_input_data_dimension(pyplot): """Check that we raise an error when `X` does not have exactly 2 features.""" X, y = make_classification(n_samples=10, n_features=4, random_state=0) clf = LogisticRegression().fit(X, y) msg = "n_features must be equal to 2. Got 4 instead." with pytest.raises(V...
Check that we raise an error when `X` does not have exactly 2 features.
test_input_data_dimension
python
scikit-learn/scikit-learn
sklearn/inspection/_plot/tests/test_boundary_decision_display.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/inspection/_plot/tests/test_boundary_decision_display.py
BSD-3-Clause
def test_check_boundary_response_method_error(): """Check error raised for multi-output multi-class classifiers by `_check_boundary_response_method`. """ class MultiLabelClassifier: classes_ = [np.array([0, 1]), np.array([0, 1])] err_msg = "Multi-label and multi-output multi-class classifi...
Check error raised for multi-output multi-class classifiers by `_check_boundary_response_method`.
test_check_boundary_response_method_error
python
scikit-learn/scikit-learn
sklearn/inspection/_plot/tests/test_boundary_decision_display.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/inspection/_plot/tests/test_boundary_decision_display.py
BSD-3-Clause
def test_check_boundary_response_method( estimator, response_method, class_of_interest, expected_prediction_method ): """Check the behaviour of `_check_boundary_response_method` for the supported cases. """ prediction_method = _check_boundary_response_method( estimator, response_method, clas...
Check the behaviour of `_check_boundary_response_method` for the supported cases.
test_check_boundary_response_method
python
scikit-learn/scikit-learn
sklearn/inspection/_plot/tests/test_boundary_decision_display.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/inspection/_plot/tests/test_boundary_decision_display.py
BSD-3-Clause
def test_multiclass_predict(pyplot): """Check multiclass `response=predict` gives expected results.""" grid_resolution = 10 eps = 1.0 X, y = make_classification(n_classes=3, n_informative=3, random_state=0) X = X[:, [0, 1]] lr = LogisticRegression(random_state=0).fit(X, y) disp = DecisionBo...
Check multiclass `response=predict` gives expected results.
test_multiclass_predict
python
scikit-learn/scikit-learn
sklearn/inspection/_plot/tests/test_boundary_decision_display.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/inspection/_plot/tests/test_boundary_decision_display.py
BSD-3-Clause
def test_decision_boundary_display_classifier( pyplot, fitted_clf, response_method, plot_method ): """Check that decision boundary is correct.""" fig, ax = pyplot.subplots() eps = 2.0 disp = DecisionBoundaryDisplay.from_estimator( fitted_clf, X, grid_resolution=5, res...
Check that decision boundary is correct.
test_decision_boundary_display_classifier
python
scikit-learn/scikit-learn
sklearn/inspection/_plot/tests/test_boundary_decision_display.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/inspection/_plot/tests/test_boundary_decision_display.py
BSD-3-Clause
def test_decision_boundary_display_outlier_detector( pyplot, response_method, plot_method ): """Check that decision boundary is correct for outlier detector.""" fig, ax = pyplot.subplots() eps = 2.0 outlier_detector = IsolationForest(random_state=0).fit(X, y) disp = DecisionBoundaryDisplay.from_...
Check that decision boundary is correct for outlier detector.
test_decision_boundary_display_outlier_detector
python
scikit-learn/scikit-learn
sklearn/inspection/_plot/tests/test_boundary_decision_display.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/inspection/_plot/tests/test_boundary_decision_display.py
BSD-3-Clause
def test_decision_boundary_display_regressor(pyplot, response_method, plot_method): """Check that we can display the decision boundary for a regressor.""" X, y = load_diabetes(return_X_y=True) X = X[:, :2] tree = DecisionTreeRegressor().fit(X, y) fig, ax = pyplot.subplots() eps = 2.0 disp = ...
Check that we can display the decision boundary for a regressor.
test_decision_boundary_display_regressor
python
scikit-learn/scikit-learn
sklearn/inspection/_plot/tests/test_boundary_decision_display.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/inspection/_plot/tests/test_boundary_decision_display.py
BSD-3-Clause
def test_multilabel_classifier_error(pyplot, response_method): """Check that multilabel classifier raises correct error.""" X, y = make_multilabel_classification(random_state=0) X = X[:, :2] tree = DecisionTreeClassifier().fit(X, y) msg = "Multi-label and multi-output multi-class classifiers are no...
Check that multilabel classifier raises correct error.
test_multilabel_classifier_error
python
scikit-learn/scikit-learn
sklearn/inspection/_plot/tests/test_boundary_decision_display.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/inspection/_plot/tests/test_boundary_decision_display.py
BSD-3-Clause
def test_multi_output_multi_class_classifier_error(pyplot, response_method): """Check that multi-output multi-class classifier raises correct error.""" X = np.asarray([[0, 1], [1, 2]]) y = np.asarray([["tree", "cat"], ["cat", "tree"]]) tree = DecisionTreeClassifier().fit(X, y) msg = "Multi-label an...
Check that multi-output multi-class classifier raises correct error.
test_multi_output_multi_class_classifier_error
python
scikit-learn/scikit-learn
sklearn/inspection/_plot/tests/test_boundary_decision_display.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/inspection/_plot/tests/test_boundary_decision_display.py
BSD-3-Clause
def test_multioutput_regressor_error(pyplot): """Check that multioutput regressor raises correct error.""" X = np.asarray([[0, 1], [1, 2]]) y = np.asarray([[0, 1], [4, 1]]) tree = DecisionTreeRegressor().fit(X, y) with pytest.raises(ValueError, match="Multi-output regressors are not supported"): ...
Check that multioutput regressor raises correct error.
test_multioutput_regressor_error
python
scikit-learn/scikit-learn
sklearn/inspection/_plot/tests/test_boundary_decision_display.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/inspection/_plot/tests/test_boundary_decision_display.py
BSD-3-Clause
def test_regressor_unsupported_response(pyplot, response_method): """Check that we can display the decision boundary for a regressor.""" X, y = load_diabetes(return_X_y=True) X = X[:, :2] tree = DecisionTreeRegressor().fit(X, y) err_msg = "should either be a classifier to be used with response_metho...
Check that we can display the decision boundary for a regressor.
test_regressor_unsupported_response
python
scikit-learn/scikit-learn
sklearn/inspection/_plot/tests/test_boundary_decision_display.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/inspection/_plot/tests/test_boundary_decision_display.py
BSD-3-Clause
def test_dataframe_labels_used(pyplot, fitted_clf): """Check that column names are used for pandas.""" pd = pytest.importorskip("pandas") df = pd.DataFrame(X, columns=["col_x", "col_y"]) # pandas column names are used by default _, ax = pyplot.subplots() disp = DecisionBoundaryDisplay.from_esti...
Check that column names are used for pandas.
test_dataframe_labels_used
python
scikit-learn/scikit-learn
sklearn/inspection/_plot/tests/test_boundary_decision_display.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/inspection/_plot/tests/test_boundary_decision_display.py
BSD-3-Clause
def test_string_target(pyplot): """Check that decision boundary works with classifiers trained on string labels.""" iris = load_iris() X = iris.data[:, [0, 1]] # Use strings as target y = iris.target_names[iris.target] log_reg = LogisticRegression().fit(X, y) # Does not raise DecisionB...
Check that decision boundary works with classifiers trained on string labels.
test_string_target
python
scikit-learn/scikit-learn
sklearn/inspection/_plot/tests/test_boundary_decision_display.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/inspection/_plot/tests/test_boundary_decision_display.py
BSD-3-Clause
def test_dataframe_support(pyplot, constructor_name): """Check that passing a dataframe at fit and to the Display does not raise warnings. Non-regression test for: * https://github.com/scikit-learn/scikit-learn/issues/23311 * https://github.com/scikit-learn/scikit-learn/issues/28717 """ df ...
Check that passing a dataframe at fit and to the Display does not raise warnings. Non-regression test for: * https://github.com/scikit-learn/scikit-learn/issues/23311 * https://github.com/scikit-learn/scikit-learn/issues/28717
test_dataframe_support
python
scikit-learn/scikit-learn
sklearn/inspection/_plot/tests/test_boundary_decision_display.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/inspection/_plot/tests/test_boundary_decision_display.py
BSD-3-Clause
def test_class_of_interest_binary(pyplot, response_method): """Check the behaviour of passing `class_of_interest` for plotting the output of `predict_proba` and `decision_function` in the binary case. """ iris = load_iris() X = iris.data[:100, :2] y = iris.target[:100] assert_array_equal(np....
Check the behaviour of passing `class_of_interest` for plotting the output of `predict_proba` and `decision_function` in the binary case.
test_class_of_interest_binary
python
scikit-learn/scikit-learn
sklearn/inspection/_plot/tests/test_boundary_decision_display.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/inspection/_plot/tests/test_boundary_decision_display.py
BSD-3-Clause
def test_class_of_interest_multiclass(pyplot, response_method): """Check the behaviour of passing `class_of_interest` for plotting the output of `predict_proba` and `decision_function` in the multiclass case. """ iris = load_iris() X = iris.data[:, :2] y = iris.target # the target are numerical...
Check the behaviour of passing `class_of_interest` for plotting the output of `predict_proba` and `decision_function` in the multiclass case.
test_class_of_interest_multiclass
python
scikit-learn/scikit-learn
sklearn/inspection/_plot/tests/test_boundary_decision_display.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/inspection/_plot/tests/test_boundary_decision_display.py
BSD-3-Clause
def test_multiclass_plot_max_class(pyplot, response_method): """Check plot correct when plotting max multiclass class.""" import matplotlib as mpl # In matplotlib < v3.5, default value of `pcolormesh(shading)` is 'flat', which # results in the last row and column being dropped. Thus older versions prod...
Check plot correct when plotting max multiclass class.
test_multiclass_plot_max_class
python
scikit-learn/scikit-learn
sklearn/inspection/_plot/tests/test_boundary_decision_display.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/inspection/_plot/tests/test_boundary_decision_display.py
BSD-3-Clause
def test_multiclass_colors_cmap(pyplot, plot_method, multiclass_colors): """Check correct cmap used for all `multiclass_colors` inputs.""" import matplotlib as mpl if parse_version(mpl.__version__) < parse_version("3.5"): pytest.skip( "Matplotlib >= 3.5 is needed for `==` to check equiv...
Check correct cmap used for all `multiclass_colors` inputs.
test_multiclass_colors_cmap
python
scikit-learn/scikit-learn
sklearn/inspection/_plot/tests/test_boundary_decision_display.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/inspection/_plot/tests/test_boundary_decision_display.py
BSD-3-Clause
def test_multiclass_plot_max_class_cmap_kwarg(pyplot): """Check `cmap` kwarg ignored when using plotting max multiclass class.""" X, y = load_iris_2d_scaled() clf = LogisticRegression().fit(X, y) msg = ( "Plotting max class of multiclass 'decision_function' or 'predict_proba', " "thus '...
Check `cmap` kwarg ignored when using plotting max multiclass class.
test_multiclass_plot_max_class_cmap_kwarg
python
scikit-learn/scikit-learn
sklearn/inspection/_plot/tests/test_boundary_decision_display.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/inspection/_plot/tests/test_boundary_decision_display.py
BSD-3-Clause
def test_subclass_named_constructors_return_type_is_subclass(pyplot): """Check that named constructors return the correct type when subclassed. Non-regression test for: https://github.com/scikit-learn/scikit-learn/pull/27675 """ clf = LogisticRegression().fit(X, y) class SubclassOfDisplay(Deci...
Check that named constructors return the correct type when subclassed. Non-regression test for: https://github.com/scikit-learn/scikit-learn/pull/27675
test_subclass_named_constructors_return_type_is_subclass
python
scikit-learn/scikit-learn
sklearn/inspection/_plot/tests/test_boundary_decision_display.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/inspection/_plot/tests/test_boundary_decision_display.py
BSD-3-Clause
def test_partial_dependence_overwrite_labels( pyplot, clf_diabetes, diabetes, kind, line_kw, label, ): """Test that make sure that we can overwrite the label of the PDP plot""" disp = PartialDependenceDisplay.from_estimator( clf_diabetes, diabetes.data, [0, 2], ...
Test that make sure that we can overwrite the label of the PDP plot
test_partial_dependence_overwrite_labels
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_grid_resolution_with_categorical(pyplot, categorical_features, array_type): """Check that we raise a ValueError when the grid_resolution is too small respect to the number of categories in the categorical features targeted. """ X = [["A", 1, "A"], ["B", 0, "C"], ["C", 2, "B"]] column_name =...
Check that we raise a ValueError when the grid_resolution is too small respect to the number of categories in the categorical features targeted.
test_grid_resolution_with_categorical
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_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 test_subclass_named_constructors_return_type_is_subclass( pyplot, diabetes, clf_diabetes ): """Check that named constructors return the correct type when subclassed. Non-regression test for: https://github.com/scikit-learn/scikit-learn/pull/27675 """ class SubclassOfDisplay(PartialDependen...
Check that named constructors return the correct type when subclassed. Non-regression test for: https://github.com/scikit-learn/scikit-learn/pull/27675
test_subclass_named_constructors_return_type_is_subclass
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 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 _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 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/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 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/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 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/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 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/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_metadata_routing(self): """Get metadata routing of this object. Please check :ref:`User Guide <metadata_routing>` on how the routing mechanism works. .. versionadded:: 1.5 Returns ------- routing : MetadataRouter A :class:`~sklearn.utils.met...
Get metadata routing of this object. Please check :ref:`User Guide <metadata_routing>` on how the routing mechanism works. .. versionadded:: 1.5 Returns ------- routing : MetadataRouter A :class:`~sklearn.utils.metadata_routing.MetadataRouter` encapsulating...
get_metadata_routing
python
scikit-learn/scikit-learn
sklearn/linear_model/_ransac.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/_ransac.py
BSD-3-Clause