测试张量流程序产生非常低的精度

发布于 2025-01-19 21:19:58 字数 1080 浏览 1 评论 0 原文

一般来说,我非常新颖,我试图制作一个从1-12中获得数字的程序,并根据其含量为哪个值,从a,b,c,d或e返回字母。发电机在生成时将每个数字随机分配给一个字母,并且该模型应该猜测分配给什么的内容。我使用HashingDectorization将APLHHOBET转换为5个值的数组,而我的代码如下:

from keras.models import Sequential
from keras.layers import Dense
import pandas as pd
from sklearn.feature_extraction.text import HashingVectorizer
# load the dataset
dataset = pd.read_csv('testbase.csv')
vectorizer = HashingVectorizer(n_features=5)
# split into input (X) and output (y) variables
input = dataset['col2']
result = vectorizer.transform(list(dataset['col1'])).toarray()
# define the keras model
model = Sequential()
model.add(Dense(5, input_dim=1, activation='relu'))
model.add(Dense(5, activation='relu'))
model.add(Dense(5, activation='sigmoid'))
# compile the keras model
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
# fit the keras model on the dataset
model.fit(input, result, epochs=150, batch_size=10)
# evaluate the keras model
_, accuracy = model.evaluate(input, result)
print('Accuracy: %.2f' % (accuracy*100))

有人可以弄清楚为什么是这种情况吗?

am very new to deep learning in general, and I tried to make a program that takes a number from 1-12, and returns an alphabet from A, B, C, D or E based on which value it is. The generator randomly assigns each number to an alphabet upon generation, and the model is supposed to guess what is assigned to what. I used HashingVectorization to convert the aplhabets into an array of 5 values, and my code is as below:

from keras.models import Sequential
from keras.layers import Dense
import pandas as pd
from sklearn.feature_extraction.text import HashingVectorizer
# load the dataset
dataset = pd.read_csv('testbase.csv')
vectorizer = HashingVectorizer(n_features=5)
# split into input (X) and output (y) variables
input = dataset['col2']
result = vectorizer.transform(list(dataset['col1'])).toarray()
# define the keras model
model = Sequential()
model.add(Dense(5, input_dim=1, activation='relu'))
model.add(Dense(5, activation='relu'))
model.add(Dense(5, activation='sigmoid'))
# compile the keras model
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
# fit the keras model on the dataset
model.fit(input, result, epochs=150, batch_size=10)
# evaluate the keras model
_, accuracy = model.evaluate(input, result)
print('Accuracy: %.2f' % (accuracy*100))

can someone figure out why this is the case?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

差↓一点笑了 2025-01-26 21:19:58

binary_crossentropy 对此不是一个好损失功能,因为您不进行二进制分类(因为您有五个类别可以分类为单位)。我会首先尝试使用分类的crossentropy,如果仍然会产生不良结果,请通过调整学习率,优化者等来实验。

binary_crossentropy is not a good loss function for this, because you're not doing binary classification (since you have five categories to classify into). I would give it a try with categorical crossentropy first, and if that still yields bad results, experiment by tweaking around with learning rate, optimizers etc.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文