Loading…
DS · EDA & full pipeline · Program 40 · In the record
End-to-end data science app: preprocess, visualize, model, evaluate, predict.
1import seaborn as sns2import matplotlib.pyplot as plt3from sklearn.datasets import load_breast_cancer4from sklearn.model_selection import train_test_split5from sklearn.preprocessing import StandardScaler6from sklearn.linear_model import LogisticRegression7from sklearn.metrics import classification_report, confusion_matrix8 9# 1. Load data10data = load_breast_cancer(as_frame=True)11df = data.frame12 13# 2. Preprocessing14df = df.drop_duplicates().dropna()15X, y = df.drop(columns='target'), df['target']16X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)17scaler = StandardScaler()18X_train, X_test = scaler.fit_transform(X_train), scaler.transform(X_test)19 20# 3. Visualization21sns.countplot(x=y)22plt.title("Class Balance (0 = malignant, 1 = benign)")23plt.show()24 25# 4. Model26model = LogisticRegression().fit(X_train, y_train)27 28# 5. Evaluation29y_pred = model.predict(X_test)30print("Confusion Matrix:\n", confusion_matrix(y_test, y_pred))31print("\nClassification Report:\n", classification_report(y_test, y_pred))32 33# 6. Prediction34print("Prediction for first test patient:", data.target_names[model.predict(X_test[:1])[0]])Confusion Matrix:
[[41 2]
[ 1 70]]
Classification Report:
precision recall f1-score support
0 0.98 0.95 0.96 43
1 0.97 0.99 0.98 71
accuracy 0.97 114
macro avg 0.97 0.97 0.97 114
weighted avg 0.97 0.97 0.97 114
Prediction for first test patient: benign
Run program 40 in your browser
Python 3.14 · Pyodide. Change the code or the input, run it, break it, and see what happens.