TransWikia.com

Why does the neural network keep giving out the same output for every input?

Data Science Asked by Uzair Ahmed on January 8, 2021

Made a neural network using TensorFlow’s Keras that is supposed to match an IP to one of the 7 type of vulnerabilities and give out what type of vulnerability that IP has.

model = tf.keras.models.Sequential([
  tf.keras.layers.Flatten(),
  tf.keras.layers.Dense(50, activation=tf.nn.relu),
  tf.keras.layers.Dense(7, activation=tf.nn.softmax)
])

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

model.fit(xs, ys, epochs=500)

xs is the list of IPs and ys is its corresponding vulnerability from 0 to 6 (seven in total).

The output for this remains the same for every input, i.e.,:

[[0.22258884 0.20329571 0.36828393 0.11352853 0.04444532 0.02388807 0.02396955]]

2 Answers

Most probably, this is because your model is way too simple - a single 50-node hidden layer for a 7-class problem does not sound adequate.

Try adding more hidden layers (and not quite sure if you really need a Flatten layer just after the input), e.g.,:

model = tf.keras.models.Sequential([
 tf.keras.layers.Dense(100, activation=tf.nn.relu),
 tf.keras.layers.Dense(50, activation=tf.nn.relu)
 tf.keras.layers.Dense(50, activation=tf.nn.relu),
 tf.keras.layers.Dense(7, activation=tf.nn.softmax)
])

Experiment with the exact number and size of the layers.

Answered by desertnaut on January 8, 2021

It depends on the represent of the ip address. If you are feeding the ip address with those dot in it. It might perform worse. Rather i would suggest to split the ip into 4 seperate input(seperated by dot) and feed the 4 input individually to the network. And then evaluate.

Answered by SrJ on January 8, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP