# Logistic Regression python code

**URL:** <https://community.deeplearning.ai/t/logistic-regression-python-code/32022>\
**Category:** Neural Networks and Deep Learning\
**Tags:** coursera-platform\
**Created:** [August 30, 2021, 9:39am UTC](https://community.deeplearning.ai/t/logistic-regression-python-code/32022 "2021-08-30T09:39:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![USharma](https://avatars.discourse-cdn.com/v4/letter/u/57b2e6/32.png) [@USharma](https://community.deeplearning.ai/u/USharma)\
**Post date:** [August 30, 2021, 9:39am UTC](https://community.deeplearning.ai/t/logistic-regression-python-code/32022/1 "2021-08-30T09:39:55Z")

</div>

I have used the dataset of cats vs dogs to train my logistic regression model but I am getting wrong output (I don’t know the implementation of CNN so I used logistic regression). Please review my code. If there is any error please tell me else give me suggestions to improve code and style.

link to dataset: [Download Kaggle Cats and Dogs Dataset from Official Microsoft Download Center](https://www.microsoft.com/en-us/download/details.aspx?id=54765)  
link to code: [Logistic regression, some error - Pastebin.com](https://pastebin.com/GEdjWztS)

---

<div class="post-metadata">

**Author:** ![thearkamitra](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/thearkamitra/32/29965_2.png) [@thearkamitra](https://community.deeplearning.ai/u/thearkamitra)\
**Post date:** [September 1, 2021, 9:29am UTC](https://community.deeplearning.ai/t/logistic-regression-python-code/32022/2 "2021-09-01T09:29:31Z")

</div>

Hi,

Thank you for pasting the code! Could you paste the error as well? It would help to pinpoint the error location more easily!

---

<div class="post-metadata">

**Author:** ![USharma](https://avatars.discourse-cdn.com/v4/letter/u/57b2e6/32.png) [@USharma](https://community.deeplearning.ai/u/USharma)\
**Post date:** [September 6, 2021, 2:50pm UTC](https://community.deeplearning.ai/t/logistic-regression-python-code/32022/3 "2021-09-06T14:50:58Z")

</div>

Sorry for the late reply, but the code is giving 0 for dog and 1 for cat which is opposite of what it should be. I am not able to understand if there is some logic error in code or I am understanding it incorrectly or is Logistic Regression not great with images.

---

<div class="post-metadata">

**Author:** ![thearkamitra](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/thearkamitra/32/29965_2.png) [@thearkamitra](https://community.deeplearning.ai/u/thearkamitra)\
**Post date:** [September 8, 2021, 7:44am UTC](https://community.deeplearning.ai/t/logistic-regression-python-code/32022/4 "2021-09-08T07:44:13Z")

</div>

Did you try for many images?  
Or is it just for one image?  
I am not sure what the issue is actually…

---

<div class="post-metadata">

**Author:** ![USharma](https://avatars.discourse-cdn.com/v4/letter/u/57b2e6/32.png) [@USharma](https://community.deeplearning.ai/u/USharma)\
**Post date:** [September 17, 2021, 6:15am UTC](https://community.deeplearning.ai/t/logistic-regression-python-code/32022/5 "2021-09-17T06:15:22Z")

</div>

Thank you for your help! Apparently the images were not loading properly and thus the output was not correct. I changed the pictures and tested on 200 new cat images and the model got around 60% correct labels and around 64 % on 200 dog images. It was totally my mistake for not checking if the images were loading properly.
