<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 note
Didn't mean to generalize NN here. Just plow through this 400&gt;25&gt;10 setup to get the feeling of NN
Step1:  prepare data
Step2:  
Step3:  load weight
Step4:  feed forward
(400 + 1) -> (25 + 1) -> (10)
<img style="float
Step5:  cost function
<img style="float
Step6:  regularized cost function
<img style="float
<ASSISTANT_TASK:>
Python Code:
%reload_ext autoreload
%autoreload 2
import sys
sys.path.append('..')
from helper import nn
from helper import logistic_regression as lr
import numpy as np
Explanation: note
Didn't mean to generalize NN here. Just plow through this 400&gt;25&gt;10 setup to get the feeling of NN
End of explanation
X_raw, y_raw = nn.load_data('ex4data1.mat', transpose=False)
X = np.insert(X_raw, 0, np.ones(X_raw.shape[0]), axis=1)
X.shape
Explanation: prepare data
End of explanation
y_raw
y = nn.expand_y(y_raw)
y
Explanation: 
End of explanation
t1, t2 = nn.load_weight('ex4weights.mat')
t1.shape, t2.shape
theta = nn.serialize(t1, t2)  # flatten params
theta.shape
Explanation: load weight
End of explanation
_, _, _, _, h = nn.feed_forward(theta, X)
h # 5000*10
Explanation: feed forward
(400 + 1) -> (25 + 1) -> (10)
<img style="float: left;" src="../img/nn_model.png">
End of explanation
nn.cost(theta, X, y)
Explanation: cost function
<img style="float: left;" src="../img/nn_cost.png">
think about this, now we have $y$ and $h_{\theta} \in R^{5000 \times 10}$
If you just ignore the m and k dimention, pairwisely this computation is trivial.
the eqation $= ylog(h_{\theta}) - (1-y)log(1-h_{\theta})$
all you need to do after pairwise computation is sums this 2d array up and divided by m
End of explanation
nn.regularized_cost(theta, X, y)
Explanation: regularized cost function
<img style="float: left;" src="../img/nn_regcost.png">
the first column of t1 and t2 is intercept $\theta$, just forget them when you do regularization
End of explanation
<END_TASK>