Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

提出“2.logistic regression”代码运行出现的报错并指出改进方法 #6

Open
WUU55 opened this issue May 31, 2022 · 0 comments

Comments

@WUU55
Copy link

WUU55 commented May 31, 2022

首先感谢你的贡献,正因为你开源的资料让我在学习吴恩达的机器学习编程作业时有了充分的参考。但是在我运行的过程中,发现一些小问题,可能是因为python版本不同,所以导致我的代码报错,现将问题指出,以方便后来的学习者。
在2.logistic regression中的第41和42行涉及到log函数,运行会报错:

RuntimeWarning: divide by zero encountered in log xxxxxxxx

这是因为当某些数据log涉及到无穷的时候,原始的np.log中内存的计算单位内存就会益出,导致后续无法计算,所以我们为期新增一个有固定值的小数位。保证其计算的时候浮点数维持在1e-5,运行不会报错。因此该两行代码改为

first = np.multiply(-y, np.log(sigmoid(X * theta.T) + 1e-5))
second = np.multiply((1-y), np.log(1 - sigmoid(X * theta.T) + 1e-5))

我的python版本为python 3.9,希望对出现同样问题的同学有参考价值。

@WUU55 WUU55 changed the title 提出代码运行出现的一些错误 提出“2.logistic regression”代码运行出现的一些错误并指出改进方法 May 31, 2022
@WUU55 WUU55 changed the title 提出“2.logistic regression”代码运行出现的一些错误并指出改进方法 提出“2.logistic regression”代码运行出现的报错并指出改进方法 May 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant