-
-
Save garymanley/1b45b290d722d1186ad6b5eeff0640e0 to your computer and use it in GitHub Desktop.
Logistic Regression in Python
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
## 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