Beispiel #1
0
    def test_c(self):
        clusters = np.array(
            [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 5, 5, 6, 6])

        classes = np.array(
            [1, 1, 1, 2, 2, 3, 3, 3, 1, 1, 2, 2, 2, 3, 3, 1, 2, 3, 1, 2, 3])

        assert round(cm.v_measure(clusters, classes), 2) == 0.30
        assert_almost_equal(cm.v_measure(clusters, classes),
                            sklearn.metrics.v_measure_score(classes, clusters),
                            decimal=10)
Beispiel #2
0
    def __init__(self, clusters: np.ndarray, classes: np.ndarray, aic: float,
                 bic: float, likelihood: float):
        """
        :param clusters: The cluster assignments
        :param classes: The class assignments
        :param aic: The Akaike information criterion
        :param bic: The Bayesian information criterion
        :param likelihood: The log likelihood
        """
        super().__init__(clusters, aic, bic, likelihood)

        self.N = len(classes)
        self.C = len(np.unique(classes))
        self.purity = purity(clusters, classes)
        self.purity2 = purity2(clusters, classes)
        self.rand_index = rand_index(clusters, classes)
        self.class_entropy = entropy(classes)
        self.precision = precision(clusters, classes)
        self.recall = recall(clusters, classes)
        self.f1_measure = f1_measure(clusters, classes)
        self.homogeneity = homogeneity(clusters, classes)
        self.completeness = completeness(clusters, classes)
        self.v_measure = v_measure(clusters, classes)
        self.nv_measure = nv_measure(clusters, classes)
        self.mutual_information = mutual_information(clusters, classes)
        self.normalized_mutual_information = normalized_mutual_information(
            clusters, classes)
        self.normalized_mutual_information2 = normalized_mutual_information2(
            clusters, classes)
Beispiel #3
0
    def test_d(self):
        clusters = np.array(
            [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 5, 6, 7, 8, 9])

        classes = np.array(
            [1, 1, 1, 2, 2, 3, 3, 3, 1, 1, 2, 2, 2, 3, 3, 1, 2, 3, 1, 2, 3])

        assert round(cm.v_measure(clusters, classes), 2) == 0.41
        assert_almost_equal(cm.v_measure(clusters, classes),
                            sklearn.metrics.v_measure_score(classes, clusters),
                            decimal=10)
        assert_raises(AssertionError,
                      assert_almost_equal,
                      cm.v_measure(clusters, classes),
                      cm.nv_measure(clusters, classes),
                      decimal=10)