Loading…
DS · Classification · Program 21 · In the record
Logistic Regression for binary classification.
1from sklearn.datasets import load_breast_cancer2from sklearn.model_selection import train_test_split3from sklearn.pipeline import make_pipeline4from sklearn.preprocessing import StandardScaler5from sklearn.linear_model import LogisticRegression6from sklearn.metrics import accuracy_score7 8X, y = load_breast_cancer(return_X_y=True)9X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25, random_state=42)10 11model = make_pipeline(StandardScaler(), LogisticRegression()).fit(X_train, y_train)12print("Logistic Regression Accuracy:", accuracy_score(y_test, model.predict(X_test)))13print("P(benign) for first test sample:", model.predict_proba(X_test[:1])[0, 1])Logistic Regression Accuracy: 0.9790209790209791 P(benign) for first test sample: 0.8766704261947693

Run program 21 in your browser
Python 3.14 · Pyodide. Change the code or the input, run it, break it, and see what happens.