Does vectorization something has to to with accuracy?

I create training loop (without regularization) using vector algebra, I am getting .85% score and sklearn logistic regression classifier giving 0.83 score.

image

image

The code I am using is related to the graded assignment, Can I send this in the private message? I need to check if I have implemented correctly or not

Maybe I misunderstood the thread title, but the choice of explicit loops versus vectorization shouldn’t alter the accuracy of the model’s predictions. Rather, vectorization allows you to take advantage of the builtin language data structures and algorithms to improve compute performance and reduce the likelihood of loop control errors in your hand written code. The motivation is it that it runs faster with fewer lines of programmer written code, not that it produces different results. Does this make sense?

1 Like

Yeah I think the same, but here output differs. So I think, I miscalculated something :sweat_smile:

1 Like

I’ve been involved with the deeplearning Coursera classes for 6 years, most of that time as an official mentor, now just lurking. Loop control is one of the most common (and sometimes hardest to self diagnose) errors people ask about. Vectorization is your friend, use it whenever you can :+1:

1 Like

Are you the DL.AI team? Just to confirm, can I DM to show you the functions I created. Need to verify if they are correct. I just dont want to leak the code here in the public discussion forum. I can’t see the mentor badge on your account, so dont know if you are legit team member or not :sweat_smile:

No longer an official mentor and never have been an employee of DLAI. I’m retired and live on a farm so reading these forums and answering some questions keeps my brain from melting away entirely. If you decide to message your code, I won’t ‘fix’ it for you, but would be glad to offer some thoughts on how to find and fix the errors yourself. Since I’m not enrolled in the MLS classes, and it sounds like you’re going off piste anyway, I think it does not violate the honor code, but your call.

Thanks. Thats all I look for. No fixing, I will do on my own, I just need guidance.

scikit learn’s optimization method may use different stopping criteria than the method you coded yourself.

The difference between scores of 0.85 and 0.83 is likely of little practical significance.

2 Likes

I ran the OP code on my Mac M1 and found that sometimes the accuracy matches exactly, and sometimes it doesn’t but is close (second decimal point varies). I haven’t looked at the sklearn implementation, but my guess is there is something different between the two that is sensitive to initial conditions and specific values since there is dataset shuffle in this code. Concur that if the OP’s implementation was grossly wrong the two outputs would not likely be close, even less to match sometimes.

1 Like

Yeah we can try with fixed initializer and disable shuffling on the train test split to have reproducible results