Last active
January 26, 2017 01:30
-
-
Save akiniwa/eb779ad4af6397138a2425ae09e09779 to your computer and use it in GitHub Desktop.
Logistic Regression CV
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.ensemble import RandomForestClassifier | |
from sklearn.linear_model import LogisticRegression | |
from sklearn.cross_validation import train_test_split | |
from sklearn.metrics import accuracy_score, roc_auc_score | |
def score(model, X, y): | |
X_train, X_test, y_train, y_test = train_test_split(X, y) | |
model.fit(X_train, y_train) | |
pred_proba = model.predict_proba(X_test) | |
pred = model.predict(X_test) | |
from sklearn.metrics import accuracy_score, roc_auc_score | |
print('acc:', accuracy_score(y_test, pred)) | |
print('auc:', roc_auc_score(y_test, pred_proba[:, 1])) | |
return model, roc_auc_score(y_test, pred_proba[:, 1]) | |
lr = LogisticRegression(class_weight='balanced') | |
score(lr, X, y) | |
rfc = RandomForestClassifier(class_weight='balanced') | |
model = score(rfc, X, y) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment