为什么我的神经网络中损失和准确率数字太高?

huangapple go评论68阅读模式
英文:

Why are my loss and accuracy number are too much in neural net?

问题

机器学习新手在学习如何使用TensorFlow进行神经网络时遇到了以下问题:

出于好奇,我想知道在这个数据集上使用神经网络与使用线性回归相比,神经网络会表现如何。所以我输入了下面的代码:

x = file.drop(columns="Height").values
y = file.drop(columns="Weight").values
y = np.reshape(y, (-1, 1))
x = np.reshape(x, (-1, 1))

from sklearn.preprocessing import StandardScaler
ss = StandardScaler()
x = ss.fit_transform(x)

from sklearn.model_selection import train_test_split
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.2)

import tensorflow as tf
model = tf.keras.Sequential([
    tf.keras.layers.Dense(16, activation="relu"),
    tf.keras.layers.Dense(16, activation="relu"),
    tf.keras.layers.Dense(1, activation="sigmoid")
])

model.compile(optimizer=tf.keras.optimizers.Adam(),
              loss=tf.keras.losses.BinaryCrossentropy(), metrics="accuracy")

model.fit(x_train, y_train, epochs=10, batch_size=16)

我使用了基本的知识来缩放数据,以增加神经网络的准确性。然而,当我运行上面的代码时,得到了这种“难看”的准确性和损失图:

我该怎么做才能提高准确性和降低损失?

英文:

Machine learning newbie here, i am currently learning on how to do neural net with tensorflow. I have this dataset below:

为什么我的神经网络中损失和准确率数字太高?

out of curiosity, i wonder how will neural net perform on this dataset instead of using Linear Regression,so i typed this code below:

x = file.drop(columns= "Height").values
y = file.drop(columns= "Weight").values
y = np.reshape(y, (-1, 1))
x = np.reshape(x, (-1, 1))

from sklearn.preprocessing import StandardScaler
ss = StandardScaler()
x = ss.fit_transform(x)

from sklearn.model_selection import train_test_split
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size = 0.2)


import tensorflow as tf
model = tf.keras.Sequential([
    tf.keras.layers.Dense(16, activation = "relu"),
    tf.keras.layers.Dense(16, activation = "relu"),
    tf.keras.layers.Dense(1, activation = "sigmoid")
])

model.compile(optimizer= tf.keras.optimizers.Adam(),
loss = tf.keras.losses.BinaryCrossentropy(), metrics= "accuracy")

model.fit(x_train, y_train, epochs = 10, batch_size = 16)#I actually dont fully know what batch size is, im adding that just for kicks

i scaled the data with the basic knowledge of by scaling it, the accuracy of neural net will increase slightly. However, when i run the code above, i get this "ugly looking" Accuracy and losses:
为什么我的神经网络中损失和准确率数字太高?

What can i do to make the accuracy and loss better?

答案1

得分: 1

应用回归模型时,输出层应使用线性激活函数。移除Sigmoid激活函数,因为它会降低身高的连续数值。为了进一步提高准确性,还可以增加"tf.keras.layers.Dense()"内的单元数。

英文:

For applying regression on the data,any linear activation should be used in the output layer. Remove the sigmoid activation as it reduces the continuous values in the height. To further improve accuracy units inside "tf.keras.layers.Dense()" could also be increased.

答案2

得分: 1

我不确定是什么导致了这么大的损失,但我建议你增加数据集的大小,这可能会有所帮助。我指的是要大得多。为什么不尝试使用一些调查报告,甚至是 Kaggle(尽管风险取决于你,因为来自 Kaggle 的数据未经验证)?

英文:

I am not entirely sure what is making that high of a loss but i would suggest you increase your dataset size that may help. I mean a lot bigger. Why dont you try using some survey reports or even kaggle(altough the risk is upto you because the data from kaggle isnt authenticated)

huangapple
  • 本文由 发表于 2023年6月12日 21:51:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/76457346.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定