简体   繁体   中英

Why is my neural network accuracy so low?

I am new to machine learning and have been getting myself to learn neural networks. This week I've tried coding a neural network using this dataset. https://archive.ics.uci.edu/ml/datasets/abalone

The dataset contains details of individual abalones such as their size, gender, etc. My goal with this dataset is to predict the ages of abalone. This could be done by multiplying the rings of abalone by 1.5 as the dataset also reveals how one ring contributes to around 1.5 years of age. Therefore, my goal is to use a neural network to predict the number of rings an abalone has. That way, I will know its age as well.

I decided to have 4 layers with 300 nodes in the hidden layer and 1 in the output. Here is my code:

abalone_ds = pd.read_csv('abalone_ds.csv', header=None, prefix='V')
abalone_ds.columns = ['Sex', 'Length', 'Diameter', 'Height',
                   'Whole weight', 'Shucked weight',
                   'Viscera weight', 'Shell weight', 'Rings']


def one_hot(ds, column_name):
    return pd.get_dummies(ds, columns=[column_name])

abalone_ds = one_hot(abalone_ds, "Sex")

y_ds = abalone_ds["Rings"]
x_ds = abalone_ds.drop(columns="Rings")

x_train, x_val, y_train, y_val = skl.train_test_split(x_ds, y_ds, test_size=0.2)

model = Sequential()
model.add(Dense(300, activation='relu', input_shape=(10,), name='Layer_2'))
model.add(Dense(300, activation='relu', name='Layer_3'))
model.add(Dense(300, activation='relu', name='Layer_4'))
model.add(Dense(1, activation='relu', name='Output'))
model.compile(loss='mean_absolute_error', optimizer='adam', metrics=['accuracy'])
model.fit(x_train, y_train, batch_size=100, epochs=5, verbose=1)

test = model.evaluate(x_val, y_val, verbose=1)

print(test)

I first labeled the columns of the dataset as they were not labeled. Then, while I was analyzing the data, I realized that only "Sex" was non-numerical, so I encoded it to a one-hot tensor. Then, I split up the data (8:2 ratio) and plugged it into the network. The result was not promising.

Here is the image to the result

You could see that my accuracy is 0 for the output layer. Moreover, the error is 1.57 rings which equivalents to 2.355 years. No matter how much I experiment/change the number of nodes or the number of layers, this accuracy value would not change.

I am not sure why this would happen. Perhaps, my understanding of what neural network outputs are wrong? For example, maybe the (1.57, 0.0) doesn't represent the number of rings and the accuracy level. Maybe this dataset is not qualified for the neural networks (meaning other algorithms are better suited). If anyone has any idea of why this is occurring or how I could improve my current code with explanations, I would gladly appreciate it.

I think the issue might be the following: From your description of the problem you are trying to perform a regression task, ie predicting the age of the abalones. The age could in theory be any positive real number. Therefore, the accuracy metric you are using here is unsuited to the task, since it is used for classification tasks, that is, when the output belongs to one of a fixed and discrete set of possibilities. Therefore I would suggest using a different metric to measure your model results, such as Mean Squared Error or Mean Absolute Error, which are suitable for regression.

Also, note that while your metric (accuracy) has a value of 0, your loss function is decreasing with each epoch, which shows your model is improving:)

To frame this as a classification problem you would have to create 20 classes. Your training set now needs to assign a class (age) to each training sample. Your model than has to classify which class a sample is in. The last dense layer in your model would be

classification=Dense(20, activation= 'softmax')
model.compile(Adam, loss=sparse_categorial_crossentropy, metrics=['accuracy']

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM