def cancer_pipeline(): X_train, X_test, y_train, y_test = get_cancer_data() pipe_lr = Pipeline([('scl', StandardScaler()), ('pca', PCA(n_components=2)), ('clf', LogisticRegression(random_state=1))]) return pipe_lr, X_train, X_test, y_train, y_test
import numpy as np import matplotlib.pyplot as plt from BCW import get_cancer_data from sklearn.preprocessing import StandardScaler from sklearn.linear_model import LogisticRegression from sklearn.svm import SVC from sklearn.pipeline import Pipeline from sklearn.metrics import confusion_matrix pipe_svc = Pipeline([('scl', StandardScaler()), ('clf', SVC(random_state=1))]) X_train, X_test, y_train, y_test = get_cancer_data() pipe_svc.fit(X_train, y_train) y_pred = pipe_svc.predict(X_test) confmat = confusion_matrix(y_true=y_test, y_pred=y_pred) fig, ax = plt.subplots(figsize=(2.5, 2.5)) ax.matshow(confmat, cmap=plt.get_cmap('Blues'), alpha=0.3) for i in range(confmat.shape[0]): for j in range(confmat.shape[1]): ax.text(x=j, y=i, s=confmat[i, j], va='center', ha='center') plt.xlabel('Predicted Label') plt.ylabel('True Label') plt.show()