LogisticRegression.py 文件源码

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

项目:tinyml 作者: parasdahal 项目源码 文件源码
def compute_cost(self):
        """Computes cost based on the current values of the parameters

        Returns
        -------
        cost : float
            Cost of the selection of current set of parameters

        """
        hypothesis = LogisticRegression.sigmoid(np.dot(self.X, self.theta))
        #new ndarray to prevent intercept from theta array to be changed
        theta=np.delete(self.theta,0)
        #regularization term
        reg = (self.lamda/2*self.num_training)*np.sum(np.power(theta,2)) 
        cost = -(np.sum(self.y * np.log(hypothesis) + (1 - self.y) * (np.log(1 - hypothesis)))) / self.num_training
        #if regularization is true, add regularization term and return cost
        if self.reg:
            return cost + reg
        return cost
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号