'Tensorflow: accuracy remains the same

I'm trying to build simple NN model, however accuracy remains the same during all epochs in the training: here is the code

editing data:

train = pd.read_csv('../input/mercedes-benz-greener-manufacturing/train.csv.zip')
test = pd.read_csv('../input/mercedes-benz-greener-manufacturing/test.csv.zip')
df.head()
cf = total.select_dtypes(include=['object']).columns
total = pd.concat([train, test], axis=0)dummies = pd.get_dummies(
    total[cf],
    drop_first=True)


# get rid of old columns and append them encoded
total = pd.concat(
    [
        total.drop(cf, axis=1), # drop old
        dummies # append them one-hot-encoded
    ],
    axis=1 # column-wise
)
is_train = ~total.y.isnull()
train, test = total[is_train].drop(['ID'], axis=1), total[~is_train].drop(['ID', 'y'], axis=1)

Callbacks:

from tensorflow.keras.models import Sequential
from tensorflow.keras.callbacks import EarlyStopping, ModelCheckpoint

early_stopping_cb = EarlyStopping(monitor='accuracy', patience=7, mode='max')
file_dir = '/logs_of_models/'
model_checkpoint = ModelCheckpoint('/logs_of_models/', monitor='accuracy', save_weights_only=True,
                                   save_best_only=True)

Building NN:

tf.random.set_seed(42)
model_1 = tf.keras.Sequential([
    tf.keras.layers.Dense(128, activation='relu'),
    tf.keras.layers.Dense(128, activation='relu'),
    tf.keras.layers.Dense(1, activation='relu')
])

model_1.compile(loss=tf.keras.losses.mae,
               optimizer=tf.keras.optimizers.Adam(),
               metrics=['accuracy'])

history_1 = model_1.fit(train, test,
                       epochs=20, callbacks=[model_checkpoint])

here is the output of fitting it:

Epoch 1/20
132/132 [==============================] - 1s 3ms/step - loss: 0.1142 - accuracy: 0.8858
Epoch 2/20
132/132 [==============================] - 0s 3ms/step - loss: 0.1142 - accuracy: 0.8858
Epoch 3/20
132/132 [==============================] - 0s 3ms/step - loss: 0.1142 - accuracy: 0.8858
Epoch 4/20
132/132 [==============================] - 0s 3ms/step - loss: 0.1142 - accuracy: 0.8858
Epoch 5/20
132/132 [==============================] - 0s 3ms/step - loss: 0.1142 - accuracy: 0.8858

And here is the screenshoot of unedited data before transforming it:enter image description here



Solution 1:[1]

loss=tf.keras.losses.mae - this is loss for regression models

metrics=['accuracy'] - this is metric for classification models

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Peter Pirog