Doubt on my code

I have used the vector approach to the question can someone please check where it is wrong it is giving 95% accuracy .

def sigmoid(z):

    return 1.0/(1.0 + np.exp(-1.0*z))

def hypo(X,theta):

    return sigmoid(np.dot(X,theta))

def grad(X,Y,theta):

    m = X.shape[0]

    hy = hypo(X,theta)

    gradd = -1.0 * (np.dot(X.T,(Y - hy)))

    return gradd/m

def grad_des(X,Y,lr=0.1,max=500):

    m,n = X.shape

    theta = np.zeros((n,))

    for i in range(max):
    
        gradd = grad(X,Y,theta)

        theta = theta + (lr*gradd)

    return theta

Hey @hiten930, try to increase the number of epochs.

hello sir @S18CRX0120 , i tried incresing the epochs there was no change in the accuracy but theta values changed significantly … i need the help if you can help me with if the code is correct because the way prateek sir discussed was a different way.

Hey @hiten930, share your ipynb after saving it on google drive.

here is the link sir @S18CRX0120 , https://drive.google.com/file/d/1cEwIRTeRE3SvjoYW7NRq26rA5B8EK2pe/view?usp=sharing
… plz help me with the error function too sir.

Hey @hiten930, your code contains many mistakes, take reference from this, and try running this one on your dataset.

Happy Learning :sunny:

sir but this approach is very much different from my approach , the approach u said is not vector approach and we are considering theta[0] very differently like we have calculated b(bias) differently why can we use the approach i used in my solution. in my solution i guess only the error calculation is wrong , rest all is right(as its 95% accurate) .

Hey @hiten930, no actually the shapes are wrong if you try printing the shapes in between gradient function etc you will see that.

If you want the vectorization code, its here this code contains everything you are asking in case still any confussion lefts, feel free to contact me.

Hope this resolved your doubt.
Plz mark the doubt as resolved in my doubts section. :blush:

https://drive.google.com/file/d/1d2f6mR_mR-6umoZaQ6xOAb0RryAkvkNx/view?usp=sharing

Sir u can check this code it is same as that u shared on github.

Hey @hiten930, yes sure i checked it, it was fine, but you forgo to normalize the x_test,

X_test = pd.read_csv("./Test Cases/Logistic_X_Test.csv").values
X_test = (X_test-u)/std
ones = np.ones((X_test.shape[0],1))
X_test = np.hstack((ones,X_test))


Y_test = hypo(X_test,theta) 

This time i submitted the csv as well from your code, and i achieved 99% accuracy.(Maximum achievable accuracy).

Great jod done, Happy Learning :sunny:

Hope this resolved your doubt.
Plz mark the doubt as resolved in my doubts section :blush:

very much thank u sir , actually i was not aware that we have to normalize the x_test … Thank u so much for clearing the doubt sir.

1 Like