splitter.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:decision-tree-id3 作者: svaante 项目源码 文件源码
def _entropy(self, y, return_class_counts=False):
        """ Entropy for the classes in the array y
        :math: \sum_{x \in X} p(x) \log_{2}(1/p(x)) :math: from
        https://en.wikipedia.org/wiki/ID3_algorithm

        Parameters
        ----------
        y : nparray of shape [n remaining attributes]
            containing the class names

        Returns
        -------
        : float
            information for remaining examples given feature
        """
        n = y.shape[0]
        if n <= 0:
            return 0
        classes, count = unique(y)
        p = np.true_divide(count, n)
        res = np.abs(np.sum(np.multiply(p, np.log2(p))))
        if return_class_counts:
            return res, np.vstack((classes, count)).T
        else:
            return res
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号