Skip to content

Instantly share code, notes, and snippets.

@garymanley
Created December 31, 2017 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save garymanley/1b45b290d722d1186ad6b5eeff0640e0 to your computer and use it in GitHub Desktop.
Save garymanley/1b45b290d722d1186ad6b5eeff0640e0 to your computer and use it in GitHub Desktop.
Logistic Regression in Python
## import libraries
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import classification_report, confusion_matrix
## load in training data
train = pd.read_excel(r'C:\Users\garym\Documents\PyWinAutoBlog\DD_data\DDData2.xlsx')
## run train test split (normally after doing data processing and analytics not shown)
X_train, X_test, y_train, y_test = train_test_split(train.drop('Ledderhose',axis=1),
train['Ledderhose'], test_size=0.2,
random_state=101)
## run logistic regression model
logmodel = LogisticRegression()
logmodel.fit(X_train,y_train)
## run predictions
predictions = logmodel.predict(X_test)
## print reports
print(classification_report(y_test,predictions))
print(confusion_matrix(y_test,predictions))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment