Skip to content

Instantly share code, notes, and snippets.

@64lines
Created November 19, 2017 17:50
Show Gist options
  • Save 64lines/3350e437f4a131ff1dc302756da4b97c to your computer and use it in GitHub Desktop.
Save 64lines/3350e437f4a131ff1dc302756da4b97c to your computer and use it in GitHub Desktop.
[PYTHON][SKLEARN] Logistical Regression
# Import the necessary modules
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import confusion_matrix, classification_report
# Create training and test sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.4, random_state=42)
# Create the classifier: logreg
logreg = LogisticRegression()
# Fit the classifier to the training data
logreg.fit(X_train, y_train)
# Predict the labels of the test set: y_pred
y_pred = logreg.predict(X_test)
# Compute and print the confusion matrix and classification report
print(confusion_matrix(y_test, y_pred))
print(classification_report(y_test, y_pred))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment