In [4]:
def derivative_calculations(X,y_target, w1, w2, b):
    
    # initialize values to 0
    dw1 = 0
    dw2 = 0
    db = 0
    J=0
    
    m = X.shape[0] # number od elements in the training set
    
    for i in range(m): # go through examples in the training set and calculate derivatives
        zi = w1 * X[i,0] + w2*X[i,1] + b        
        ai = 1 / (1+ np.exp(-zi))        
        J += loss_function(y_target[i,0], ai) 

        dzi = ai - y_target[i,0]        
        dw1 += X[i,0] * dzi  # here we do not need a for loop over n features, because we have just two features       
        dw2 += X[i,1] * dzi        
        db += dzi
    
    # calculate average values
    J/= m
    dw1/=m
    dw2/=m
    db/=m
    
    return dw1, dw2, db, J