logistic_regression.py 文件源码

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

项目:dl4nlp 作者: yohokuno 项目源码 文件源码
def logistic_regression_cost_gradient(parameters, input, output):
    """
    Cost and gradient for logistic regression
    :param parameters: weight vector
    :param input: feature vector
    :param output: binary label (0 or 1)
    :return: cost and gradient for the input and output
    """
    prediction = expit(np.dot(input, parameters))
    if output:
        inside_log = prediction
    else:
        inside_log = 1.0 - prediction

    if inside_log != 0.0:
        cost = -np.log(inside_log)
    else:
        cost = np.finfo(float).min

    gradient = (prediction - output) * input
    return cost, gradient
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号