예제 #1
0
    def test_instance_validation(self):

        clf = self.Clusterer()
        scikitplot.clustering_factory(clf)

        not_clf = self.NotClusterer()
        self.assertRaises(TypeError, scikitplot.clustering_factory, not_clf)
예제 #2
0
    def test_instance_validation(self):

        clf = self.Clusterer()
        scikitplot.clustering_factory(clf)

        not_clf = self.NotClusterer()
        self.assertRaises(TypeError, scikitplot.clustering_factory, not_clf)
예제 #3
0
 def test_copy(self):
     np.random.seed(0)
     clf = KMeans()
     scikitplot.clustering_factory(clf)
     ax = clf.plot_silhouette(self.X)
     assert not hasattr(clf, "cluster_centers_")
     ax = clf.plot_silhouette(self.X, copy=False)
     assert hasattr(clf, "cluster_centers_")
예제 #4
0
 def test_copy(self):
     np.random.seed(0)
     clf = KMeans()
     scikitplot.clustering_factory(clf)
     ax = clf.plot_silhouette(self.X)
     assert not hasattr(clf, "cluster_centers_")
     ax = clf.plot_silhouette(self.X, copy=False)
     assert hasattr(clf, "cluster_centers_")
예제 #5
0
 def test_ax(self):
     np.random.seed(0)
     clf = KMeans()
     scikitplot.clustering_factory(clf)
     fig, ax = plt.subplots(1, 1)
     out_ax = clf.plot_silhouette(self.X)
     assert ax is not out_ax
     out_ax = clf.plot_silhouette(self.X, ax=ax)
     assert ax is out_ax
예제 #6
0
 def test_ax(self):
     np.random.seed(0)
     clf = KMeans()
     scikitplot.clustering_factory(clf)
     fig, ax = plt.subplots(1, 1)
     out_ax = clf.plot_silhouette(self.X)
     assert ax is not out_ax
     out_ax = clf.plot_silhouette(self.X, ax=ax)
     assert ax is out_ax
예제 #7
0
    def test_n_clusters_in_clf(self):
        np.random.seed(0)

        class DummyClusterer:
            def __init__(self):
                pass

            def fit(self):
                pass

            def fit_predict(self):
                pass

        clf = DummyClusterer()
        scikitplot.clustering_factory(clf)
        self.assertRaises(TypeError, clf.plot_elbow_curve, self.X)
예제 #8
0
    def test_n_clusters_in_clf(self):
        np.random.seed(0)

        class DummyClusterer:
            def __init__(self):
                pass

            def fit(self):
                pass

            def fit_predict(self):
                pass

        clf = DummyClusterer()
        scikitplot.clustering_factory(clf)
        self.assertRaises(TypeError, clf.plot_elbow_curve, self.X)
예제 #9
0
    def test_method_insertion(self):

        clf = self.Clusterer()
        scikitplot.clustering_factory(clf)
        assert hasattr(clf, 'plot_silhouette')
        assert hasattr(clf, 'plot_elbow_curve')

        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter('always')
            scikitplot.clustering_factory(clf)

            assert len(w) >= 2
            for warning in w[1:]:
                assert issubclass(warning.category, UserWarning)
                assert ' method already in clf. ' \
                       'Overriding anyway. This may ' \
                       'result in unintended behavior.' in str(warning.message)
예제 #10
0
    def test_method_insertion(self):

        clf = self.Clusterer()
        scikitplot.clustering_factory(clf)
        assert hasattr(clf, 'plot_silhouette')
        assert hasattr(clf, 'plot_elbow_curve')

        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter('always')
            scikitplot.clustering_factory(clf)

            assert len(w) == 2
            for warning in w:
                assert issubclass(warning.category, UserWarning)
                assert ' method already in clf. ' \
                       'Overriding anyway. This may ' \
                       'result in unintended behavior.' in str(warning.message)
예제 #11
0
 def test_cmap(self):
     np.random.seed(0)
     clf = KMeans()
     scikitplot.clustering_factory(clf)
     ax = clf.plot_silhouette(self.X, cmap='Spectral')
     ax = clf.plot_silhouette(self.X, cmap=plt.cm.Spectral)
예제 #12
0
 def test_cluster_ranges(self):
     np.random.seed(0)
     clf = KMeans()
     scikitplot.clustering_factory(clf)
     ax = clf.plot_elbow_curve(self.X, cluster_ranges=range(1, 10))
     ax = clf.plot_elbow_curve(self.X)
예제 #13
0
"""An example showing the plot_silhouette method used by a scikit-learn clusterer"""
from __future__ import absolute_import
import matplotlib.pyplot as plt
from scikitplot import clustering_factory
from sklearn.cluster import KMeans
from sklearn.datasets import load_iris as load_data

X, y = load_data(return_X_y=True)
kmeans = clustering_factory(KMeans(n_clusters=4, random_state=1))
kmeans.plot_silhouette(X)
plt.show()
예제 #14
0
"""An example showing the plot_silhouette method used by a scikit-learn clusterer"""
from __future__ import absolute_import
import matplotlib.pyplot as plt
from scikitplot import clustering_factory
from sklearn.cluster import KMeans
from sklearn.datasets import load_iris as load_data


X, y = load_data(return_X_y=True)
kmeans = clustering_factory(KMeans(random_state=1))
kmeans.plot_elbow_curve(X, cluster_ranges=range(1, 11))
plt.show()
예제 #15
0
 def test_cluster_ranges(self):
     np.random.seed(0)
     clf = KMeans()
     scikitplot.clustering_factory(clf)
     ax = clf.plot_elbow_curve(self.X, cluster_ranges=range(1, 10))
     ax = clf.plot_elbow_curve(self.X)
예제 #16
0
 def test_cmap(self):
     np.random.seed(0)
     clf = KMeans()
     scikitplot.clustering_factory(clf)
     ax = clf.plot_silhouette(self.X, cmap='Spectral')
     ax = clf.plot_silhouette(self.X, cmap=plt.cm.Spectral)