Skip to content

Commit

Permalink
Use n_components=3 to test actual regression
Browse files Browse the repository at this point in the history
n_components and n_features were equal and one was used for the other in
some places.
  • Loading branch information
lesteve committed Oct 20, 2016
1 parent 55672f9 commit 4e1c101
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions sklearn/mixture/tests/test_gaussian_mixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,7 @@ def test_property():

def test_sample():
rng = np.random.RandomState(0)
rand_data = RandomData(rng, scale=7)
rand_data = RandomData(rng, scale=7, n_components=3)
n_features, n_components = rand_data.n_features, rand_data.n_components

for covar_type in COVARIANCE_TYPE:
Expand All @@ -937,7 +937,8 @@ def test_sample():
# Just to make sure the class samples correctly
n_samples = 20000
X_s, y_s = gmm.sample(n_samples)
for k in range(n_features):

for k in range(n_components):
if covar_type == 'full':
assert_array_almost_equal(gmm.covariances_[k],
np.cov(X_s[y_s == k].T), decimal=1)
Expand All @@ -954,15 +955,16 @@ def test_sample():
decimal=1)

means_s = np.array([np.mean(X_s[y_s == k], 0)
for k in range(n_features)])
for k in range(n_components)])
assert_array_almost_equal(gmm.means_, means_s, decimal=1)

# Check that sizes that are drawn match what is requested
assert_equal(X_s.shape, (n_samples, n_components))
for sample_size in range(1, 50):
X_s, _ = gmm.sample(sample_size)
assert_equal(X_s.shape, (sample_size, n_components))
# Check shapes of sampled data, see
# https://github.com/scikit-learn/scikit-learn/issues/7701
assert_equal(X_s.shape, (n_samples, n_features))

for sample_size in range(1, 100):
X_s, _ = gmm.sample(sample_size)
assert_equal(X_s.shape, (sample_size, n_features))


@ignore_warnings(category=ConvergenceWarning)
Expand Down

0 comments on commit 4e1c101

Please sign in to comment.