-
-
Notifications
You must be signed in to change notification settings - Fork 46.1k
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
Log_likelihood update #1008
Conversation
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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.
scores = np.dot(X, weights) | ||
predictions = sigmoid(scores) | ||
if step % 10000 == 0: | ||
print log_likelihood(X,Y,weights) # Print log-likelihood every so often |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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 (.
Click the automated test below to see why it is failing... |
… wastage analysis from 1961-2013 (FAO).ipynb
There was a problem hiding this 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.
* 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
No description provided.