def fit(self, X, y):
        if self.method is 'mi':
            self._weights = mutual_information(X, y)
        elif self.method is 'pmi':
            self._weights = pointwise_mutual_information(X, y, normalize=False)
        elif self.method is 'npmi':
            self._weights = pointwise_mutual_information(X, y, normalize=True)
        elif self.method is 'ppmi_exp':
            self._weights = pointwise_mutual_information(X,
                                                         y,
                                                         normalize=True,
                                                         positive='exp')
        elif self.method is 'pmi_k':
            self._weights = pointwise_mutual_information(X,
                                                         y,
                                                         normalize=True,
                                                         k_weight=self.pmi_k)
        elif self.method is 'ppmi':
            self._weights = pointwise_mutual_information(X,
                                                         y,
                                                         normalize=False,
                                                         positive='cutoff')
        elif self.method is 'cp_raw':
            self._weights = conditional_probabilities(X, y, ratio=False)
        elif self.method is 'cp_ratio':
            self._weights = conditional_probabilities(X, y, ratio=True)
        else:
            raise ValueError

        return self
    def test_pointwise_mutual_information(self):
        X = array([[0, 1], [1, 0], [1, 1]])
        y = array([[0, 1], [1, 0], [1, 0]])

        assert_array_approx_equal(pointwise_mutual_information(X, y),
                                  [0.1178, 0.1178],
                                  decimal=3)
        assert_array_approx_equal(pointwise_mutual_information(
            csr_matrix(X), csr_matrix(y)), [0.1178, 0.1178],
                                  decimal=3)
    def test_pointwise_mutual_information(self):
        X = array([[0, 1],
                   [1, 0],
                   [1, 1]])
        y = array([[0, 1],
                   [1, 0],
                   [1, 0]])

        assert_array_approx_equal(pointwise_mutual_information(X, y), [0.1178, 0.1178], decimal=3)
        assert_array_approx_equal(pointwise_mutual_information(csr_matrix(X), csr_matrix(y)),
                                  [0.1178, 0.1178], decimal=3)
    def fit(self, X, y):
        if self.method is 'mi':
            self._weights = mutual_information(X, y)
        elif self.method is 'pmi':
            self._weights = pointwise_mutual_information(X, y, normalize=False)
        elif self.method is 'npmi':
            self._weights = pointwise_mutual_information(X, y, normalize=True)
        elif self.method is 'ppmi_exp':
            self._weights = pointwise_mutual_information(X, y, normalize=True, positive='exp')
        elif self.method is 'pmi_k':
            self._weights = pointwise_mutual_information(X, y, normalize=True, k_weight=self.pmi_k)
        elif self.method is 'ppmi':
            self._weights = pointwise_mutual_information(X, y, normalize=False, positive='cutoff')
        elif self.method is 'cp_raw':
            self._weights = conditional_probabilities(X, y, ratio=False)
        elif self.method is 'cp_ratio':
            self._weights = conditional_probabilities(X, y, ratio=True)
        else:
            raise ValueError

        return self