Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions doc/whats_new/v0.20.rst
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,11 @@ Decomposition, manifold learning and clustering
by :user:`Jan Margeta <jmargeta>`, :user:`Guillaume Lemaitre <glemaitre>`,
and :user:`Devansh D. <devanshdalal>`.

- Fixed a bug in :class:`mixture.BaseMixture` where the reported `n_iter_` was
missing an iteration. It affected :class:`mixture.GaussianMixture` and
:class:`mixture.BayesianGaussianMixture`. :issue:`10740` by :user:`Erich
Schubert <kno10>` and :user:`Guillaume Lemaitre <glemaitre>`.

Metrics

- Fixed a bug in :func:`metrics.precision_precision_recall_fscore_support`
Expand Down
2 changes: 1 addition & 1 deletion sklearn/mixture/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def fit(self, X, y=None):
self._initialize_parameters(X, random_state)
self.lower_bound_ = -np.infty

for n_iter in range(self.max_iter):
for n_iter in range(1, self.max_iter + 1):
prev_lower_bound = self.lower_bound_

log_prob_norm, log_resp = self._e_step(X)
Expand Down
2 changes: 1 addition & 1 deletion sklearn/mixture/tests/test_gaussian_mixture.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Author: Wei Xue <[email protected]>
# Thierry Guillemot <[email protected]>
# License: BSD 3 clauseimport warnings
# License: BSD 3 clause

import sys
import warnings
Expand Down
23 changes: 23 additions & 0 deletions sklearn/mixture/tests/test_mixture.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Author: Guillaume Lemaitre <[email protected]>
# License: BSD 3 clause

import pytest
import numpy as np

from sklearn.mixture import GaussianMixture
from sklearn.mixture import BayesianGaussianMixture


@pytest.mark.parametrize(
"estimator",
[GaussianMixture(),
BayesianGaussianMixture()]
)
def test_gaussian_mixture_n_iter(estimator):
# check that n_iter is the number of iteration performed.
rng = np.random.RandomState(0)
X = rng.rand(10, 5)
max_iter = 1
estimator.set_params(max_iter=max_iter)
estimator.fit(X)
assert estimator.n_iter_ == max_iter