-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ed75e84
commit 4315a08
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import numpy as np | ||
from sklearn.datasets import load_breast_cancer | ||
from sklearn.model_selection import train_test_split | ||
from sklearn.preprocessing import StandardScaler | ||
from sklearn.metrics import accuracy_score | ||
import tensorflow as tf | ||
|
||
# Load the Breast Cancer dataset | ||
data = load_breast_cancer() | ||
X = data.data | ||
y = data.target | ||
|
||
# Split the data into training and testing sets | ||
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42) | ||
|
||
# Standardize the features | ||
scaler = StandardScaler() | ||
X_train = scaler.fit_transform(X_train) | ||
X_test = scaler.transform(X_test) | ||
|
||
# Build the neural network model | ||
model = tf.keras.Sequential([ | ||
tf.keras.layers.Dense(30, activation='relu', input_shape=(X_train.shape[1],)), | ||
tf.keras.layers.Dense(15, activation='relu'), | ||
tf.keras.layers.Dense(1, activation='sigmoid') # Binary classification | ||
]) | ||
|
||
# Compile the model | ||
model.compile(optimizer='adam', | ||
loss='binary_crossentropy', | ||
metrics=['accuracy']) | ||
|
||
# Train the model | ||
model.fit(X_train, y_train, epochs=50, batch_size=16, verbose=1) | ||
|
||
# Evaluate the model | ||
y_pred = (model.predict(X_test) > 0.5).astype(int).flatten() | ||
accuracy = accuracy_score(y_test, y_pred) | ||
|
||
print(f"Model Accuracy: {accuracy * 100:.2f}%") |