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_precision_recall_chance_level_line( pyplot, chance_level_kw, constructor_name, ): """Check the chance level line plotting behavior.""" X, y = make_classification(n_classes=2, n_samples=50, random_state=0) pos_prevalence = Counter(y)[1] / len(y) lr = LogisticRegression() y_pred ...
Check the chance level line plotting behavior.
test_precision_recall_chance_level_line
python
scikit-learn/scikit-learn
sklearn/metrics/_plot/tests/test_precision_recall_display.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/metrics/_plot/tests/test_precision_recall_display.py
BSD-3-Clause
def test_precision_recall_display_name(pyplot, constructor_name, default_label): """Check the behaviour of the name parameters""" X, y = make_classification(n_classes=2, n_samples=100, random_state=0) pos_label = 1 classifier = LogisticRegression().fit(X, y) classifier.fit(X, y) y_pred = class...
Check the behaviour of the name parameters
test_precision_recall_display_name
python
scikit-learn/scikit-learn
sklearn/metrics/_plot/tests/test_precision_recall_display.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/metrics/_plot/tests/test_precision_recall_display.py
BSD-3-Clause
def test_default_labels(pyplot, average_precision, estimator_name, expected_label): """Check the default labels used in the display.""" precision = np.array([1, 0.5, 0]) recall = np.array([0, 0.5, 1]) display = PrecisionRecallDisplay( precision, recall, average_precision=average_...
Check the default labels used in the display.
test_default_labels
python
scikit-learn/scikit-learn
sklearn/metrics/_plot/tests/test_precision_recall_display.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/metrics/_plot/tests/test_precision_recall_display.py
BSD-3-Clause
def test_prediction_error_display_raise_error( pyplot, class_method, regressor, params, err_type, err_msg ): """Check that we raise the proper error when making the parameters # validation.""" with pytest.raises(err_type, match=err_msg): if class_method == "from_estimator": Predictio...
Check that we raise the proper error when making the parameters # validation.
test_prediction_error_display_raise_error
python
scikit-learn/scikit-learn
sklearn/metrics/_plot/tests/test_predict_error_display.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/metrics/_plot/tests/test_predict_error_display.py
BSD-3-Clause
def test_from_estimator_not_fitted(pyplot): """Check that we raise a `NotFittedError` when the passed regressor is not fit.""" regressor = Ridge() with pytest.raises(NotFittedError, match="is not fitted yet."): PredictionErrorDisplay.from_estimator(regressor, X, y)
Check that we raise a `NotFittedError` when the passed regressor is not fit.
test_from_estimator_not_fitted
python
scikit-learn/scikit-learn
sklearn/metrics/_plot/tests/test_predict_error_display.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/metrics/_plot/tests/test_predict_error_display.py
BSD-3-Clause
def test_prediction_error_display(pyplot, regressor_fitted, class_method, kind): """Check the default behaviour of the display.""" if class_method == "from_estimator": display = PredictionErrorDisplay.from_estimator( regressor_fitted, X, y, kind=kind ) else: y_pred = regr...
Check the default behaviour of the display.
test_prediction_error_display
python
scikit-learn/scikit-learn
sklearn/metrics/_plot/tests/test_predict_error_display.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/metrics/_plot/tests/test_predict_error_display.py
BSD-3-Clause
def test_plot_prediction_error_ax(pyplot, regressor_fitted, class_method): """Check that we can pass an axis to the display.""" _, ax = pyplot.subplots() if class_method == "from_estimator": display = PredictionErrorDisplay.from_estimator(regressor_fitted, X, y, ax=ax) else: y_pred = reg...
Check that we can pass an axis to the display.
test_plot_prediction_error_ax
python
scikit-learn/scikit-learn
sklearn/metrics/_plot/tests/test_predict_error_display.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/metrics/_plot/tests/test_predict_error_display.py
BSD-3-Clause
def test_prediction_error_custom_artist( pyplot, regressor_fitted, class_method, scatter_kwargs, line_kwargs ): """Check that we can tune the style of the line and the scatter.""" extra_params = { "kind": "actual_vs_predicted", "scatter_kwargs": scatter_kwargs, "line_kwargs": line_kw...
Check that we can tune the style of the line and the scatter.
test_prediction_error_custom_artist
python
scikit-learn/scikit-learn
sklearn/metrics/_plot/tests/test_predict_error_display.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/metrics/_plot/tests/test_predict_error_display.py
BSD-3-Clause
def _check_figure_axes_and_labels(display, pos_label): """Check mpl axes and figure defaults are correct.""" import matplotlib as mpl assert isinstance(display.ax_, mpl.axes.Axes) assert isinstance(display.figure_, mpl.figure.Figure) assert display.ax_.get_adjustable() == "box" assert display.a...
Check mpl axes and figure defaults are correct.
_check_figure_axes_and_labels
python
scikit-learn/scikit-learn
sklearn/metrics/_plot/tests/test_roc_curve_display.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/metrics/_plot/tests/test_roc_curve_display.py
BSD-3-Clause
def test_roc_curve_display_plotting( pyplot, response_method, data_binary, with_sample_weight, drop_intermediate, with_strings, constructor_name, default_name, ): """Check the overall plotting behaviour for single curve.""" X, y = data_binary pos_label = None if with_str...
Check the overall plotting behaviour for single curve.
test_roc_curve_display_plotting
python
scikit-learn/scikit-learn
sklearn/metrics/_plot/tests/test_roc_curve_display.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/metrics/_plot/tests/test_roc_curve_display.py
BSD-3-Clause
def test_roc_curve_plot_parameter_length_validation(pyplot, params, err_msg): """Check `plot` parameter length validation performed correctly.""" display = RocCurveDisplay(**params) if err_msg: with pytest.raises(ValueError, match=err_msg): display.plot() else: # No error sho...
Check `plot` parameter length validation performed correctly.
test_roc_curve_plot_parameter_length_validation
python
scikit-learn/scikit-learn
sklearn/metrics/_plot/tests/test_roc_curve_display.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/metrics/_plot/tests/test_roc_curve_display.py
BSD-3-Clause
def test_roc_curve_display_kwargs_deprecation(pyplot, data_binary, constructor_name): """Check **kwargs deprecated correctly in favour of `curve_kwargs`.""" X, y = data_binary lr = LogisticRegression() lr.fit(X, y) fpr = np.array([0, 0.5, 1]) tpr = np.array([0, 0.5, 1]) # Error when both `c...
Check **kwargs deprecated correctly in favour of `curve_kwargs`.
test_roc_curve_display_kwargs_deprecation
python
scikit-learn/scikit-learn
sklearn/metrics/_plot/tests/test_roc_curve_display.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/metrics/_plot/tests/test_roc_curve_display.py
BSD-3-Clause
def test_roc_curve_plot_legend_label(pyplot, data_binary, name, curve_kwargs, roc_auc): """Check legend label correct with all `curve_kwargs`, `name` combinations.""" fpr = [np.array([0, 0.5, 1]), np.array([0, 0.5, 1]), np.array([0, 0.5, 1])] tpr = [np.array([0, 0.5, 1]), np.array([0, 0.5, 1]), np.array([0,...
Check legend label correct with all `curve_kwargs`, `name` combinations.
test_roc_curve_plot_legend_label
python
scikit-learn/scikit-learn
sklearn/metrics/_plot/tests/test_roc_curve_display.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/metrics/_plot/tests/test_roc_curve_display.py
BSD-3-Clause
def test_roc_curve_from_cv_results_curve_kwargs(pyplot, data_binary, curve_kwargs): """Check line kwargs passed correctly in `from_cv_results`.""" X, y = data_binary cv_results = cross_validate( LogisticRegression(), X, y, cv=3, return_estimator=True, return_indices=True ) display = RocCurv...
Check line kwargs passed correctly in `from_cv_results`.
test_roc_curve_from_cv_results_curve_kwargs
python
scikit-learn/scikit-learn
sklearn/metrics/_plot/tests/test_roc_curve_display.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/metrics/_plot/tests/test_roc_curve_display.py
BSD-3-Clause
def _check_chance_level(plot_chance_level, chance_level_kw, display): """Check chance level line and line styles correct.""" import matplotlib as mpl if plot_chance_level: assert isinstance(display.chance_level_, mpl.lines.Line2D) assert tuple(display.chance_level_.get_xdata()) == (0, 1) ...
Check chance level line and line styles correct.
_check_chance_level
python
scikit-learn/scikit-learn
sklearn/metrics/_plot/tests/test_roc_curve_display.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/metrics/_plot/tests/test_roc_curve_display.py
BSD-3-Clause
def test_roc_curve_chance_level_line( pyplot, data_binary, plot_chance_level, chance_level_kw, label, constructor_name, ): """Check chance level plotting behavior of `from_predictions`, `from_estimator`.""" X, y = data_binary lr = LogisticRegression() lr.fit(X, y) y_score =...
Check chance level plotting behavior of `from_predictions`, `from_estimator`.
test_roc_curve_chance_level_line
python
scikit-learn/scikit-learn
sklearn/metrics/_plot/tests/test_roc_curve_display.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/metrics/_plot/tests/test_roc_curve_display.py
BSD-3-Clause
def test_roc_curve_chance_level_line_from_cv_results( pyplot, data_binary, plot_chance_level, chance_level_kw, curve_kwargs, ): """Check chance level plotting behavior with `from_cv_results`.""" X, y = data_binary n_cv = 3 cv_results = cross_validate( LogisticRegression(), X,...
Check chance level plotting behavior with `from_cv_results`.
test_roc_curve_chance_level_line_from_cv_results
python
scikit-learn/scikit-learn
sklearn/metrics/_plot/tests/test_roc_curve_display.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/metrics/_plot/tests/test_roc_curve_display.py
BSD-3-Clause
def test_roc_curve_display_complex_pipeline(pyplot, data_binary, clf, constructor_name): """Check the behaviour with complex pipeline.""" X, y = data_binary clf = clone(clf) if constructor_name == "from_estimator": with pytest.raises(NotFittedError): RocCurveDisplay.from_estimator(...
Check the behaviour with complex pipeline.
test_roc_curve_display_complex_pipeline
python
scikit-learn/scikit-learn
sklearn/metrics/_plot/tests/test_roc_curve_display.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/metrics/_plot/tests/test_roc_curve_display.py
BSD-3-Clause
def test_y_score_and_y_pred_specified_error(): """Check that an error is raised when both y_score and y_pred are specified.""" y_true = np.array([0, 1, 1, 0]) y_score = np.array([0.1, 0.4, 0.35, 0.8]) y_pred = np.array([0.2, 0.3, 0.5, 0.1]) with pytest.raises( ValueError, match="`y_pred` an...
Check that an error is raised when both y_score and y_pred are specified.
test_y_score_and_y_pred_specified_error
python
scikit-learn/scikit-learn
sklearn/metrics/_plot/tests/test_roc_curve_display.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/metrics/_plot/tests/test_roc_curve_display.py
BSD-3-Clause
def test_y_pred_deprecation_warning(pyplot): """Check that a warning is raised when y_pred is specified.""" y_true = np.array([0, 1, 1, 0]) y_score = np.array([0.1, 0.4, 0.35, 0.8]) with pytest.warns(FutureWarning, match="y_pred is deprecated in 1.7"): display_y_pred = RocCurveDisplay.from_pred...
Check that a warning is raised when y_pred is specified.
test_y_pred_deprecation_warning
python
scikit-learn/scikit-learn
sklearn/metrics/_plot/tests/test_roc_curve_display.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/metrics/_plot/tests/test_roc_curve_display.py
BSD-3-Clause
def _check_shape(param, param_shape, name): """Validate the shape of the input parameter 'param'. Parameters ---------- param : array param_shape : tuple name : str """ param = np.array(param) if param.shape != param_shape: raise ValueError( "The parameter '%s'...
Validate the shape of the input parameter 'param'. Parameters ---------- param : array param_shape : tuple name : str
_check_shape
python
scikit-learn/scikit-learn
sklearn/mixture/_base.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/mixture/_base.py
BSD-3-Clause
def _initialize_parameters(self, X, random_state): """Initialize the model parameters. Parameters ---------- X : array-like of shape (n_samples, n_features) random_state : RandomState A random number generator instance that controls the random seed used...
Initialize the model parameters. Parameters ---------- X : array-like of shape (n_samples, n_features) random_state : RandomState A random number generator instance that controls the random seed used for the method chosen to initialize the parameters.
_initialize_parameters
python
scikit-learn/scikit-learn
sklearn/mixture/_base.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/mixture/_base.py
BSD-3-Clause
def fit(self, X, y=None): """Estimate model parameters with the EM algorithm. The method fits the model ``n_init`` times and sets the parameters with which the model has the largest likelihood or lower bound. Within each trial, the method iterates between E-step and M-step for ``max_ite...
Estimate model parameters with the EM algorithm. The method fits the model ``n_init`` times and sets the parameters with which the model has the largest likelihood or lower bound. Within each trial, the method iterates between E-step and M-step for ``max_iter`` times until the change of...
fit
python
scikit-learn/scikit-learn
sklearn/mixture/_base.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/mixture/_base.py
BSD-3-Clause
def fit_predict(self, X, y=None): """Estimate model parameters using X and predict the labels for X. The method fits the model n_init times and sets the parameters with which the model has the largest likelihood or lower bound. Within each trial, the method iterates between E-step and M...
Estimate model parameters using X and predict the labels for X. The method fits the model n_init times and sets the parameters with which the model has the largest likelihood or lower bound. Within each trial, the method iterates between E-step and M-step for `max_iter` times until the ...
fit_predict
python
scikit-learn/scikit-learn
sklearn/mixture/_base.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/mixture/_base.py
BSD-3-Clause
def _e_step(self, X): """E step. Parameters ---------- X : array-like of shape (n_samples, n_features) Returns ------- log_prob_norm : float Mean of the logarithms of the probabilities of each sample in X log_responsibility : array, shape (n...
E step. Parameters ---------- X : array-like of shape (n_samples, n_features) Returns ------- log_prob_norm : float Mean of the logarithms of the probabilities of each sample in X log_responsibility : array, shape (n_samples, n_components) ...
_e_step
python
scikit-learn/scikit-learn
sklearn/mixture/_base.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/mixture/_base.py
BSD-3-Clause
def score_samples(self, X): """Compute the log-likelihood of each sample. Parameters ---------- X : array-like of shape (n_samples, n_features) List of n_features-dimensional data points. Each row corresponds to a single data point. Returns -----...
Compute the log-likelihood of each sample. Parameters ---------- X : array-like of shape (n_samples, n_features) List of n_features-dimensional data points. Each row corresponds to a single data point. Returns ------- log_prob : array, shape (n_s...
score_samples
python
scikit-learn/scikit-learn
sklearn/mixture/_base.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/mixture/_base.py
BSD-3-Clause
def predict(self, X): """Predict the labels for the data samples in X using trained model. Parameters ---------- X : array-like of shape (n_samples, n_features) List of n_features-dimensional data points. Each row corresponds to a single data point. Retu...
Predict the labels for the data samples in X using trained model. Parameters ---------- X : array-like of shape (n_samples, n_features) List of n_features-dimensional data points. Each row corresponds to a single data point. Returns ------- label...
predict
python
scikit-learn/scikit-learn
sklearn/mixture/_base.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/mixture/_base.py
BSD-3-Clause
def predict_proba(self, X): """Evaluate the components' density for each sample. Parameters ---------- X : array-like of shape (n_samples, n_features) List of n_features-dimensional data points. Each row corresponds to a single data point. Returns ...
Evaluate the components' density for each sample. Parameters ---------- X : array-like of shape (n_samples, n_features) List of n_features-dimensional data points. Each row corresponds to a single data point. Returns ------- resp : array, shape (...
predict_proba
python
scikit-learn/scikit-learn
sklearn/mixture/_base.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/mixture/_base.py
BSD-3-Clause
def sample(self, n_samples=1): """Generate random samples from the fitted Gaussian distribution. Parameters ---------- n_samples : int, default=1 Number of samples to generate. Returns ------- X : array, shape (n_samples, n_features) Rand...
Generate random samples from the fitted Gaussian distribution. Parameters ---------- n_samples : int, default=1 Number of samples to generate. Returns ------- X : array, shape (n_samples, n_features) Randomly generated sample. y : array,...
sample
python
scikit-learn/scikit-learn
sklearn/mixture/_base.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/mixture/_base.py
BSD-3-Clause
def _estimate_log_prob_resp(self, X): """Estimate log probabilities and responsibilities for each sample. Compute the log probabilities, weighted log probabilities per component and responsibilities for each sample in X with respect to the current state of the model. Parameters...
Estimate log probabilities and responsibilities for each sample. Compute the log probabilities, weighted log probabilities per component and responsibilities for each sample in X with respect to the current state of the model. Parameters ---------- X : array-like of sha...
_estimate_log_prob_resp
python
scikit-learn/scikit-learn
sklearn/mixture/_base.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/mixture/_base.py
BSD-3-Clause
def _print_verbose_msg_init_end(self, lb, init_has_converged): """Print verbose message on the end of iteration.""" converged_msg = "converged" if init_has_converged else "did not converge" if self.verbose == 1: print(f"Initialization {converged_msg}.") elif self.verbose >= 2...
Print verbose message on the end of iteration.
_print_verbose_msg_init_end
python
scikit-learn/scikit-learn
sklearn/mixture/_base.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/mixture/_base.py
BSD-3-Clause
def _log_wishart_norm(degrees_of_freedom, log_det_precisions_chol, n_features): """Compute the log of the Wishart distribution normalization term. Parameters ---------- degrees_of_freedom : array-like of shape (n_components,) The number of degrees of freedom on the covariance Wishart di...
Compute the log of the Wishart distribution normalization term. Parameters ---------- degrees_of_freedom : array-like of shape (n_components,) The number of degrees of freedom on the covariance Wishart distributions. log_det_precision_chol : array-like of shape (n_components,) ...
_log_wishart_norm
python
scikit-learn/scikit-learn
sklearn/mixture/_bayesian_mixture.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/mixture/_bayesian_mixture.py
BSD-3-Clause
def _check_parameters(self, X): """Check that the parameters are well defined. Parameters ---------- X : array-like of shape (n_samples, n_features) """ self._check_weights_parameters() self._check_means_parameters(X) self._check_precision_parameters(X) ...
Check that the parameters are well defined. Parameters ---------- X : array-like of shape (n_samples, n_features)
_check_parameters
python
scikit-learn/scikit-learn
sklearn/mixture/_bayesian_mixture.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/mixture/_bayesian_mixture.py
BSD-3-Clause
def _check_weights_parameters(self): """Check the parameter of the Dirichlet distribution.""" if self.weight_concentration_prior is None: self.weight_concentration_prior_ = 1.0 / self.n_components else: self.weight_concentration_prior_ = self.weight_concentration_prior
Check the parameter of the Dirichlet distribution.
_check_weights_parameters
python
scikit-learn/scikit-learn
sklearn/mixture/_bayesian_mixture.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/mixture/_bayesian_mixture.py
BSD-3-Clause
def _check_means_parameters(self, X): """Check the parameters of the Gaussian distribution. Parameters ---------- X : array-like of shape (n_samples, n_features) """ _, n_features = X.shape if self.mean_precision_prior is None: self.mean_precision_pr...
Check the parameters of the Gaussian distribution. Parameters ---------- X : array-like of shape (n_samples, n_features)
_check_means_parameters
python
scikit-learn/scikit-learn
sklearn/mixture/_bayesian_mixture.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/mixture/_bayesian_mixture.py
BSD-3-Clause
def _check_precision_parameters(self, X): """Check the prior parameters of the precision distribution. Parameters ---------- X : array-like of shape (n_samples, n_features) """ _, n_features = X.shape if self.degrees_of_freedom_prior is None: self.de...
Check the prior parameters of the precision distribution. Parameters ---------- X : array-like of shape (n_samples, n_features)
_check_precision_parameters
python
scikit-learn/scikit-learn
sklearn/mixture/_bayesian_mixture.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/mixture/_bayesian_mixture.py
BSD-3-Clause
def _checkcovariance_prior_parameter(self, X): """Check the `covariance_prior_`. Parameters ---------- X : array-like of shape (n_samples, n_features) """ _, n_features = X.shape if self.covariance_prior is None: self.covariance_prior_ = { ...
Check the `covariance_prior_`. Parameters ---------- X : array-like of shape (n_samples, n_features)
_checkcovariance_prior_parameter
python
scikit-learn/scikit-learn
sklearn/mixture/_bayesian_mixture.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/mixture/_bayesian_mixture.py
BSD-3-Clause
def _initialize(self, X, resp): """Initialization of the mixture parameters. Parameters ---------- X : array-like of shape (n_samples, n_features) resp : array-like of shape (n_samples, n_components) """ nk, xk, sk = _estimate_gaussian_parameters( X,...
Initialization of the mixture parameters. Parameters ---------- X : array-like of shape (n_samples, n_features) resp : array-like of shape (n_samples, n_components)
_initialize
python
scikit-learn/scikit-learn
sklearn/mixture/_bayesian_mixture.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/mixture/_bayesian_mixture.py
BSD-3-Clause
def _estimate_weights(self, nk): """Estimate the parameters of the Dirichlet distribution. Parameters ---------- nk : array-like of shape (n_components,) """ if self.weight_concentration_prior_type == "dirichlet_process": # For dirichlet process weight_concen...
Estimate the parameters of the Dirichlet distribution. Parameters ---------- nk : array-like of shape (n_components,)
_estimate_weights
python
scikit-learn/scikit-learn
sklearn/mixture/_bayesian_mixture.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/mixture/_bayesian_mixture.py
BSD-3-Clause
def _estimate_means(self, nk, xk): """Estimate the parameters of the Gaussian distribution. Parameters ---------- nk : array-like of shape (n_components,) xk : array-like of shape (n_components, n_features) """ self.mean_precision_ = self.mean_precision_prior_ +...
Estimate the parameters of the Gaussian distribution. Parameters ---------- nk : array-like of shape (n_components,) xk : array-like of shape (n_components, n_features)
_estimate_means
python
scikit-learn/scikit-learn
sklearn/mixture/_bayesian_mixture.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/mixture/_bayesian_mixture.py
BSD-3-Clause
def _estimate_precisions(self, nk, xk, sk): """Estimate the precisions parameters of the precision distribution. Parameters ---------- nk : array-like of shape (n_components,) xk : array-like of shape (n_components, n_features) sk : array-like The shape dep...
Estimate the precisions parameters of the precision distribution. Parameters ---------- nk : array-like of shape (n_components,) xk : array-like of shape (n_components, n_features) sk : array-like The shape depends of `covariance_type`: 'full' : (n_comp...
_estimate_precisions
python
scikit-learn/scikit-learn
sklearn/mixture/_bayesian_mixture.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/mixture/_bayesian_mixture.py
BSD-3-Clause
def _estimate_wishart_full(self, nk, xk, sk): """Estimate the full Wishart distribution parameters. Parameters ---------- X : array-like of shape (n_samples, n_features) nk : array-like of shape (n_components,) xk : array-like of shape (n_components, n_features) ...
Estimate the full Wishart distribution parameters. Parameters ---------- X : array-like of shape (n_samples, n_features) nk : array-like of shape (n_components,) xk : array-like of shape (n_components, n_features) sk : array-like of shape (n_components, n_features, n_...
_estimate_wishart_full
python
scikit-learn/scikit-learn
sklearn/mixture/_bayesian_mixture.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/mixture/_bayesian_mixture.py
BSD-3-Clause
def _estimate_wishart_tied(self, nk, xk, sk): """Estimate the tied Wishart distribution parameters. Parameters ---------- X : array-like of shape (n_samples, n_features) nk : array-like of shape (n_components,) xk : array-like of shape (n_components, n_features) ...
Estimate the tied Wishart distribution parameters. Parameters ---------- X : array-like of shape (n_samples, n_features) nk : array-like of shape (n_components,) xk : array-like of shape (n_components, n_features) sk : array-like of shape (n_features, n_features) ...
_estimate_wishart_tied
python
scikit-learn/scikit-learn
sklearn/mixture/_bayesian_mixture.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/mixture/_bayesian_mixture.py
BSD-3-Clause
def _estimate_wishart_diag(self, nk, xk, sk): """Estimate the diag Wishart distribution parameters. Parameters ---------- X : array-like of shape (n_samples, n_features) nk : array-like of shape (n_components,) xk : array-like of shape (n_components, n_features) ...
Estimate the diag Wishart distribution parameters. Parameters ---------- X : array-like of shape (n_samples, n_features) nk : array-like of shape (n_components,) xk : array-like of shape (n_components, n_features) sk : array-like of shape (n_components, n_features) ...
_estimate_wishart_diag
python
scikit-learn/scikit-learn
sklearn/mixture/_bayesian_mixture.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/mixture/_bayesian_mixture.py
BSD-3-Clause
def _estimate_wishart_spherical(self, nk, xk, sk): """Estimate the spherical Wishart distribution parameters. Parameters ---------- X : array-like of shape (n_samples, n_features) nk : array-like of shape (n_components,) xk : array-like of shape (n_components, n_featur...
Estimate the spherical Wishart distribution parameters. Parameters ---------- X : array-like of shape (n_samples, n_features) nk : array-like of shape (n_components,) xk : array-like of shape (n_components, n_features) sk : array-like of shape (n_components,)
_estimate_wishart_spherical
python
scikit-learn/scikit-learn
sklearn/mixture/_bayesian_mixture.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/mixture/_bayesian_mixture.py
BSD-3-Clause
def _m_step(self, X, log_resp): """M step. Parameters ---------- X : array-like of shape (n_samples, n_features) log_resp : array-like of shape (n_samples, n_components) Logarithm of the posterior probabilities (or responsibilities) of the point of each ...
M step. Parameters ---------- X : array-like of shape (n_samples, n_features) log_resp : array-like of shape (n_samples, n_components) Logarithm of the posterior probabilities (or responsibilities) of the point of each sample in X.
_m_step
python
scikit-learn/scikit-learn
sklearn/mixture/_bayesian_mixture.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/mixture/_bayesian_mixture.py
BSD-3-Clause
def _compute_lower_bound(self, log_resp, log_prob_norm): """Estimate the lower bound of the model. The lower bound on the likelihood (of the training data with respect to the model) is used to detect the convergence and has to increase at each iteration. Parameters ----...
Estimate the lower bound of the model. The lower bound on the likelihood (of the training data with respect to the model) is used to detect the convergence and has to increase at each iteration. Parameters ---------- X : array-like of shape (n_samples, n_features) ...
_compute_lower_bound
python
scikit-learn/scikit-learn
sklearn/mixture/_bayesian_mixture.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/mixture/_bayesian_mixture.py
BSD-3-Clause
def _check_weights(weights, n_components): """Check the user provided 'weights'. Parameters ---------- weights : array-like of shape (n_components,) The proportions of components of each mixture. n_components : int Number of components. Returns ------- weights : array,...
Check the user provided 'weights'. Parameters ---------- weights : array-like of shape (n_components,) The proportions of components of each mixture. n_components : int Number of components. Returns ------- weights : array, shape (n_components,)
_check_weights
python
scikit-learn/scikit-learn
sklearn/mixture/_gaussian_mixture.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/mixture/_gaussian_mixture.py
BSD-3-Clause
def _check_means(means, n_components, n_features): """Validate the provided 'means'. Parameters ---------- means : array-like of shape (n_components, n_features) The centers of the current components. n_components : int Number of components. n_features : int Number of ...
Validate the provided 'means'. Parameters ---------- means : array-like of shape (n_components, n_features) The centers of the current components. n_components : int Number of components. n_features : int Number of features. Returns ------- means : array, (n_c...
_check_means
python
scikit-learn/scikit-learn
sklearn/mixture/_gaussian_mixture.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/mixture/_gaussian_mixture.py
BSD-3-Clause
def _check_precision_positivity(precision, covariance_type): """Check a precision vector is positive-definite.""" if np.any(np.less_equal(precision, 0.0)): raise ValueError("'%s precision' should be positive" % covariance_type)
Check a precision vector is positive-definite.
_check_precision_positivity
python
scikit-learn/scikit-learn
sklearn/mixture/_gaussian_mixture.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/mixture/_gaussian_mixture.py
BSD-3-Clause
def _check_precision_matrix(precision, covariance_type): """Check a precision matrix is symmetric and positive-definite.""" if not ( np.allclose(precision, precision.T) and np.all(linalg.eigvalsh(precision) > 0.0) ): raise ValueError( "'%s precision' should be symmetric, positive...
Check a precision matrix is symmetric and positive-definite.
_check_precision_matrix
python
scikit-learn/scikit-learn
sklearn/mixture/_gaussian_mixture.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/mixture/_gaussian_mixture.py
BSD-3-Clause
def _check_precisions(precisions, covariance_type, n_components, n_features): """Validate user provided precisions. Parameters ---------- precisions : array-like 'full' : shape of (n_components, n_features, n_features) 'tied' : shape of (n_features, n_features) 'diag' : shape of...
Validate user provided precisions. Parameters ---------- precisions : array-like 'full' : shape of (n_components, n_features, n_features) 'tied' : shape of (n_features, n_features) 'diag' : shape of (n_components, n_features) 'spherical' : shape of (n_components,) covar...
_check_precisions
python
scikit-learn/scikit-learn
sklearn/mixture/_gaussian_mixture.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/mixture/_gaussian_mixture.py
BSD-3-Clause
def _estimate_gaussian_covariances_full(resp, X, nk, means, reg_covar): """Estimate the full covariance matrices. Parameters ---------- resp : array-like of shape (n_samples, n_components) X : array-like of shape (n_samples, n_features) nk : array-like of shape (n_components,) means : ar...
Estimate the full covariance matrices. Parameters ---------- resp : array-like of shape (n_samples, n_components) X : array-like of shape (n_samples, n_features) nk : array-like of shape (n_components,) means : array-like of shape (n_components, n_features) reg_covar : float Return...
_estimate_gaussian_covariances_full
python
scikit-learn/scikit-learn
sklearn/mixture/_gaussian_mixture.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/mixture/_gaussian_mixture.py
BSD-3-Clause
def _estimate_gaussian_covariances_tied(resp, X, nk, means, reg_covar): """Estimate the tied covariance matrix. Parameters ---------- resp : array-like of shape (n_samples, n_components) X : array-like of shape (n_samples, n_features) nk : array-like of shape (n_components,) means : arra...
Estimate the tied covariance matrix. Parameters ---------- resp : array-like of shape (n_samples, n_components) X : array-like of shape (n_samples, n_features) nk : array-like of shape (n_components,) means : array-like of shape (n_components, n_features) reg_covar : float Returns ...
_estimate_gaussian_covariances_tied
python
scikit-learn/scikit-learn
sklearn/mixture/_gaussian_mixture.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/mixture/_gaussian_mixture.py
BSD-3-Clause
def _estimate_gaussian_covariances_diag(resp, X, nk, means, reg_covar): """Estimate the diagonal covariance vectors. Parameters ---------- responsibilities : array-like of shape (n_samples, n_components) X : array-like of shape (n_samples, n_features) nk : array-like of shape (n_components,) ...
Estimate the diagonal covariance vectors. Parameters ---------- responsibilities : array-like of shape (n_samples, n_components) X : array-like of shape (n_samples, n_features) nk : array-like of shape (n_components,) means : array-like of shape (n_components, n_features) reg_covar : fl...
_estimate_gaussian_covariances_diag
python
scikit-learn/scikit-learn
sklearn/mixture/_gaussian_mixture.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/mixture/_gaussian_mixture.py
BSD-3-Clause
def _estimate_gaussian_parameters(X, resp, reg_covar, covariance_type): """Estimate the Gaussian distribution parameters. Parameters ---------- X : array-like of shape (n_samples, n_features) The input data array. resp : array-like of shape (n_samples, n_components) The responsibil...
Estimate the Gaussian distribution parameters. Parameters ---------- X : array-like of shape (n_samples, n_features) The input data array. resp : array-like of shape (n_samples, n_components) The responsibilities for each data sample in X. reg_covar : float The regularizat...
_estimate_gaussian_parameters
python
scikit-learn/scikit-learn
sklearn/mixture/_gaussian_mixture.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/mixture/_gaussian_mixture.py
BSD-3-Clause
def _compute_precision_cholesky(covariances, covariance_type): """Compute the Cholesky decomposition of the precisions. Parameters ---------- covariances : array-like The covariance matrix of the current components. The shape depends of the covariance_type. covariance_type : {'full...
Compute the Cholesky decomposition of the precisions. Parameters ---------- covariances : array-like The covariance matrix of the current components. The shape depends of the covariance_type. covariance_type : {'full', 'tied', 'diag', 'spherical'} The type of precision matrices...
_compute_precision_cholesky
python
scikit-learn/scikit-learn
sklearn/mixture/_gaussian_mixture.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/mixture/_gaussian_mixture.py
BSD-3-Clause
def _compute_precision_cholesky_from_precisions(precisions, covariance_type): r"""Compute the Cholesky decomposition of precisions using precisions themselves. As implemented in :func:`_compute_precision_cholesky`, the `precisions_cholesky_` is an upper-triangular matrix for each Gaussian component, which ...
Compute the Cholesky decomposition of precisions using precisions themselves. As implemented in :func:`_compute_precision_cholesky`, the `precisions_cholesky_` is an upper-triangular matrix for each Gaussian component, which can be expressed as the $UU^T$ factorization of the precision matrix for each Gaus...
_compute_precision_cholesky_from_precisions
python
scikit-learn/scikit-learn
sklearn/mixture/_gaussian_mixture.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/mixture/_gaussian_mixture.py
BSD-3-Clause
def _compute_log_det_cholesky(matrix_chol, covariance_type, n_features): """Compute the log-det of the cholesky decomposition of matrices. Parameters ---------- matrix_chol : array-like Cholesky decompositions of the matrices. 'full' : shape of (n_components, n_features, n_features) ...
Compute the log-det of the cholesky decomposition of matrices. Parameters ---------- matrix_chol : array-like Cholesky decompositions of the matrices. 'full' : shape of (n_components, n_features, n_features) 'tied' : shape of (n_features, n_features) 'diag' : shape of (n_com...
_compute_log_det_cholesky
python
scikit-learn/scikit-learn
sklearn/mixture/_gaussian_mixture.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/mixture/_gaussian_mixture.py
BSD-3-Clause
def _estimate_log_gaussian_prob(X, means, precisions_chol, covariance_type): """Estimate the log Gaussian probability. Parameters ---------- X : array-like of shape (n_samples, n_features) means : array-like of shape (n_components, n_features) precisions_chol : array-like Cholesky dec...
Estimate the log Gaussian probability. Parameters ---------- X : array-like of shape (n_samples, n_features) means : array-like of shape (n_components, n_features) precisions_chol : array-like Cholesky decompositions of the precision matrices. 'full' : shape of (n_components, n_fe...
_estimate_log_gaussian_prob
python
scikit-learn/scikit-learn
sklearn/mixture/_gaussian_mixture.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/mixture/_gaussian_mixture.py
BSD-3-Clause
def _check_parameters(self, X): """Check the Gaussian mixture parameters are well defined.""" _, n_features = X.shape if self.weights_init is not None: self.weights_init = _check_weights(self.weights_init, self.n_components) if self.means_init is not None: self....
Check the Gaussian mixture parameters are well defined.
_check_parameters
python
scikit-learn/scikit-learn
sklearn/mixture/_gaussian_mixture.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/mixture/_gaussian_mixture.py
BSD-3-Clause
def _initialize(self, X, resp): """Initialization of the Gaussian mixture parameters. Parameters ---------- X : array-like of shape (n_samples, n_features) resp : array-like of shape (n_samples, n_components) """ n_samples, _ = X.shape weights, means, co...
Initialization of the Gaussian mixture parameters. Parameters ---------- X : array-like of shape (n_samples, n_features) resp : array-like of shape (n_samples, n_components)
_initialize
python
scikit-learn/scikit-learn
sklearn/mixture/_gaussian_mixture.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/mixture/_gaussian_mixture.py
BSD-3-Clause
def _n_parameters(self): """Return the number of free parameters in the model.""" _, n_features = self.means_.shape if self.covariance_type == "full": cov_params = self.n_components * n_features * (n_features + 1) / 2.0 elif self.covariance_type == "diag": cov_par...
Return the number of free parameters in the model.
_n_parameters
python
scikit-learn/scikit-learn
sklearn/mixture/_gaussian_mixture.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/mixture/_gaussian_mixture.py
BSD-3-Clause
def test_gaussian_mixture_setting_best_params(): """`GaussianMixture`'s best_parameters, `n_iter_` and `lower_bound_` must be set appropriately in the case of divergence. Non-regression test for: https://github.com/scikit-learn/scikit-learn/issues/18216 """ rnd = np.random.RandomState(0) n_...
`GaussianMixture`'s best_parameters, `n_iter_` and `lower_bound_` must be set appropriately in the case of divergence. Non-regression test for: https://github.com/scikit-learn/scikit-learn/issues/18216
test_gaussian_mixture_setting_best_params
python
scikit-learn/scikit-learn
sklearn/mixture/tests/test_gaussian_mixture.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/mixture/tests/test_gaussian_mixture.py
BSD-3-Clause
def test_gaussian_mixture_precisions_init_diag(global_dtype): """Check that we properly initialize `precision_cholesky_` when we manually provide the precision matrix. In this regard, we check the consistency between estimating the precision matrix and providing the same precision matrix as initializat...
Check that we properly initialize `precision_cholesky_` when we manually provide the precision matrix. In this regard, we check the consistency between estimating the precision matrix and providing the same precision matrix as initialization. It should lead to the same results with the same number of i...
test_gaussian_mixture_precisions_init_diag
python
scikit-learn/scikit-learn
sklearn/mixture/tests/test_gaussian_mixture.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/mixture/tests/test_gaussian_mixture.py
BSD-3-Clause
def _calculate_precisions(X, resp, covariance_type): """Calculate precision matrix of X and its Cholesky decomposition for the given covariance type. """ reg_covar = 1e-6 weights, means, covariances = _estimate_gaussian_parameters( X, resp, reg_covar, covariance_type ) precisions_cho...
Calculate precision matrix of X and its Cholesky decomposition for the given covariance type.
_calculate_precisions
python
scikit-learn/scikit-learn
sklearn/mixture/tests/test_gaussian_mixture.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/mixture/tests/test_gaussian_mixture.py
BSD-3-Clause
def test_gaussian_mixture_single_component_stable(): """ Non-regression test for #23032 ensuring 1-component GM works on only a few samples. """ rng = np.random.RandomState(0) X = rng.multivariate_normal(np.zeros(2), np.identity(2), size=3) gm = GaussianMixture(n_components=1) gm.fit(X)....
Non-regression test for #23032 ensuring 1-component GM works on only a few samples.
test_gaussian_mixture_single_component_stable
python
scikit-learn/scikit-learn
sklearn/mixture/tests/test_gaussian_mixture.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/mixture/tests/test_gaussian_mixture.py
BSD-3-Clause
def test_gaussian_mixture_all_init_does_not_estimate_gaussian_parameters( monkeypatch, global_random_seed, ): """When all init parameters are provided, the Gaussian parameters are not estimated. Non-regression test for gh-26015. """ mock = Mock(side_effect=_estimate_gaussian_parameters) ...
When all init parameters are provided, the Gaussian parameters are not estimated. Non-regression test for gh-26015.
test_gaussian_mixture_all_init_does_not_estimate_gaussian_parameters
python
scikit-learn/scikit-learn
sklearn/mixture/tests/test_gaussian_mixture.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/mixture/tests/test_gaussian_mixture.py
BSD-3-Clause
def fit(self, X, y, **params): """Fit the classifier. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) Training data. y : array-like of shape (n_samples,) Target values. **params : dict Parameter...
Fit the classifier. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) Training data. y : array-like of shape (n_samples,) Target values. **params : dict Parameters to pass to the `fit` method of the under...
fit
python
scikit-learn/scikit-learn
sklearn/model_selection/_classification_threshold.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/model_selection/_classification_threshold.py
BSD-3-Clause
def predict_proba(self, X): """Predict class probabilities for `X` using the fitted estimator. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) Training vectors, where `n_samples` is the number of samples and `n_features` is ...
Predict class probabilities for `X` using the fitted estimator. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) Training vectors, where `n_samples` is the number of samples and `n_features` is the number of features. Return...
predict_proba
python
scikit-learn/scikit-learn
sklearn/model_selection/_classification_threshold.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/model_selection/_classification_threshold.py
BSD-3-Clause
def predict_log_proba(self, X): """Predict logarithm class probabilities for `X` using the fitted estimator. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) Training vectors, where `n_samples` is the number of samples and `n...
Predict logarithm class probabilities for `X` using the fitted estimator. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) Training vectors, where `n_samples` is the number of samples and `n_features` is the number of features. ...
predict_log_proba
python
scikit-learn/scikit-learn
sklearn/model_selection/_classification_threshold.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/model_selection/_classification_threshold.py
BSD-3-Clause
def decision_function(self, X): """Decision function for samples in `X` using the fitted estimator. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) Training vectors, where `n_samples` is the number of samples and `n_features...
Decision function for samples in `X` using the fitted estimator. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) Training vectors, where `n_samples` is the number of samples and `n_features` is the number of features. Retur...
decision_function
python
scikit-learn/scikit-learn
sklearn/model_selection/_classification_threshold.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/model_selection/_classification_threshold.py
BSD-3-Clause
def predict(self, X): """Predict the target of new samples. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The samples, as accepted by `estimator.predict`. Returns ------- class_labels : ndarray of shape (n_sam...
Predict the target of new samples. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The samples, as accepted by `estimator.predict`. Returns ------- class_labels : ndarray of shape (n_samples,) The predicted ...
predict
python
scikit-learn/scikit-learn
sklearn/model_selection/_classification_threshold.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/model_selection/_classification_threshold.py
BSD-3-Clause
def _fit_and_score_over_thresholds( classifier, X, y, *, fit_params, train_idx, val_idx, curve_scorer, score_params, ): """Fit a classifier and compute the scores for different decision thresholds. Parameters ---------- classifier : estimator instance The cla...
Fit a classifier and compute the scores for different decision thresholds. Parameters ---------- classifier : estimator instance The classifier to fit and use for scoring. If `classifier` is already fitted, it will be used as is. X : {array-like, sparse matrix} of shape (n_samples, n_f...
_fit_and_score_over_thresholds
python
scikit-learn/scikit-learn
sklearn/model_selection/_classification_threshold.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/model_selection/_classification_threshold.py
BSD-3-Clause
def _mean_interpolated_score(target_thresholds, cv_thresholds, cv_scores): """Compute the mean interpolated score across folds by defining common thresholds. Parameters ---------- target_thresholds : ndarray of shape (thresholds,) The thresholds to use to compute the mean score. cv_thresho...
Compute the mean interpolated score across folds by defining common thresholds. Parameters ---------- target_thresholds : ndarray of shape (thresholds,) The thresholds to use to compute the mean score. cv_thresholds : ndarray of shape (n_folds, thresholds_fold) The thresholds used to c...
_mean_interpolated_score
python
scikit-learn/scikit-learn
sklearn/model_selection/_classification_threshold.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/model_selection/_classification_threshold.py
BSD-3-Clause
def _fit(self, X, y, **params): """Fit the classifier and post-tune the decision threshold. 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 classifier and post-tune the decision threshold. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) Training data. y : array-like of shape (n_samples,) Target values. **params : dict Parameters to ...
_fit
python
scikit-learn/scikit-learn
sklearn/model_selection/_classification_threshold.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/model_selection/_classification_threshold.py
BSD-3-Clause
def _get_curve_scorer(self): """Get the curve scorer based on the objective metric used.""" scoring = check_scoring(self.estimator, scoring=self.scoring) curve_scorer = _CurveScorer.from_scorer( scoring, self._get_response_method(), self.thresholds ) return curve_scor...
Get the curve scorer based on the objective metric used.
_get_curve_scorer
python
scikit-learn/scikit-learn
sklearn/model_selection/_classification_threshold.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/model_selection/_classification_threshold.py
BSD-3-Clause
def plot( self, ax=None, *, negate_score=False, score_name=None, score_type="both", std_display_style="fill_between", line_kw=None, fill_between_kw=None, errorbar_kw=None, ): """Plot visualization. Parameters --...
Plot visualization. Parameters ---------- ax : matplotlib Axes, default=None Axes object to plot on. If `None`, a new figure and axes is created. negate_score : bool, default=False Whether or not to negate the scores obtained through :fun...
plot
python
scikit-learn/scikit-learn
sklearn/model_selection/_plot.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/model_selection/_plot.py
BSD-3-Clause
def from_estimator( cls, estimator, X, y, *, groups=None, train_sizes=np.linspace(0.1, 1.0, 5), cv=None, scoring=None, exploit_incremental_learning=False, n_jobs=None, pre_dispatch="all", verbose=0, shuffle=F...
Create a learning curve display from an estimator. Read more in the :ref:`User Guide <visualizations>` for general information about the visualization API and :ref:`detailed documentation <learning_curve>` regarding the learning curve visualization. Parameters ---------...
from_estimator
python
scikit-learn/scikit-learn
sklearn/model_selection/_plot.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/model_selection/_plot.py
BSD-3-Clause
def plot( self, ax=None, *, negate_score=False, score_name=None, score_type="both", std_display_style="fill_between", line_kw=None, fill_between_kw=None, errorbar_kw=None, ): """Plot visualization. Parameters --...
Plot visualization. Parameters ---------- ax : matplotlib Axes, default=None Axes object to plot on. If `None`, a new figure and axes is created. negate_score : bool, default=False Whether or not to negate the scores obtained through :fun...
plot
python
scikit-learn/scikit-learn
sklearn/model_selection/_plot.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/model_selection/_plot.py
BSD-3-Clause
def from_estimator( cls, estimator, X, y, *, param_name, param_range, groups=None, cv=None, scoring=None, n_jobs=None, pre_dispatch="all", verbose=0, error_score=np.nan, fit_params=None, ax=No...
Create a validation curve display from an estimator. Read more in the :ref:`User Guide <visualizations>` for general information about the visualization API and :ref:`detailed documentation <validation_curve>` regarding the validation curve visualization. Parameters ---...
from_estimator
python
scikit-learn/scikit-learn
sklearn/model_selection/_plot.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/model_selection/_plot.py
BSD-3-Clause
def __iter__(self): """Iterate over the points in the grid. Returns ------- params : iterator over dict of str to any Yields dictionaries mapping each estimator parameter to one of its allowed values. """ for p in self.param_grid: # Al...
Iterate over the points in the grid. Returns ------- params : iterator over dict of str to any Yields dictionaries mapping each estimator parameter to one of its allowed values.
__iter__
python
scikit-learn/scikit-learn
sklearn/model_selection/_search.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/model_selection/_search.py
BSD-3-Clause
def __len__(self): """Number of points on the grid.""" # Product function that can handle iterables (np.prod can't). product = partial(reduce, operator.mul) return sum( product(len(v) for v in p.values()) if p else 1 for p in self.param_grid )
Number of points on the grid.
__len__
python
scikit-learn/scikit-learn
sklearn/model_selection/_search.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/model_selection/_search.py
BSD-3-Clause
def __getitem__(self, ind): """Get the parameters that would be ``ind``th in iteration Parameters ---------- ind : int The iteration index Returns ------- params : dict of str to any Equal to list(self)[ind] """ # This is ...
Get the parameters that would be ``ind``th in iteration Parameters ---------- ind : int The iteration index Returns ------- params : dict of str to any Equal to list(self)[ind]
__getitem__
python
scikit-learn/scikit-learn
sklearn/model_selection/_search.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/model_selection/_search.py
BSD-3-Clause
def __len__(self): """Number of points that will be sampled.""" if self._is_all_lists(): grid_size = len(ParameterGrid(self.param_distributions)) return min(self.n_iter, grid_size) else: return self.n_iter
Number of points that will be sampled.
__len__
python
scikit-learn/scikit-learn
sklearn/model_selection/_search.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/model_selection/_search.py
BSD-3-Clause
def _search_estimator_has(attr): """Check if we can delegate a method to the underlying estimator. Calling a prediction method will only be available if `refit=True`. In such case, we check first the fitted best estimator. If it is not fitted, we check the unfitted estimator. Checking the unfitted...
Check if we can delegate a method to the underlying estimator. Calling a prediction method will only be available if `refit=True`. In such case, we check first the fitted best estimator. If it is not fitted, we check the unfitted estimator. Checking the unfitted estimator allows to use `hasattr` on th...
_search_estimator_has
python
scikit-learn/scikit-learn
sklearn/model_selection/_search.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/model_selection/_search.py
BSD-3-Clause
def _yield_masked_array_for_each_param(candidate_params): """ Yield a masked array for each candidate param. `candidate_params` is a sequence of params which were used in a `GridSearchCV`. We use masked arrays for the results, as not all params are necessarily present in each element of `candid...
Yield a masked array for each candidate param. `candidate_params` is a sequence of params which were used in a `GridSearchCV`. We use masked arrays for the results, as not all params are necessarily present in each element of `candidate_params`. For example, if using `GridSearchCV` with a `SVC...
_yield_masked_array_for_each_param
python
scikit-learn/scikit-learn
sklearn/model_selection/_search.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/model_selection/_search.py
BSD-3-Clause
def score(self, X, y=None, **params): """Return the score on the given data, if the estimator has been refit. This uses the score defined by ``scoring`` where provided, and the ``best_estimator_.score`` method otherwise. Parameters ---------- X : array-like of shape (n_...
Return the score on the given data, if the estimator has been refit. This uses the score defined by ``scoring`` where provided, and the ``best_estimator_.score`` method otherwise. Parameters ---------- X : array-like of shape (n_samples, n_features) Input data, wher...
score
python
scikit-learn/scikit-learn
sklearn/model_selection/_search.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/model_selection/_search.py
BSD-3-Clause
def n_features_in_(self): """Number of features seen during :term:`fit`. Only available when `refit=True`. """ # For consistency with other estimators we raise a AttributeError so # that hasattr() fails if the search estimator isn't fitted. try: check_is_fitt...
Number of features seen during :term:`fit`. Only available when `refit=True`.
n_features_in_
python
scikit-learn/scikit-learn
sklearn/model_selection/_search.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/model_selection/_search.py
BSD-3-Clause
def _check_refit_for_multimetric(self, scores): """Check `refit` is compatible with `scores` is valid""" multimetric_refit_msg = ( "For multi-metric scoring, the parameter refit must be set to a " "scorer key or a callable to refit an estimator with the best " "parame...
Check `refit` is compatible with `scores` is valid
_check_refit_for_multimetric
python
scikit-learn/scikit-learn
sklearn/model_selection/_search.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/model_selection/_search.py
BSD-3-Clause
def _select_best_index(refit, refit_metric, results): """Select index of the best combination of hyperparemeters.""" if callable(refit): # If callable, refit is expected to return the index of the best # parameter set. best_index = refit(results) if not is...
Select index of the best combination of hyperparemeters.
_select_best_index
python
scikit-learn/scikit-learn
sklearn/model_selection/_search.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/model_selection/_search.py
BSD-3-Clause
def _get_scorers(self): """Get the scorer(s) to be used. This is used in ``fit`` and ``get_metadata_routing``. Returns ------- scorers, refit_metric """ refit_metric = "score" if callable(self.scoring): scorers = self.scoring elif se...
Get the scorer(s) to be used. This is used in ``fit`` and ``get_metadata_routing``. Returns ------- scorers, refit_metric
_get_scorers
python
scikit-learn/scikit-learn
sklearn/model_selection/_search.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/model_selection/_search.py
BSD-3-Clause
def _get_routed_params_for_fit(self, params): """Get the parameters to be used for routing. This is a method instead of a snippet in ``fit`` since it's used twice, here in ``fit``, and in ``HalvingRandomSearchCV.fit``. """ if _routing_enabled(): routed_params = proce...
Get the parameters to be used for routing. This is a method instead of a snippet in ``fit`` since it's used twice, here in ``fit``, and in ``HalvingRandomSearchCV.fit``.
_get_routed_params_for_fit
python
scikit-learn/scikit-learn
sklearn/model_selection/_search.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/model_selection/_search.py
BSD-3-Clause
def fit(self, X, y=None, **params): """Run fit with all sets of parameters. Parameters ---------- X : array-like of shape (n_samples, n_features) or (n_samples, n_samples) Training vectors, where `n_samples` is the number of samples and `n_features` is the numbe...
Run fit with all sets of parameters. Parameters ---------- X : array-like of shape (n_samples, n_features) or (n_samples, n_samples) Training vectors, where `n_samples` is the number of samples and `n_features` is the number of features. For precomputed kernel or ...
fit
python
scikit-learn/scikit-learn
sklearn/model_selection/_search.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/model_selection/_search.py
BSD-3-Clause
def _store(key_name, array, weights=None, splits=False, rank=False): """A small helper to store the scores/times to the cv_results_""" # When iterated first by splits, then by parameters # We want `array` to have `n_candidates` rows and `n_splits` cols. array = np.array(a...
A small helper to store the scores/times to the cv_results_
_store
python
scikit-learn/scikit-learn
sklearn/model_selection/_search.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/model_selection/_search.py
BSD-3-Clause
def _select_best_index(refit, refit_metric, results): """Custom refit callable to return the index of the best candidate. We want the best candidate out of the last iteration. By default BaseSearchCV would return the best candidate out of all iterations. Currently, we only support for ...
Custom refit callable to return the index of the best candidate. We want the best candidate out of the last iteration. By default BaseSearchCV would return the best candidate out of all iterations. Currently, we only support for a single metric thus `refit` and `refit_metric` are not r...
_select_best_index
python
scikit-learn/scikit-learn
sklearn/model_selection/_search_successive_halving.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/model_selection/_search_successive_halving.py
BSD-3-Clause
def fit(self, X, y=None, **params): """Run fit with all sets of parameters. 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 : a...
Run fit with all sets of parameters. 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,) or (n_samples, n_...
fit
python
scikit-learn/scikit-learn
sklearn/model_selection/_search_successive_halving.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/model_selection/_search_successive_halving.py
BSD-3-Clause
def split(self, X, y=None, groups=None): """Generate indices to split data into training and test set. Parameters ---------- X : array-like of shape (n_samples, n_features) Training data, where `n_samples` is the number of samples and `n_features` is the number o...
Generate indices to split data into training and test set. Parameters ---------- X : array-like of shape (n_samples, n_features) Training data, where `n_samples` is the number of samples and `n_features` is the number of features. y : array-like of shape (n_samp...
split
python
scikit-learn/scikit-learn
sklearn/model_selection/_split.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/model_selection/_split.py
BSD-3-Clause
def split(self, X, y=None, groups=None): """Generate indices to split data into training and test set. Parameters ---------- X : array-like of shape (n_samples, n_features) Training data, where `n_samples` is the number of samples and `n_features` is the number o...
Generate indices to split data into training and test set. Parameters ---------- X : array-like of shape (n_samples, n_features) Training data, where `n_samples` is the number of samples and `n_features` is the number of features. y : array-like of shape (n_samp...
split
python
scikit-learn/scikit-learn
sklearn/model_selection/_split.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/model_selection/_split.py
BSD-3-Clause
def _iter_test_masks(self, X=None, y=None, groups=None): """Generates boolean masks corresponding to test sets. By default, delegates to _iter_test_indices(X, y, groups) """ for test_index in self._iter_test_indices(X, y, groups): test_mask = np.zeros(_num_samples(X), dtype=...
Generates boolean masks corresponding to test sets. By default, delegates to _iter_test_indices(X, y, groups)
_iter_test_masks
python
scikit-learn/scikit-learn
sklearn/model_selection/_split.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/model_selection/_split.py
BSD-3-Clause