# Predecting age from weight and height, using neural networks

There are three parts to the question you asked.

1st part (what’s wrong with the code) Ans: There is nothing wrong as such. Just proper lr and initilization

2nd part(where to use sigmoid). Ans: Nowhere in regression.

3rd part(correct alpha): Ans: start with 1 run the model and observe loss. Make alpha=1e-1 and so on. In the entire process observe loss. Whichever alpha yields small loss, choose that.

Code for 1st part: (Make following chnages)

``````b=np.zeros((1,))
alpha=1e-5
``````

Yeah, that’s it 🙂 You may keep a list of loss for each epoch loss. I kept it for your code and got following graph. (Note I used only 50 epochs. you may keep higher values) Full Code

``````import numpy as np
import matplotlib.pyplot as plt

# weight,height,age

data=[[50,160,15],
[45,156,13],
[55,162,17],
[56,163,18],
[58,163.4,20],
[12,85,2],
[14.2,95,3],
[15.4,100,4],
[32,138.4,10],
[25.8,128.3,8]]

# missing age data
mys=[22.4,121.1]

w1=np.random.rand()
w2=np.random.rand()
b=0
alpha=0.00001

loss = []
for i in range(50):
ri=np.random.randint(len(data))
point=data[ri]

pred=(point*w1)+(point*w2)+b
target=point
cost=(pred-target)**2

dcost_pred=2*(pred-target)
dpred_w1=point
dpred_w2=point
dpred_db=1

dcost_w1=dcost_pred*dpred_w1
dcost_w2=dcost_pred*dpred_w2
dcost_b=dcost_pred*dpred_db

w1=(w1-alpha*dcost_w1)
w2=w2-alpha*dcost_w2
b=b-alpha*dcost_b
loss.append(cost)

plt.plot(loss)
``````