Breast Cancer Classification using Logistic Regression Practice Problem
This data science coding problem helps you practice Logistic Regression, breast cancer classification using logistic regression, and implementation skills. Read the problem statement, write your solution, and strengthen your understanding of Logistic Regression.
- Problem ID: 10
- Problem key: 10-breast-cancer-classification-using-logistic-regression
- URL: https://datacrack.app/solve/10-breast-cancer-classification-using-logistic-regression
- Difficulty: easy
- Topic: Logistic Regression
- Module: Introduction to Machine Learning
Problem Statement
---
# 🧩 Binary Classification (Real Dataset: Breast Cancer)
---
### 🎯 Goal
Train a **Logistic Regression** model using **Scikit-learn** on the **Breast Cancer** dataset.
This introduces how to use Scikit-learn’s model training interface for binary classification tasks.
---
### 🧮 Background & Syntax Introduction
Scikit-learn provides many ready-to-use datasets and models.
In this problem, you’ll use the **Breast Cancer** dataset to train a **Logistic Regression** classifier.
#### 🧩 Loading the Dataset
```python
from sklearn.datasets import load_breast_cancer
data = load_breast_cancer()
```
#### 🧠 Key Scikit-learn Methods
* `LogisticRegression()` — creates a logistic regression model.
* `.fit(X, y)` — trains the model using all the data.
* `.predict(X)` — returns predicted labels for new samples.
---
### 📥 Input / 📤 Output
**Input:**
* `X_test` — list of samples, where each sample is a list of feature values.
**Output:**
* A list of predicted class labels (0 or 1).
---
### 💻 Task Description
Train a **logistic regression model** using all data from the Breast Cancer dataset.
Then, predict class labels for the given `X_test` input using the trained model.
Return the predictions as a **Python list** of integers (0 or 1).
---
### 🧩 Starter Code
```python
import pandas as pd
from sklearn.datasets import load_breast_cancer
from sklearn.linear_model import LogisticRegression
def breast_cancer_classification(X_test):
"""
Train a logistic regression model on the Breast Cancer dataset
and return predicted class labels for the given X_test.
Args:
X_test (list[list[float]]): Samples to classify.
Returns:
list[int]: Predicted class labels (0 or 1)
"""
# TODO: Implement the training and prediction pipeline
pass
```
---
### 💡 Example
```python
# Example Input
from sklearn.datasets import load_breast_cancer
data = load_breast_cancer()
X_test = data.data[:3].tolist() # first 3 samples
breast_cancer_classification(X_test)
```
**Expected Output:**
```python
[0, 0, 0]
```
---
Starter Code
import pandas as pd
from sklearn.datasets import load_breast_cancer
from sklearn.linear_model import LogisticRegression
def breast_cancer_classification(X_test):
"""
Train a logistic regression model on the Breast Cancer dataset
and return predicted class labels for the given X_test.
Args:
X_test (list[list[float]]): Samples to classify.
Returns:
list[int]: Predicted class labels (0 or 1)
"""
# TODO: Implement the training and prediction pipeline
pass