Skip to content

Instantly share code, notes, and snippets.

Created November 23, 2020 06:16
What would you like to do?
3 ways to do dimensional reduction techniques in Scikit-learn
import pandas as pd
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score, f1_score, classification_report
from sklearn.datasets import load_breast_cancer
(X, y) = load_breast_cancer(return_X_y = True)
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=0)
clf = LogisticRegression(random_state=0), y_train)
print('%s: %.3f' % ('Logreg Train Accuracy', accuracy_score(y_train, clf.predict(X_train))))
print('%s: %.3f' % ('Logreg Test Accuracy', accuracy_score(y_test, clf.predict(X_test))))
print('%s: %.3f' % ('Logreg Train F1 Score', f1_score(y_train, clf.predict(X_train))))
print('%s: %.3f' % ('Logreg Test F1 Score', f1_score(y_test, clf.predict(X_test))))
print(classification_report(y_test, clf.predict(X_test)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment