- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我一直在尝试使用以下代码运行神经网络:
model=Sequential()
model.add(Dense(output_dim=40, input_dim=90, init="glorot_uniform"))
model.add(Activation("tanh"))
model.add(Dense(output_dim=10, init="glorot_uniform"))
model.add(Activation("linear"))
model.compile(loss="mean_absolute_percentage_error", optimizer="rmsprop")
model.fit(X=predictor_train, y=target_train, nb_epoch=2, batch_size=90,show_accuracy=True)
我一直没能找出这个错误的意思:
raise ValueError(base_exc_str)
ValueError: Dimension mismatch; shapes are (98, 10), (98, 1)
据我了解,形状应该相等,例如 (98,10), (98,10)
或 (98,1),(98,1)
这就是导致问题的原因。是吗?
如果是,有谁知道我可以在代码或数据集中的什么地方解决这个问题? 10 和 1 是什么意思?
如果没有,谁能向我解释发生了什么?
额外信息:
变量 predictor_train:
predictor_train.shape = (98, 90)
type(predictor_train) = numpy.ndarray
predictor_train.dtype = float64
len(predictor_train) = 98
predictor_train = [[ -9.28079499e+03 -5.44726790e+03 9.77551565e+03 ..., -2.94089612e+01
1.05007607e+01 9.32395201e+00]
[ -9.32333218e+03 -4.06918099e+03 8.84849310e+03 ..., 3.02589395e+01
1.32480085e+01 7.35936371e+00]
[ -9.08950902e+03 -2.59672093e+03 6.78783637e+03 ..., -7.22732280e+00
-8.72789507e+00 -3.38694330e+01]
...,
[ 6.00971088e+03 4.82090785e+02 2.06287833e+03 ..., 5.07504624e+00
-1.08715262e+01 -4.44630971e+00]
[ 6.02593657e+03 1.04561016e+03 1.19684456e+03 ..., 2.10305449e+01
-1.00583976e+01 -5.45816394e-01]
[ 6.11828134e+03 1.50004864e+03 3.00936969e+02 ..., -1.66676535e+01
6.07002336e+00 3.00131153e+00]]
变量 target_train:
target_train.shape = (98,)
type(target_train) = pandas.core.series.Series
target_train.dtype = float64
len(target_train) = 98
target_train =
Date
2007-07-01 0.009137
2007-08-01 0.010607
2007-09-01 0.007146
...
2015-06-01 -0.008642
2015-07-01 -0.008642
2015-08-01 -0.008642
Freq: MS, Name: Actual, dtype: float64
完整回溯:
Traceback (most recent call last):
File "/Users/santanna_santanna/PycharmProjects/Predictive Models/teste2.py", line 1479, in Pred
model.fit(X=predictor_train, y=target_train, nb_epoch=2, batch_size=90,show_accuracy=True)
File "/Library/Python/2.7/site-packages/keras/models.py", line 581, in fit
shuffle=shuffle, metrics=metrics)
File "/Library/Python/2.7/site-packages/keras/models.py", line 239, in _fit
outs = f(ins_batch)
File "/Library/Python/2.7/site-packages/keras/backend/theano_backend.py", line 365, in __call__
return self.function(*inputs)
File "/Library/Python/2.7/site-packages/theano/compile/function_module.py", line 595, in __call__
outputs = self.fn()
File "/Library/Python/2.7/site-packages/theano/gof/vm.py", line 233, in __call__
link.raise_with_op(node, thunk)
File "/Library/Python/2.7/site-packages/theano/gof/vm.py", line 229, in __call__
thunk()
File "/Library/Python/2.7/site-packages/theano/gof/op.py", line 768, in rval
r = p(n, [x[0] for x in i], o)
File "/Library/Python/2.7/site-packages/theano/tensor/elemwise.py", line 808, in perform
raise ValueError(base_exc_str)
ValueError: Dimension mismatch; shapes are (98, 10), (98, 1)
Apply node that caused the error: Elemwise{Sub}[(0, 0)](Elemwise{Add}[(0, 0)].0, <TensorType(float32, matrix)>)
Inputs types: [TensorType(float32, matrix), TensorType(float32, matrix)]
Inputs shapes: [(98, 10), (98, 1)]
Inputs strides: [(40, 4), (4, 4)]
Inputs values: ['not shown', 'not shown']
HINT: Re-running with most Theano optimization disabled could give you a back-trace of when this node was created. This can be done with by setting the Theano flag 'optimizer=fast_compile'. If that does not work, Theano optimizations can be disabled with 'optimizer=None'.
HINT: Use the Theano flag 'exception_verbosity=high' for a debugprint and storage map footprint of this apply node.
最佳答案
预期输出维度 (98,10) 与您使用的数据维度 (98,1) 不匹配
那是因为您使用的示例代码应该对 10 类数据库进行分类。如果您想进行预测,请将最后一层更改为
model.add(Dense(output_dim=1, init="glorot_uniform"))
此外,我认为您的成本函数会有问题。如果您有连续数据,则不应使用绝对百分比误差。改变这个
model.compile(loss="mean_absolute_percentage_error", optimizer="rmsprop")
也许是这样
model.compile(loss="mean_squared_error", optimizer="rmsprop")
关于Python/Keras/Theano - 值错误 : Dimension mismatch; shapes are (98, 10), (98, 1),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35658519/
equal() 算法可以告诉我们两个序列是否匹配。mismatch() 算法也可以告诉我们两个序列是否匹配,而且如果不匹配,它还能告诉我们不匹配的位置。 mismatch() 的 4 个版本和 equ
我只是想在 emacs 中自定义一些 org-mode 导出设置,所以我做了 M-xcustomize-group组织导出 html。这是由 Customize buffer 提出的,除其他外,我着手
我正在尝试通过 ColdFusion 使用基于 HTTPS 的 SOAP WebService,但它返回“连接失败”。 在转储结果变量时,它显示: 错误详细信息:“I/O 异常:证书‘subdomai
我想匹配表单的输入:: commit a1b2c3 Author: Michael commit d3g4 Author: David 这是我写的语法: grammar commit; file
我正在尝试根据《Doing Bayesian Data Analysis: A Tutorial with R, JAGS, and Stan (2015)》一书来学习贝叶斯分析。 这本书里有例子。所
我有一些使用 java 泛型的类,一切都工作正常,直到我向类层次结构添加了一些附加层。 我想知道问题是否与“类型删除”有关,但我不确定如何表达继承来消除这个问题。 类定义: public interf
我正在尝试向我的应用程序添加一种语言,它一直运行到现在。经过一天尝试了解发生了什么,我放弃了。 这是我的问题: 我的基本语言是英语(开发语言),我的其他语言是法语。我在 Main.storyboard
我最近开始在 Go 中使用模块,但我经常遇到这样的问题,即在一台机器上一切正常,但在另一台机器上构建代码库时遇到校验和不匹配。 问题总是涉及相同的第三方依赖(github.com/ericlagerg
今天在用织梦系统搭建新站,在系统基本参数设置好了之后,像往常那样点击【确定】这个按钮,没想到却出现了Token mismatch!的提示,系统的基本参数无法改变,后经过查询,将出现Token mis
题目地址:https://leetcode.com/problems/set-mismatch/description/open in new window 题目描述 Theset S origi
在看似简单的任务上陷入了极大的困境...当我尝试隐藏 时出现类型不匹配错误多个 使用此代码的列.. 有什么更好的建议吗? 问候, Sub Hider() Sheets("Data So
大家好,我收到一个编译错误:类型不匹配。在下面的代码中。我希望你们能帮助我。谢谢! Private Sub cmbBusId_AfterUpdate() With Me .txtStOdo = App
我最近遇到了一条我从未见过的借用检查器消息,我试图理解它。这是重现它的代码(简化的,现实生活中的例子更复杂)- playground : fn foo(v1: &mut Vec, v2: &mut V
我尝试编写代码以打印Z字符。 zzzzzzz z z z z z zzzzzzz 但是当我编译这段代码时,它会抛出 D:\erlang\graphics>erlc zee
Sub Reset_Bet() Application.ScreenUpdating = False Sheets("Bet Angel").Select
我很难弄清楚这段应该是基本的代码片段出了什么问题。我想知道是否有人可以帮助我。任何想法都将非常感激,我对 VBA 还很陌生。 我的代码是: Dim table() as Variant: ta
我只是想从键盘读取整数、 double 、字符串值。它对于整数和 double 工作正常。但当涉及到字符串时,它会抛出输入不匹配异常,因此我无法从键盘读取字符串。 import java.util.S
给定一个学生花名册文件,其中第一行是类(class)中的学生人数,在接下来的几行中,我提供了他们的姓名、ID 和年龄,如下所示: 5 Mary, 1010, 15 Ben, 1
Android资源编译失败C:\Users\TTP\AndroidStudioProjects\TicCrossGame\app\src\main\res\layout\activity_main.x
found : (Int, String, Option[java.lang.String]) required: (Int, String, Option[java.lang.String])
我是一名优秀的程序员,十分优秀!