Breast Cancer Evaluation Practice Problem
This data science coding problem helps you practice Evaluation Metrics for Classification, breast cancer evaluation, and implementation skills. Read the problem statement, write your solution, and strengthen your understanding of Evaluation Metrics for Classification.
- Problem ID: 144
- Problem key: 144-breast-cancer-evaluation
- URL: https://datacrack.app/solve/144-breast-cancer-evaluation
- Difficulty: medium
- Topic: Evaluation Metrics for Classification
- Module: Introduction to Machine Learning
Problem Statement
## 🧩 Breast Cancer Model Evaluation
### 🎯 Goal
Put everything together for classification! You will train a model on the **Breast Cancer** dataset and use your evaluation skills to judge its performance using multiple metrics.
---
### 💻 Task Description
To ensure you evaluate correctly, follow these steps inside your function:
1. **Fetch Dataset**: Use `load_breast_cancer` from `sklearn.datasets`.
2. **Modeling**: Train a `LogisticRegression(max_iter=10000)` model on the **entire** Breast Cancer dataset.
3. **Predictions**: Use the model to predict outcomes for the provided `X_test`.
4. **Summary**: Return a dictionary of metrics (`accuracy`, `precision`, `recall`, `f1`) computed between the provided `y_test` and your predictions.
---
### 📥 Input / 📤 Output
**Input**
- `X_test` (`list[list[float]]`): Features for a subset of patients.
- `y_test` (`list[int]`): True labels (0 = malignant, 1 = benign) for the same subset.
**Output**
- `dict`: A dictionary containing `"accuracy"`, `"precision"`, `"recall"`, and `"f1"`.
- Each metric should be rounded to 6 decimal places.
---
### 🧩 Starter Code
```python
import numpy as np
from sklearn.datasets import load_breast_cancer
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score, precision_score, recall_score, f1_score
def evaluate_cancer_model(X_test, y_test):
"""
Train a Logistic Regression model on Breast Cancer data and return a performance summary.
"""
# 1. Load data
# 2. Train model
# 3. Predict
# 4. Compute metrics and return dict
pass
```
---
Starter Code
import numpy as np
from sklearn.datasets import load_breast_cancer
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score, precision_score, recall_score, f1_score
def evaluate_cancer_model(X_test, y_test):
"""
Train a Logistic Regression model on Breast Cancer data and return a performance summary.
"""
# 1. Load data
# 2. Train model
# 3. Predict
# 4. Compute metrics and return dict
pass