Last active
November 5, 2019 07:15
-
-
Save dvgodoy/c8cf1c6bbbb4422d082bfd77074bb257 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.linear_model import LogisticRegression | |
from sklearn.metrics import log_loss | |
import numpy as np | |
x = np.array([-2.2, -1.4, -.8, .2, .4, .8, 1.2, 2.2, 2.9, 4.6]) | |
y = np.array([0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]) | |
logr = LogisticRegression(solver='lbfgs') | |
logr.fit(x.reshape(-1, 1), y) | |
y_pred = logr.predict_proba(x.reshape(-1, 1))[:, 1].ravel() | |
loss = log_loss(y, y_pred) | |
print('x = {}'.format(x)) | |
print('y = {}'.format(y)) | |
print('p(y) = {}'.format(np.round(y_pred, 2))) | |
print('Log Loss / Cross Entropy = {:.4f}'.format(loss)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment