text: import numpy as np
  from sklearn.datasets import load_digits
  from sklearn.model_selection import train_test_split
  from sklearn.dummy import DummyClassifier
  from sklearn.tree import DecisionTreeClassifier
  from sklearn.metrics import confusion_matrix
  from sklearn.linear_model import LogisticRegression
  
  from sklearn.metrics import f1_score, classification_report
  
  import warnings
  
  warnings.filterwarnings("ignore", category=Warning)
  
  digits = load_digits()
  y = digits.target == 9
  
  X_train, X_test, y_train, y_test = train_test_split(digits.data, y, random_state=0)
  
  dummy_majority = DummyClassifier(strategy='most_frequent').fit(X_train, y_train)
  pred_most_frequent = dummy_majority.predict(X_test)
  
  print("Unique predicted labels: {}".format(np.unique(pred_most_frequent)))
  print("Test score: {:.2f}".format(dummy_majority.score(X_test, y_test)))
  
  tree = DecisionTreeClassifier(max_depth=2).fit(X_train, y_train)
  pred_tree = tree.predict(X_test)
  print("Test score: {:.2f}".format(tree.score(X_test, y_test)))
  
  dummy = DummyClassifier().fit(X_train, y_train)
  pred_dummy = dummy.predict(X_test)
  print("dummy score: {:.2f}".format(dummy.score(X_test, y_test)))
  
  logreg = LogisticRegression(C=0.1).fit(X_train, y_train)
  pred_logreg = logreg.predict(X_test)
  print("logreg score: {:.2f}".format(logreg.score(X_test, y_test)))
  
  # Confusion Matrices
  confusion = confusion_matrix(y_test, pred_logreg)
  print("Confusion matrix:\n{}".format(confusion))
  
  print("Most frequent class:")
  print(confusion_matrix(y_test, pred_most_frequent))
  print("\nDummy model:")
  print(confusion_matrix(y_test, pred_dummy))
  print("\nDecision tree:")
  print(confusion_matrix(y_test, pred_tree))
  print("\nLogistic Regression:")
  print(confusion_matrix(y_test, pred_logreg))
  
  # F1
  print("f1 score most frequent: {:.2f}".format(f1_score(y_test, pred_most_frequent)))
  print("f1 score dummy: {:.2f}".format(f1_score(y_test, pred_dummy)))
  print("f1 score tree: {:.2f}".format(f1_score(y_test, pred_tree)))
  print("f1 score logistic regression: {:.2f}".format(f1_score(y_test, pred_logreg)))
  
  # report
  # print(classification_report(y_test, pred_most_frequent))
  print(classification_report(y_test, pred_most_frequent, target_names=["not nine", "nine"]))
  
  print(classification_report(y_test, pred_dummy, target_names=["not nine", "nine"]))
  print(classification_report(y_test, pred_logreg, target_names=["not nine", "nine"]))
  