# UNQ_C2
# GRADED FUNCTION: compute_cost
def compute_cost(X, y, w, b, *argv):
"""
Computes the cost over all examples
Args:
X : (ndarray Shape (m,n)) data, m examples by n features
y : (ndarray Shape (m,)) target value
w : (ndarray Shape (n,)) values of parameters of the model
b : (scalar) value of bias parameter of the model
*argv : unused, for compatibility with regularized version below
Returns:
total_cost : (scalar) cost
"""
m, n = X.shape
### START CODE HERE ###
total_cost = 0
for i in range(m):
z = np.dot(X[i], w)
z = np.sum(z, axis=1) + b
total_cost += -(y[i] * np.log(sigmoid(z)) - ((1 - y[i]) * np.log(1 - sigmoid(z)))
total_cost = total_cost / m
### END CODE HERE ###
return total_cost
我正在尝试定义一个计算逻辑回归模型成本的函数,但它似乎有一些问题。它在
(total_cost = total_cost / m)
上显示语法错误,但我不知道它出了什么问题
尝试获取total_cost的标量值
您在上一行中缺少结束语
)
:
total_cost += -(y[i] * np.log(sigmoid(z)) - ((1 - y[i]) * np.log(1 - sigmoid(z))))
# This is missing ---------------------------------------------------------------^