A scaled logistic regression reads 30 tumour measurements and predicts class 1 (benign) or 0 (malignant). A positive push moves a row towards benign; a negative push moves it towards malignant.
For one test sample, a doctor wants both sides of the story.
Task: write both_sides(test_index, n).
load_breast_cancer(return_X_y=True, as_frame=True).train_test_split(X, y, test_size=0.25, random_state=0, stratify=y).make_pipeline(StandardScaler(), LogisticRegression(max_iter=1000)) on the training rows.X_test.iloc[[test_index]]. Its pushes are its scaled values times coef_[0]."predicted": the predicted class, a plain int"benign": the names of the n columns with the largest positive pushes, largest first"malignant": the names of the n columns with the most negative pushes, most negative first