Breast cancer Dataset high loss function and low accuracy

Viewed 72

i am new to the ml topic and tried some training today. I ran into several problems until i reached the position where i am now. Can anyone explane to me why the accurcy is not changing and why the loss function is so high? I used the wisconsin breast cancer data set.

Here is my code:

import pandas as pd
import tensorflow as tf

df = pd.read_csv('data.csv',)

df['diagnosis']=df['diagnosis'].replace(['M'], 1)
df['diagnosis']=df['diagnosis'].replace(['B'], 0)

df = df.iloc[: , :-1]

df.head

x = df.drop(columns=["diagnosis"])

y = df["diagnosis"]

from sklearn.model_selection import train_test_split

x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.1)

model = tf.keras.models.Sequential()

model.add(tf.keras.layers.Dense(256, input_shape=(x_train.shape[1],), activation='sigmoid'))
model.add(tf.keras.layers.Dense(1, activation='sigmoid'))

model.summary()

model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])

df.dtypes

model.fit(x_train, y_train, epochs=500)
1 Answers

Looking at the Kaggle dataset you provide in the question comments, I run the model again. I faced the same problem you were describing:

Epoch 500/500
16/16 [==============================] - 0s 3ms/step - loss: 0.6577 - accuracy: 0.6328

The reason is that in the dataset is present the column id. Drop this column before training phase:

df = df.drop('id', axis=1)

I obtained better results:

Epoch 500/500
16/16 [==============================] - 0s 3ms/step - loss: 0.0770 -  accuracy: 0.9648

(almost) Always remove IDs and identifiers columns from your dataset. If you need it, set it as the index of the dataframe but not as column. They confused the predictor in training phase since they do not provide any useful information.

Related