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 sqeuclidean_row_norms(X, num_threads):
"""Compute the squared euclidean norm of the rows of X in parallel.
Parameters
----------
X : ndarray or CSR matrix of shape (n_samples, n_features)
Input data. Must be c-contiguous.
num_threads : int
The number of OpenMP threads to use.
... | Compute the squared euclidean norm of the rows of X in parallel.
Parameters
----------
X : ndarray or CSR matrix of shape (n_samples, n_features)
Input data. Must be c-contiguous.
num_threads : int
The number of OpenMP threads to use.
Returns
-------
sqeuclidean_row_norms ... | sqeuclidean_row_norms | python | scikit-learn/scikit-learn | sklearn/metrics/_pairwise_distances_reduction/_dispatcher.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/metrics/_pairwise_distances_reduction/_dispatcher.py | BSD-3-Clause |
def is_usable_for(cls, X, Y, metric) -> bool:
"""Return True if the dispatcher can be used for the
given parameters.
Parameters
----------
X : {ndarray, sparse matrix} of shape (n_samples_X, n_features)
Input data.
Y : {ndarray, sparse matrix} of shape (n_sa... | Return True if the dispatcher can be used for the
given parameters.
Parameters
----------
X : {ndarray, sparse matrix} of shape (n_samples_X, n_features)
Input data.
Y : {ndarray, sparse matrix} of shape (n_samples_Y, n_features)
Input data.
met... | is_usable_for | python | scikit-learn/scikit-learn | sklearn/metrics/_pairwise_distances_reduction/_dispatcher.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/metrics/_pairwise_distances_reduction/_dispatcher.py | BSD-3-Clause |
def compute(
cls,
X,
Y,
**kwargs,
):
"""Compute the reduction.
Parameters
----------
X : ndarray or CSR matrix of shape (n_samples_X, n_features)
Input data.
Y : ndarray or CSR matrix of shape (n_samples_Y, n_features)
... | Compute the reduction.
Parameters
----------
X : ndarray or CSR matrix of shape (n_samples_X, n_features)
Input data.
Y : ndarray or CSR matrix of shape (n_samples_Y, n_features)
Input data.
**kwargs : additional parameters for the reduction
No... | compute | python | scikit-learn/scikit-learn | sklearn/metrics/_pairwise_distances_reduction/_dispatcher.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/metrics/_pairwise_distances_reduction/_dispatcher.py | BSD-3-Clause |
def compute(
cls,
X,
Y,
k,
metric="euclidean",
chunk_size=None,
metric_kwargs=None,
strategy=None,
return_distance=False,
):
"""Compute the argkmin reduction.
Parameters
----------
X : ndarray or CSR matrix of s... | Compute the argkmin reduction.
Parameters
----------
X : ndarray or CSR matrix of shape (n_samples_X, n_features)
Input data.
Y : ndarray or CSR matrix of shape (n_samples_Y, n_features)
Input data.
k : int
The k for the argkmin reduction.
... | compute | python | scikit-learn/scikit-learn | sklearn/metrics/_pairwise_distances_reduction/_dispatcher.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/metrics/_pairwise_distances_reduction/_dispatcher.py | BSD-3-Clause |
def compute(
cls,
X,
Y,
radius,
metric="euclidean",
chunk_size=None,
metric_kwargs=None,
strategy=None,
return_distance=False,
sort_results=False,
):
"""Return the results of the reduction for the given arguments.
Param... | Return the results of the reduction for the given arguments.
Parameters
----------
X : ndarray or CSR matrix of shape (n_samples_X, n_features)
Input data.
Y : ndarray or CSR matrix of shape (n_samples_Y, n_features)
Input data.
radius : float
... | compute | python | scikit-learn/scikit-learn | sklearn/metrics/_pairwise_distances_reduction/_dispatcher.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/metrics/_pairwise_distances_reduction/_dispatcher.py | BSD-3-Clause |
def compute(
cls,
X,
Y,
k,
weights,
Y_labels,
unique_Y_labels,
metric="euclidean",
chunk_size=None,
metric_kwargs=None,
strategy=None,
):
"""Compute the argkmin reduction.
Parameters
----------
X... | Compute the argkmin reduction.
Parameters
----------
X : ndarray of shape (n_samples_X, n_features)
The input array to be labelled.
Y : ndarray of shape (n_samples_Y, n_features)
The input array whose class membership are provided through the
`Y_labe... | compute | python | scikit-learn/scikit-learn | sklearn/metrics/_pairwise_distances_reduction/_dispatcher.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/metrics/_pairwise_distances_reduction/_dispatcher.py | BSD-3-Clause |
def compute(
cls,
X,
Y,
radius,
weights,
Y_labels,
unique_Y_labels,
outlier_label,
metric="euclidean",
chunk_size=None,
metric_kwargs=None,
strategy=None,
):
"""Return the results of the reduction for the given a... | Return the results of the reduction for the given arguments.
Parameters
----------
X : ndarray of shape (n_samples_X, n_features)
The input array to be labelled.
Y : ndarray of shape (n_samples_Y, n_features)
The input array whose class membership is provided thro... | compute | python | scikit-learn/scikit-learn | sklearn/metrics/_pairwise_distances_reduction/_dispatcher.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/metrics/_pairwise_distances_reduction/_dispatcher.py | BSD-3-Clause |
def plot(
self,
*,
include_values=True,
cmap="viridis",
xticks_rotation="horizontal",
values_format=None,
ax=None,
colorbar=True,
im_kw=None,
text_kw=None,
):
"""Plot visualization.
Parameters
----------
... | Plot visualization.
Parameters
----------
include_values : bool, default=True
Includes values in confusion matrix.
cmap : str or matplotlib Colormap, default='viridis'
Colormap recognized by matplotlib.
xticks_rotation : {'vertical', 'horizontal'} or fl... | plot | python | scikit-learn/scikit-learn | sklearn/metrics/_plot/confusion_matrix.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/metrics/_plot/confusion_matrix.py | BSD-3-Clause |
def from_estimator(
cls,
estimator,
X,
y,
*,
labels=None,
sample_weight=None,
normalize=None,
display_labels=None,
include_values=True,
xticks_rotation="horizontal",
values_format=None,
cmap="viridis",
ax=Non... | Plot Confusion Matrix given an estimator and some data.
For general information regarding `scikit-learn` visualization tools, see
the :ref:`Visualization Guide <visualizations>`.
For guidance on interpreting these plots, refer to the
:ref:`Model Evaluation Guide <confusion_matrix>`.
... | from_estimator | python | scikit-learn/scikit-learn | sklearn/metrics/_plot/confusion_matrix.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/metrics/_plot/confusion_matrix.py | BSD-3-Clause |
def from_predictions(
cls,
y_true,
y_pred,
*,
labels=None,
sample_weight=None,
normalize=None,
display_labels=None,
include_values=True,
xticks_rotation="horizontal",
values_format=None,
cmap="viridis",
ax=None,
... | Plot Confusion Matrix given true and predicted labels.
For general information regarding `scikit-learn` visualization tools, see
the :ref:`Visualization Guide <visualizations>`.
For guidance on interpreting these plots, refer to the
:ref:`Model Evaluation Guide <confusion_matrix>`.
... | from_predictions | python | scikit-learn/scikit-learn | sklearn/metrics/_plot/confusion_matrix.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/metrics/_plot/confusion_matrix.py | BSD-3-Clause |
def from_estimator(
cls,
estimator,
X,
y,
*,
sample_weight=None,
drop_intermediate=True,
response_method="auto",
pos_label=None,
name=None,
ax=None,
**kwargs,
):
"""Plot DET curve given an estimator and data.
... | Plot DET curve given an estimator and data.
For general information regarding `scikit-learn` visualization tools, see
the :ref:`Visualization Guide <visualizations>`.
For guidance on interpreting these plots, refer to the
:ref:`Model Evaluation Guide <det_curve>`.
.. versionadd... | from_estimator | python | scikit-learn/scikit-learn | sklearn/metrics/_plot/det_curve.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/metrics/_plot/det_curve.py | BSD-3-Clause |
def from_predictions(
cls,
y_true,
y_pred,
*,
sample_weight=None,
drop_intermediate=True,
pos_label=None,
name=None,
ax=None,
**kwargs,
):
"""Plot the DET curve given the true and predicted labels.
For general informati... | Plot the DET curve given the true and predicted labels.
For general information regarding `scikit-learn` visualization tools, see
the :ref:`Visualization Guide <visualizations>`.
For guidance on interpreting these plots, refer to the
:ref:`Model Evaluation Guide <det_curve>`.
.... | from_predictions | python | scikit-learn/scikit-learn | sklearn/metrics/_plot/det_curve.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/metrics/_plot/det_curve.py | BSD-3-Clause |
def plot(self, ax=None, *, name=None, **kwargs):
"""Plot visualization.
Parameters
----------
ax : matplotlib axes, default=None
Axes object to plot on. If `None`, a new figure and axes is
created.
name : str, default=None
Name of DET curve f... | Plot visualization.
Parameters
----------
ax : matplotlib axes, default=None
Axes object to plot on. If `None`, a new figure and axes is
created.
name : str, default=None
Name of DET curve for labeling. If `None`, use `estimator_name` if
... | plot | python | scikit-learn/scikit-learn | sklearn/metrics/_plot/det_curve.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/metrics/_plot/det_curve.py | BSD-3-Clause |
def plot(
self,
ax=None,
*,
name=None,
plot_chance_level=False,
chance_level_kw=None,
despine=False,
**kwargs,
):
"""Plot visualization.
Extra keyword arguments will be passed to matplotlib's `plot`.
Parameters
-------... | Plot visualization.
Extra keyword arguments will be passed to matplotlib's `plot`.
Parameters
----------
ax : Matplotlib Axes, default=None
Axes object to plot on. If `None`, a new figure and axes is
created.
name : str, default=None
Name of... | plot | python | scikit-learn/scikit-learn | sklearn/metrics/_plot/precision_recall_curve.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/metrics/_plot/precision_recall_curve.py | BSD-3-Clause |
def from_estimator(
cls,
estimator,
X,
y,
*,
sample_weight=None,
drop_intermediate=False,
response_method="auto",
pos_label=None,
name=None,
ax=None,
plot_chance_level=False,
chance_level_kw=None,
despine=Fal... | Plot precision-recall curve given an estimator and some data.
For general information regarding `scikit-learn` visualization tools, see
the :ref:`Visualization Guide <visualizations>`.
For guidance on interpreting these plots, refer to the :ref:`Model
Evaluation Guide <precision_recall_... | from_estimator | python | scikit-learn/scikit-learn | sklearn/metrics/_plot/precision_recall_curve.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/metrics/_plot/precision_recall_curve.py | BSD-3-Clause |
def from_predictions(
cls,
y_true,
y_pred,
*,
sample_weight=None,
drop_intermediate=False,
pos_label=None,
name=None,
ax=None,
plot_chance_level=False,
chance_level_kw=None,
despine=False,
**kwargs,
):
""... | Plot precision-recall curve given binary class predictions.
For general information regarding `scikit-learn` visualization tools, see
the :ref:`Visualization Guide <visualizations>`.
For guidance on interpreting these plots, refer to the :ref:`Model
Evaluation Guide <precision_recall_f_... | from_predictions | python | scikit-learn/scikit-learn | sklearn/metrics/_plot/precision_recall_curve.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/metrics/_plot/precision_recall_curve.py | BSD-3-Clause |
def plot(
self,
ax=None,
*,
kind="residual_vs_predicted",
scatter_kwargs=None,
line_kwargs=None,
):
"""Plot visualization.
Extra keyword arguments will be passed to matplotlib's ``plot``.
Parameters
----------
ax : matplotlib ... | Plot visualization.
Extra keyword arguments will be passed to matplotlib's ``plot``.
Parameters
----------
ax : matplotlib axes, default=None
Axes object to plot on. If `None`, a new figure and axes is
created.
kind : {"actual_vs_predicted", "residual_v... | plot | python | scikit-learn/scikit-learn | sklearn/metrics/_plot/regression.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/metrics/_plot/regression.py | BSD-3-Clause |
def from_estimator(
cls,
estimator,
X,
y,
*,
kind="residual_vs_predicted",
subsample=1_000,
random_state=None,
ax=None,
scatter_kwargs=None,
line_kwargs=None,
):
"""Plot the prediction error given a regressor and some da... | Plot the prediction error given a regressor and some data.
For general information regarding `scikit-learn` visualization tools,
read more in the :ref:`Visualization Guide <visualizations>`.
For details regarding interpreting these plots, refer to the
:ref:`Model Evaluation Guide <visua... | from_estimator | python | scikit-learn/scikit-learn | sklearn/metrics/_plot/regression.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/metrics/_plot/regression.py | BSD-3-Clause |
def from_predictions(
cls,
y_true,
y_pred,
*,
kind="residual_vs_predicted",
subsample=1_000,
random_state=None,
ax=None,
scatter_kwargs=None,
line_kwargs=None,
):
"""Plot the prediction error given the true and predicted targets... | Plot the prediction error given the true and predicted targets.
For general information regarding `scikit-learn` visualization tools,
read more in the :ref:`Visualization Guide <visualizations>`.
For details regarding interpreting these plots, refer to the
:ref:`Model Evaluation Guide <... | from_predictions | python | scikit-learn/scikit-learn | sklearn/metrics/_plot/regression.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/metrics/_plot/regression.py | BSD-3-Clause |
def plot(
self,
ax=None,
*,
name=None,
curve_kwargs=None,
plot_chance_level=False,
chance_level_kw=None,
despine=False,
**kwargs,
):
"""Plot visualization.
Parameters
----------
ax : matplotlib axes, default=Non... | Plot visualization.
Parameters
----------
ax : matplotlib axes, default=None
Axes object to plot on. If `None`, a new figure and axes is
created.
name : str or list of str, default=None
Name for labeling legend entries. The number of legend entries
... | plot | python | scikit-learn/scikit-learn | sklearn/metrics/_plot/roc_curve.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/metrics/_plot/roc_curve.py | BSD-3-Clause |
def from_estimator(
cls,
estimator,
X,
y,
*,
sample_weight=None,
drop_intermediate=True,
response_method="auto",
pos_label=None,
name=None,
ax=None,
curve_kwargs=None,
plot_chance_level=False,
chance_level_kw... | Create a ROC Curve display from an estimator.
For general information regarding `scikit-learn` visualization tools,
see the :ref:`Visualization Guide <visualizations>`.
For guidance on interpreting these plots, refer to the :ref:`Model
Evaluation Guide <roc_metrics>`.
Parameter... | from_estimator | python | scikit-learn/scikit-learn | sklearn/metrics/_plot/roc_curve.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/metrics/_plot/roc_curve.py | BSD-3-Clause |
def from_cv_results(
cls,
cv_results,
X,
y,
*,
sample_weight=None,
drop_intermediate=True,
response_method="auto",
pos_label=None,
ax=None,
name=None,
curve_kwargs=None,
plot_chance_level=False,
chance_level_... | Create a multi-fold ROC curve display given cross-validation results.
.. versionadded:: 1.7
Parameters
----------
cv_results : dict
Dictionary as returned by :func:`~sklearn.model_selection.cross_validate`
using `return_estimator=True` and `return_indices=True` ... | from_cv_results | python | scikit-learn/scikit-learn | sklearn/metrics/_plot/roc_curve.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/metrics/_plot/roc_curve.py | BSD-3-Clause |
def test_display_curve_error_classifier(pyplot, data, data_binary, Display):
"""Check that a proper error is raised when only binary classification is
supported."""
X, y = data
X_binary, y_binary = data_binary
clf = DecisionTreeClassifier().fit(X, y)
# Case 1: multiclass classifier with multicl... | Check that a proper error is raised when only binary classification is
supported. | test_display_curve_error_classifier | python | scikit-learn/scikit-learn | sklearn/metrics/_plot/tests/test_common_curve_display.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/metrics/_plot/tests/test_common_curve_display.py | BSD-3-Clause |
def test_display_curve_error_regression(pyplot, data_binary, Display):
"""Check that we raise an error with regressor."""
# Case 1: regressor
X, y = data_binary
regressor = DecisionTreeRegressor().fit(X, y)
msg = "Expected 'estimator' to be a binary classifier. Got DecisionTreeRegressor"
with ... | Check that we raise an error with regressor. | test_display_curve_error_regression | python | scikit-learn/scikit-learn | sklearn/metrics/_plot/tests/test_common_curve_display.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/metrics/_plot/tests/test_common_curve_display.py | BSD-3-Clause |
def test_display_curve_error_no_response(
pyplot,
data_binary,
response_method,
msg,
Display,
):
"""Check that a proper error is raised when the response method requested
is not defined for the given trained classifier."""
X, y = data_binary
class MyClassifier(ClassifierMixin, BaseE... | Check that a proper error is raised when the response method requested
is not defined for the given trained classifier. | test_display_curve_error_no_response | python | scikit-learn/scikit-learn | sklearn/metrics/_plot/tests/test_common_curve_display.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/metrics/_plot/tests/test_common_curve_display.py | BSD-3-Clause |
def test_display_curve_estimator_name_multiple_calls(
pyplot,
data_binary,
Display,
constructor_name,
):
"""Check that passing `name` when calling `plot` will overwrite the original name
in the legend."""
X, y = data_binary
clf_name = "my hand-crafted name"
clf = LogisticRegression()... | Check that passing `name` when calling `plot` will overwrite the original name
in the legend. | test_display_curve_estimator_name_multiple_calls | python | scikit-learn/scikit-learn | sklearn/metrics/_plot/tests/test_common_curve_display.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/metrics/_plot/tests/test_common_curve_display.py | BSD-3-Clause |
def test_display_curve_not_fitted_errors_old_name(pyplot, data_binary, clf, Display):
"""Check that a proper error is raised when the classifier is not
fitted."""
X, y = data_binary
# clone since we parametrize the test and the classifier will be fitted
# when testing the second and subsequent plott... | Check that a proper error is raised when the classifier is not
fitted. | test_display_curve_not_fitted_errors_old_name | python | scikit-learn/scikit-learn | sklearn/metrics/_plot/tests/test_common_curve_display.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/metrics/_plot/tests/test_common_curve_display.py | BSD-3-Clause |
def test_display_curve_not_fitted_errors(pyplot, data_binary, clf, Display):
"""Check that a proper error is raised when the classifier is not fitted."""
X, y = data_binary
# clone since we parametrize the test and the classifier will be fitted
# when testing the second and subsequent plotting function
... | Check that a proper error is raised when the classifier is not fitted. | test_display_curve_not_fitted_errors | python | scikit-learn/scikit-learn | sklearn/metrics/_plot/tests/test_common_curve_display.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/metrics/_plot/tests/test_common_curve_display.py | BSD-3-Clause |
def test_display_curve_n_samples_consistency(pyplot, data_binary, Display):
"""Check the error raised when `y_pred` or `sample_weight` have inconsistent
length."""
X, y = data_binary
classifier = DecisionTreeClassifier().fit(X, y)
msg = "Found input variables with inconsistent numbers of samples"
... | Check the error raised when `y_pred` or `sample_weight` have inconsistent
length. | test_display_curve_n_samples_consistency | python | scikit-learn/scikit-learn | sklearn/metrics/_plot/tests/test_common_curve_display.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/metrics/_plot/tests/test_common_curve_display.py | BSD-3-Clause |
def test_display_curve_error_pos_label(pyplot, data_binary, Display):
"""Check consistence of error message when `pos_label` should be specified."""
X, y = data_binary
y = y + 10
classifier = DecisionTreeClassifier().fit(X, y)
y_pred = classifier.predict_proba(X)[:, -1]
msg = r"y_true takes val... | Check consistence of error message when `pos_label` should be specified. | test_display_curve_error_pos_label | python | scikit-learn/scikit-learn | sklearn/metrics/_plot/tests/test_common_curve_display.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/metrics/_plot/tests/test_common_curve_display.py | BSD-3-Clause |
def test_classifier_display_curve_named_constructor_return_type(
pyplot, data_binary, Display, constructor
):
"""Check that named constructors return the correct type when subclassed.
Non-regression test for:
https://github.com/scikit-learn/scikit-learn/pull/27675
"""
X, y = data_binary
# ... | Check that named constructors return the correct type when subclassed.
Non-regression test for:
https://github.com/scikit-learn/scikit-learn/pull/27675
| test_classifier_display_curve_named_constructor_return_type | python | scikit-learn/scikit-learn | sklearn/metrics/_plot/tests/test_common_curve_display.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/metrics/_plot/tests/test_common_curve_display.py | BSD-3-Clause |
def test_confusion_matrix_display_validation(pyplot):
"""Check that we raise the proper error when validating parameters."""
X, y = make_classification(
n_samples=100, n_informative=5, n_classes=5, random_state=0
)
with pytest.raises(NotFittedError):
ConfusionMatrixDisplay.from_estimato... | Check that we raise the proper error when validating parameters. | test_confusion_matrix_display_validation | python | scikit-learn/scikit-learn | sklearn/metrics/_plot/tests/test_confusion_matrix_display.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/metrics/_plot/tests/test_confusion_matrix_display.py | BSD-3-Clause |
def test_confusion_matrix_display_custom_labels(
pyplot, constructor_name, with_labels, with_display_labels
):
"""Check the resulting plot when labels are given."""
n_classes = 5
X, y = make_classification(
n_samples=100, n_informative=5, n_classes=n_classes, random_state=0
)
classifier ... | Check the resulting plot when labels are given. | test_confusion_matrix_display_custom_labels | python | scikit-learn/scikit-learn | sklearn/metrics/_plot/tests/test_confusion_matrix_display.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/metrics/_plot/tests/test_confusion_matrix_display.py | BSD-3-Clause |
def test_confusion_matrix_display(pyplot, constructor_name):
"""Check the behaviour of the default constructor without using the class
methods."""
n_classes = 5
X, y = make_classification(
n_samples=100, n_informative=5, n_classes=n_classes, random_state=0
)
classifier = SVC().fit(X, y)
... | Check the behaviour of the default constructor without using the class
methods. | test_confusion_matrix_display | python | scikit-learn/scikit-learn | sklearn/metrics/_plot/tests/test_confusion_matrix_display.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/metrics/_plot/tests/test_confusion_matrix_display.py | BSD-3-Clause |
def test_confusion_matrix_contrast(pyplot):
"""Check that the text color is appropriate depending on background."""
cm = np.eye(2) / 2
disp = ConfusionMatrixDisplay(cm, display_labels=[0, 1])
disp.plot(cmap=pyplot.cm.gray)
# diagonal text is black
assert_allclose(disp.text_[0, 0].get_color(), ... | Check that the text color is appropriate depending on background. | test_confusion_matrix_contrast | python | scikit-learn/scikit-learn | sklearn/metrics/_plot/tests/test_confusion_matrix_display.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/metrics/_plot/tests/test_confusion_matrix_display.py | BSD-3-Clause |
def test_confusion_matrix_pipeline(pyplot, clf):
"""Check the behaviour of the plotting with more complex pipeline."""
n_classes = 5
X, y = make_classification(
n_samples=100, n_informative=5, n_classes=n_classes, random_state=0
)
with pytest.raises(NotFittedError):
ConfusionMatrixDi... | Check the behaviour of the plotting with more complex pipeline. | test_confusion_matrix_pipeline | python | scikit-learn/scikit-learn | sklearn/metrics/_plot/tests/test_confusion_matrix_display.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/metrics/_plot/tests/test_confusion_matrix_display.py | BSD-3-Clause |
def test_confusion_matrix_with_unknown_labels(pyplot, constructor_name):
"""Check that when labels=None, the unique values in `y_pred` and `y_true`
will be used.
Non-regression test for:
https://github.com/scikit-learn/scikit-learn/pull/18405
"""
n_classes = 5
X, y = make_classification(
... | Check that when labels=None, the unique values in `y_pred` and `y_true`
will be used.
Non-regression test for:
https://github.com/scikit-learn/scikit-learn/pull/18405
| test_confusion_matrix_with_unknown_labels | python | scikit-learn/scikit-learn | sklearn/metrics/_plot/tests/test_confusion_matrix_display.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/metrics/_plot/tests/test_confusion_matrix_display.py | BSD-3-Clause |
def test_colormap_max(pyplot):
"""Check that the max color is used for the color of the text."""
gray = pyplot.get_cmap("gray", 1024)
confusion_matrix = np.array([[1.0, 0.0], [0.0, 1.0]])
disp = ConfusionMatrixDisplay(confusion_matrix)
disp.plot(cmap=gray)
color = disp.text_[1, 0].get_color()
... | Check that the max color is used for the color of the text. | test_colormap_max | python | scikit-learn/scikit-learn | sklearn/metrics/_plot/tests/test_confusion_matrix_display.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/metrics/_plot/tests/test_confusion_matrix_display.py | BSD-3-Clause |
def test_im_kw_adjust_vmin_vmax(pyplot):
"""Check that im_kw passes kwargs to imshow"""
confusion_matrix = np.array([[0.48, 0.04], [0.08, 0.4]])
disp = ConfusionMatrixDisplay(confusion_matrix)
disp.plot(im_kw=dict(vmin=0.0, vmax=0.8))
clim = disp.im_.get_clim()
assert clim[0] == pytest.approx(... | Check that im_kw passes kwargs to imshow | test_im_kw_adjust_vmin_vmax | python | scikit-learn/scikit-learn | sklearn/metrics/_plot/tests/test_confusion_matrix_display.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/metrics/_plot/tests/test_confusion_matrix_display.py | BSD-3-Clause |
def test_confusion_matrix_text_kw(pyplot):
"""Check that text_kw is passed to the text call."""
font_size = 15.0
X, y = make_classification(random_state=0)
classifier = SVC().fit(X, y)
# from_estimator passes the font size
disp = ConfusionMatrixDisplay.from_estimator(
classifier, X, y, ... | Check that text_kw is passed to the text call. | test_confusion_matrix_text_kw | python | scikit-learn/scikit-learn | sklearn/metrics/_plot/tests/test_confusion_matrix_display.py | https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/metrics/_plot/tests/test_confusion_matrix_display.py | BSD-3-Clause |
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_legend_label(
pyplot, data_binary, name, curve_kwargs
):
"""Check legend label correct with all `curve_kwargs`, `name` combinations."""
X, y = data_binary
n_cv = 3
cv_results = cross_validate(
LogisticRegression(), X, y, cv=n_cv, return_estimator=True, retu... | Check legend label correct with all `curve_kwargs`, `name` combinations. | test_roc_curve_from_cv_results_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_roc_curve_display_default_labels(
pyplot, roc_auc, name, curve_kwargs, expected_labels
):
"""Check the default labels used in the display."""
fpr = [np.array([0, 0.5, 1]), np.array([0, 0.3, 1])]
tpr = [np.array([0, 0.5, 1]), np.array([0, 0.3, 1])]
disp = RocCurveDisplay(fpr=fpr, tpr=tpr, ro... | Check the default labels used in the display. | test_roc_curve_display_default_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_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 |
Subsets and Splits
Django Code with Docstrings
Filters Python code examples from Django repository that contain Django-related code, helping identify relevant code snippets for understanding Django framework usage patterns.
SQL Console for Shuu12121/python-treesitter-filtered-datasetsV2
Retrieves Python code examples from Django repository that contain 'django' in the code, which helps identify Django-specific code snippets but provides limited analytical insights beyond basic filtering.
SQL Console for Shuu12121/python-treesitter-filtered-datasetsV2
Retrieves specific code examples from the Flask repository but doesn't provide meaningful analysis or patterns beyond basic data retrieval.
HTTPX Repo Code and Docstrings
Retrieves specific code examples from the httpx repository, which is useful for understanding how particular libraries are used but doesn't provide broader analytical insights about the dataset.
Requests Repo Docstrings & Code
Retrieves code examples with their docstrings and file paths from the requests repository, providing basic filtering but limited analytical value beyond finding specific code samples.
Quart Repo Docstrings & Code
Retrieves code examples with their docstrings from the Quart repository, providing basic code samples but offering limited analytical value for understanding broader patterns or relationships in the dataset.