Skip to content

Instantly share code, notes, and snippets.

@yuyasugano
Created November 23, 2020 06:16
Show Gist options
  • Save yuyasugano/2e43d7b203f9010a5db231499ed0e875 to your computer and use it in GitHub Desktop.
Save yuyasugano/2e43d7b203f9010a5db231499ed0e875 to your computer and use it in GitHub Desktop.
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)
clf.fit(X_train, 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