Skip to content

Commit a467584

Browse files
committed
Notebook and helper files
1 parent db50f06 commit a467584

8 files changed

+253256
-0
lines changed

costs.py

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import numpy as np
2+
from hw_helpers import sigmoid
3+
4+
5+
def compute_mse(y, tx, w):
6+
"""
7+
Compute the mean square error.
8+
:param y: labels
9+
:param tx: features
10+
:param w: weights
11+
:return: the mean square error
12+
"""
13+
e = y - tx.dot(w)
14+
mse = e.T.dot(e) / (2 * len(e))
15+
return mse
16+
17+
18+
def calculate_loss(y, tx, w, lambda_=0):
19+
"""
20+
Compute the negative log likelihood
21+
:param y: labels
22+
:param tx: features
23+
:param w: weights
24+
:param lambda_: regularization
25+
:return: the negative log likelihood
26+
"""
27+
# ***************************************************
28+
# INSERT YOUR CODE HERE
29+
# TODO
30+
# ***************************************************
31+
return (((-1)*(y*np.log(sigmoid(tx@w))+(1-y)*np.log(1-sigmoid(tx@w)))) + lambda_/2*w.T@w).mean()
32+
33+

0 commit comments

Comments
 (0)