-
-
Save ryanbekabe/ba126b570701df91c557e40e18eec335 to your computer and use it in GitHub Desktop.
This file contains hidden or 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