text_plain_output_1.png
from sklearn.preprocessing import StandardScaler

import matplotlib.pyplot as plt

import numpy as np

import random

import tensorflow as tf

data = np.genfromtxt('/kaggle/input/da-assignment2/wdbc.data', delimiter=',')
data = np.delete(data, [0, 1], axis=1)
file = open('/kaggle/input/wdbc-labels/wdbc_labels.csv', 'r')
lines = file.readlines()
count = 0
labels = np.zeros((data.shape[0], 1))
for line in lines:
    if line[0] == 'M':
        labels[count] = 0
    else:
        labels[count] = 1
    count = count + 1

data_comb = []
for i in range(569):
    data_comb.append((data[i], labels[i]))
random.shuffle(data_comb)
data = np.empty((569, 30))
for i in range(569):
    data[i] = np.array(data_comb[i][0])
    labels[i] = data_comb[i][1]
border = int(data.shape[0] * 0.75)
train_x = data[0:border]
train_y = labels[0:border]
test_x = data[border + 1:data.shape[0]]
test_y = labels[border + 1:data.shape[0]]

from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
train_x = sc.fit_transform(train_x)
test_x = sc.transform(test_x)

model = tf.keras.Sequential()
model.add(tf.keras.layers.Input(30))
model.add(tf.keras.layers.Dense(512, activation='relu'))
model.add(tf.keras.layers.Dense(256, activation='relu'))
model.add(tf.keras.layers.Dense(128, activation='relu'))
model.add(tf.keras.layers.Dense(1, activation='sigmoid'))
model.compile(optimizer=tf.keras.optimizers.Adam(learning_rate=0.0002), loss='binary_crossentropy', metrics=['accuracy', tf.keras.metrics.TruePositives(), tf.keras.metrics.FalsePositives(), tf.keras.metrics.TrueNegatives(), tf.keras.metrics.FalseNegatives()])
model.summary()

model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])
batch_size = 64
print('Fit on NumPy data')
history = model.fit(train_x, train_y, batch_size=batch_size, epochs=1)
dataset = tf.data.Dataset.from_tensor_slices((train_x, train_y)).batch(batch_size)
print('Fit on Dataset')
history = model.fit(dataset, epochs=15)