Downloads · 30 days
0
varunchoursiya/breastcancer
breastcancer is a machine learning model from varunchoursiya. Use it for the machine learning task on the model card, and read the license before you ship it in a product. The card lists the license as mit.
This is a PyTorch-based Deep Artificial Neural Network (ANN) trained on the Wisconsin Diagnostic Breast Cancer (WDBC) dataset to classify cell nuclei observations as either Malignant (M) or Benign (B).
Downloads · 30 days
0
Access
Public
Updated Aug 29, 2026
Repo size
69.1 KB
Likes
0
Public
Click a slice to open those files.
.pth67.9 KB · 88%
From the Hugging Face model README
This is a PyTorch-based Deep Artificial Neural Network (ANN) trained on the Wisconsin Diagnostic Breast Cancer (WDBC) dataset to classify cell nuclei observations as either Malignant (M) or Benign (B).
Hyperparameters were systematically tuned using Optuna to maximize classification accuracy.
The hyperparameter search space was optimized over 30 trials using Tree-structured Parzen Estimator (TPE):
nn.BatchNorm1d) per hidden layer0.43930.0031nn.BCEWithLogitsLoss)id, Unnamed: 32).LabelEncoder (M -> 1, B -> 0).StandardScaler (zero mean and unit variance).Evaluated on unseen test set (20% split, 114 samples):
| Metric | Score |
|---|---|
| Best Test Accuracy | 100.00% (1.00) |
| Average Study Accuracy | ~96.5% |
import torch
import torch.nn as nn
import pickle
import numpy as np
# 1. Define Model Architecture
class MyNN(nn.Module):
def __init__(self, input_dim=30, output_dim=1, num_hidden_layers=2, neuron_per_layer=106, dropout_rate=0.4393):
super().__init__()
layers = []
current_dim = input_dim
for _ in range(num_hidden_layers):
layers.append(nn.Linear(current_dim, neuron_per_layer))
layers.append(nn.BatchNorm1d(neuron_per_layer))
layers.append(nn.ReLU())
layers.append(nn.Dropout(dropout_rate))
current_dim = neuron_per_layer
layers.append(nn.Linear(current_dim, output_dim))
self.model = nn.Sequential(*layers)
def forward(self, x):
return self.model(x)
# 2. Load Scaler & Model Weights
with open("scaler.pkl", "rb") as f:
scaler = pickle.load(f)
model = MyNN()
model.load_state_dict(torch.load("best_model.pth", map_location=torch.device('cpu')))
model.eval()
# 3. Predict on raw 30 feature array
sample_features = np.random.rand(1, 30) # Replace with actual 30 feature values
scaled_features = scaler.transform(sample_features)
input_tensor = torch.tensor(scaled_features, dtype=torch.float32)
with torch.no_grad():
logits = model(input_tensor)
prob = torch.sigmoid(logits).item()
prediction = "Malignant" if prob >= 0.5 else "Benign"
print(f"Prediction: {prediction} (Probability: {prob:.4f})")
sample_features = np.random.rand(1, 30) # Replace with actual 30 feature values scaled_features = scaler.transform(sample_features) input_tensor = torch.tensor(scaled_features, dtype=torch.float32)
with torch.no_grad(): logits = model(input_tensor) prob = torch.sigmoid(logits).item()
prediction = "Malignant" if prob >= 0.5 else "Benign" print(f"Prediction: {prediction} (Probability: {prob:.4f})")