Exemplo n.º 1
0
def test_make_blobs_n_samples_list(setup):
    n_samples = [50, 30, 20]
    X, y = make_blobs(n_samples=n_samples, n_features=2, random_state=0)
    X, y = mt.ExecutableTuple((X, y)).execute().fetch()

    assert X.shape == (sum(n_samples), 2)
    assert all(np.bincount(y, minlength=len(n_samples)) == n_samples) is True
Exemplo n.º 2
0
    def testMakeBlobsNSamplesList(self):
        n_samples = [50, 30, 20]
        X, y = make_blobs(n_samples=n_samples, n_features=2, random_state=0)
        X, y = mt.ExecutableTuple((X, y)).execute()

        self.assertEqual(X.shape, (sum(n_samples), 2), "X shape mismatch")
        self.assertTrue(
            all(np.bincount(y, minlength=len(n_samples)) == n_samples),
            "Incorrect number of samples per blob")
Exemplo n.º 3
0
def test_make_blobs_n_samples_centers_none(setup):
    for n_samples in [[5, 3, 0], np.array([5, 3, 0]), tuple([5, 3, 0])]:
        centers = None
        X, y = make_blobs(n_samples=n_samples, centers=centers, random_state=0)
        X, y = mt.ExecutableTuple((X, y)).execute().fetch()

        assert X.shape == (sum(n_samples), 2)
        assert all(
            np.bincount(y, minlength=len(n_samples)) == n_samples) is True
Exemplo n.º 4
0
    def testMakeBlobsNSamplesCentersNone(self):
        for n_samples in [[5, 3, 0], np.array([5, 3, 0]), tuple([5, 3, 0])]:
            centers = None
            X, y = make_blobs(n_samples=n_samples,
                              centers=centers,
                              random_state=0)
            X, y = mt.ExecutableTuple((X, y)).execute()

            self.assertEqual(X.shape, (sum(n_samples), 2), "X shape mismatch")
            self.assertTrue(
                all(np.bincount(y, minlength=len(n_samples)) == n_samples),
                "Incorrect number of samples per blob")
Exemplo n.º 5
0
def test_make_blobs_n_samples_list_with_centers(setup):
    n_samples = [20, 20, 20]
    centers = np.array([[0.0, 0.0], [1.0, 1.0], [0.0, 1.0]])
    cluster_stds = np.array([0.05, 0.2, 0.4])
    X, y = make_blobs(n_samples=n_samples,
                      centers=centers,
                      cluster_std=cluster_stds,
                      random_state=0)
    X, y = mt.ExecutableTuple((X, y)).execute().fetch()

    assert X.shape == (sum(n_samples), 2)
    assert all(np.bincount(y, minlength=len(n_samples)) == n_samples) is True
    for i, (ctr, std) in enumerate(zip(centers, cluster_stds)):
        assert_almost_equal((X[y == i] - ctr).std(), std, 1, "Unexpected std")
Exemplo n.º 6
0
def test_make_blobs(setup):
    cluster_stds = np.array([0.05, 0.2, 0.4])
    cluster_centers = np.array([[0.0, 0.0], [1.0, 1.0], [0.0, 1.0]])
    X, y = make_blobs(random_state=0,
                      n_samples=50,
                      n_features=2,
                      centers=cluster_centers,
                      cluster_std=cluster_stds)
    X, y = mt.ExecutableTuple((X, y)).execute().fetch()
    assert X.shape == (50, 2)
    assert y.shape == (50, )
    assert np.unique(y).shape == (3, )
    for i, (ctr, std) in enumerate(zip(cluster_centers, cluster_stds)):
        assert_almost_equal((X[y == i] - ctr).std(), std, 1, "Unexpected std")
Exemplo n.º 7
0
 def testMakeBlobs(self):
     cluster_stds = np.array([0.05, 0.2, 0.4])
     cluster_centers = np.array([[0.0, 0.0], [1.0, 1.0], [0.0, 1.0]])
     X, y = make_blobs(random_state=0,
                       n_samples=50,
                       n_features=2,
                       centers=cluster_centers,
                       cluster_std=cluster_stds)
     X, y = mt.ExecutableTuple((X, y)).execute()
     self.assertEqual(X.shape, (50, 2), "X shape mismatch")
     self.assertEqual(y.shape, (50, ), "y shape mismatch")
     self.assertEqual(
         np.unique(y).shape, (3, ), "Unexpected number of blobs")
     for i, (ctr, std) in enumerate(zip(cluster_centers, cluster_stds)):
         assert_almost_equal((X[y == i] - ctr).std(), std, 1,
                             "Unexpected std")
Exemplo n.º 8
0
    def testMakeBlobsNSamplesListWithCenters(self):
        n_samples = [20, 20, 20]
        centers = np.array([[0.0, 0.0], [1.0, 1.0], [0.0, 1.0]])
        cluster_stds = np.array([0.05, 0.2, 0.4])
        X, y = make_blobs(n_samples=n_samples,
                          centers=centers,
                          cluster_std=cluster_stds,
                          random_state=0)
        X, y = mt.ExecutableTuple((X, y)).execute()

        self.assertEqual(X.shape, (sum(n_samples), 2), "X shape mismatch")
        self.assertTrue(
            all(np.bincount(y, minlength=len(n_samples)) == n_samples),
            "Incorrect number of samples per blob")
        for i, (ctr, std) in enumerate(zip(centers, cluster_stds)):
            assert_almost_equal((X[y == i] - ctr).std(), std, 1,
                                "Unexpected std")