Question: data = [ [ 4 , 3 , 1 , 1 ] , [ 2 , 3 , 0 . 5 , 0 ] ,

data =[[4,3,1,1],
[2,3,0.5,0],
[5,4,1.2,1],
[4.5,4.5,1.1,1],
[1,2.7,0.5,0],
[1.7,2.7,0.7,0],
[3.5,3.5,1.2,1],
[2.1,2.3,0.5,0],
[2.3,2.1,0.7,0],
[3.5,3.2,1.3,1]]
mystery_Animal =[3.2,3.1,3]
def sigmoid(x):
return 1/(1+np.exp(-x))
def sigmoid_p(x):
return sigmoid(x)*(1-sigmoid(x))
def train():
w1=0.2
w2=0.1
w3=-0.6
wb =0.1
Iterations =10000
learning_rate =0.1
Costs =[]
For i in range(iterations):
ri = np.random.randint(len(data))
point = data[ri]
z = point[0]* w1+ point[1]* w2+ point[2]* w3+ b
pred = sigmoid(z)
target = point[2]
cost = np.square(pred - target)
if I %100==0:
c=0
For j in range(len(data)):
p= data[j]
p_pred = sigmoid(w1* p[0]+ w2* p[1]+ w3* p[2]+ b)
c += np.square(p_pred - p[3])
costs.append(c)
dcost_dpred =2*(pred - target)
dpred_dz = sigmoid_p(z)
dz_dw1= point[0]
dz_dw2= point[1]
dz_dw3= point[2]
dz_db =1
dcost_dz = dcost_dpred * dpred_dz
dcost_dw1= dcost_dz * dz_dw1
dcost_dw2= dcost_dz * dz_dw2
dcost_dw3= dcost_dz * dz_dw3
dz_db = dcost_dz * dz_db
w1= w1- learning_rate *dcost_dw1
w2= w2- learning_rate *dcost_dw2
w3= w3- learning_rate *dcost_dw3
b = b - learning_rate *dcost_db
return costs, w1, w2, w3, b
costs, w1, w2, w3, b = train()
z= w1*mystery_Animal[0]+ w2*mystery_Animal[1]+ w3*mystery_Animal[2]+ b
pred = sigmoid(z)
print(pred) can you fix this code I want to print the updated weights for 3 epoch also I want the graph

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!