英文:
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)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论