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

Log_likelihood update #1008

Merged
merged 12 commits into from
Jul 13, 2019
Merged

Log_likelihood update #1008

merged 12 commits into from
Jul 13, 2019

Conversation

ChillOrb
Copy link
Contributor

No description provided.

ChillOrb added 3 commits July 11, 2019 22:28
This is a simple exploratory notebook that heavily expolits pandas and seaborn
Update with log_likelihood logistic_regression.py
def log_likelihood(X, Y, weights):
scores = np.dot(features, weights)
ll = np.sum( target*scores - np.log(1 + np.exp(scores)) )
return ll
Copy link
Member

@cclauss cclauss Jul 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not create the variable ll, it is not an intuitive name so just return the result. The function is self explanatory. Of course, a docstring, doctests, and type hints would not hurt.

Copy link
Member

@cclauss cclauss Jul 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return np.sum(target * scores - np.log(1 + np.exp(scores)))

@@ -55,6 +61,17 @@ def logistic_reg(
J = cost_function(h, y)

iterations += 1 # update iterations

for step in xrange(num_steps):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

xrange() was removed in Python 3 so please use range() instead.

machine_learning/logistic_regression.py Outdated Show resolved Hide resolved
scores = np.dot(X, weights)
predictions = sigmoid(scores)
if step % 10000 == 0:
print log_likelihood(X,Y,weights) # Print log-likelihood every so often
Copy link
Member

@cclauss cclauss Jul 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

print() is a function in Python 3. --> print(log_likelihood(X, Y, weights))

if step % 10000 == 0:
print log_likelihood(X,Y,weights) # Print log-likelihood every so often
return weights

if iterations == max_iterations:
print ('Maximum iterations exceeded!')
print ('Minimal cost function J=', J)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style: No space between print and (.

@cclauss
Copy link
Member

cclauss commented Jul 13, 2019

Click the automated test below to see why it is failing...

Copy link
Contributor Author

@ChillOrb ChillOrb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have made some changes. Please review and i would appreciate you helping me.

@cclauss cclauss merged commit 0d61539 into TheAlgorithms:master Jul 13, 2019
stokhos pushed a commit to stokhos/Python that referenced this pull request Jan 3, 2021
* Add files via upload

This is a simple exploratory notebook that heavily expolits pandas and seaborn

* Update logistic_regression.py

* Update logistic_regression.py

* Rename Food wastage analysis from 1961-2013 (FAO).ipynb to other/Food wastage analysis from 1961-2013 (FAO).ipynb

* Update logistic_regression.py

* Update logistic_regression.py

* Update logistic_regression.py

* Update logistic_regression.py

* Update logistic_regression.py

* Update logistic_regression.py

* Update logistic_regression.py
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

Successfully merging this pull request may close these issues.

2 participants