DCA.py 文件源码

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

项目:ml_defense 作者: arjunbhagoji 项目源码 文件源码
def _get_Smatrices(self, X, y):

        Sb = np.zeros((X.shape[1], X.shape[1]))

        S = np.inner(X.T, X.T)
        N = len(X)
        mu = np.mean(X, axis=0)
        classLabels = np.unique(y)
        for label in classLabels:
            classIdx = np.argwhere(y == label).T[0]
            Nl = len(classIdx)
            xL = X[classIdx]
            muL = np.mean(xL, axis=0)
            muLbar = muL - mu
            Sb = Sb + Nl * np.outer(muLbar, muLbar)

        Sbar = S - N * np.outer(mu, mu)
        Sw = Sbar - Sb
        self.mean_ = mu

        return (Sw, Sb)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号