Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 千层面回归:错误_Python_Theano_Deep Learning - Fatal编程技术网

Python 千层面回归:错误

Python 千层面回归:错误,python,theano,deep-learning,Python,Theano,Deep Learning,我正试着用千层面/nolearn进行回归。我很难找到如何做到这一点的文档(一般来说,深度学习是新的) 从一个简单的网络开始(一个隐藏层) 我得到以下错误: TypeError Traceback (most recent call last) <ipython-input-23-23c15ceec104> in <module>() ----> 1 net_s.fit(X, y) /home/alex

我正试着用千层面/nolearn进行回归。我很难找到如何做到这一点的文档(一般来说,深度学习是新的)

从一个简单的网络开始(一个隐藏层)

我得到以下错误:

TypeError                                 Traceback (most recent call last)
<ipython-input-23-23c15ceec104> in <module>()
----> 1 net_s.fit(X, y)

/home/alex/anaconda3/lib/python3.4/site-packages/nolearn/lasagne.py in fit(self, X, y)
    148             out, self.loss, self.update,
    149             self.X_tensor_type,
--> 150             self.y_tensor_type,
    151             )
    152         self.train_iter_, self.eval_iter_, self.predict_iter_ = iter_funcs

/home/alex/anaconda3/lib/python3.4/site-packages/nolearn/lasagne.py in _create_iter_funcs(self, output_layer, loss_func, update, input_type, output_type)
    298         all_params = get_all_params(output_layer)
    299         update_params = self._get_params_for('update')
--> 300         updates = update(loss_train, all_params, **update_params)
    301 
    302         train_iter = theano.function(

/home/alex/src/lasagne/lasagne/updates.py in nesterov_momentum(loss, all_params, learning_rate, momentum)
     38 # such that the gradient can be evaluated at the current parameters.
     39 def nesterov_momentum(loss, all_params, learning_rate, momentum=0.9):
---> 40     all_grads = theano.grad(loss, all_params)
     41     updates = []
     42 

/home/alex/anaconda3/lib/python3.4/site-packages/theano/gradient.py in grad(cost, wrt, consider_constant, disconnected_inputs, add_names, known_grads, return_disconnected)
    431 
    432     if cost is not None and cost.ndim != 0:
--> 433         raise TypeError("cost must be a scalar.")
    434 
    435     if isinstance(wrt, set):

TypeError: cost must be a scalar.
TypeError回溯(最近一次调用)
在()
---->1净配合(X,y)
/home/alex/anaconda3/lib/python3.4/site-packages/nolearn/lasagne.py in-fit(self,X,y)
148出,自我丢失,自我更新,
149自X_张量型,
-->150自y张量型,
151             )
152 self.train\u iter\u,self.eval\u iter\u,self.predict\u iter=iter\u函数
/home/alex/anaconda3/lib/python3.4/site-packages/nolearn/lasagne.py in\u create\u iter\u funcs(self、output\u layer、loss\u func、update、input\u type、output\u type)
298所有参数=获取所有参数(输出层)
299 update_params=self._get_params_for('update'))
-->300更新=更新(丢失列车,所有参数,**更新参数)
301
302列车=列车号功能(
/nesterov_momentum中的home/alex/src/lasagne/lasagne/updates.py(损失、所有参数、学习率、动量)
38#以便可以在当前参数下评估梯度。
39 def nesterov_动量(损失、所有参数、学习率、动量=0.9):
--->40所有梯度=编号梯度(损失,所有参数)
41更新=[]
42
/home/alex/anaconda3/lib/python3.4/site-packages/theano/gradient.py(成本、wrt、考虑常数、断开的输入、添加名称、已知的梯度、返回断开的)
431
432如果成本不是无且成本.ndim!=0:
-->433 raise TypeError(“成本必须是标量”)
434
435如果存在(wrt,set):
TypeError:成本必须是标量。

谢谢!。

不确定您使用的是什么版本的nolearn和千层面。我确实注意到您的
y
形状为
(137,)
。从我的使用情况来看,这需要
(137,1)
才能适用于您的情况,并且通常,dim 2需要与
输出的数量单位相匹配

尝试
y。重塑(-1,1))


如果这不起作用,则可能是Python 3的兼容性问题。

请确保您使用的nolearn和Lasagne版本是已知可以协同工作的版本

假设您一直在遵循。那么正确的做法是从安装依赖项,如下所示:

pip uninstall Lasagne
pip uninstall nolearn
pip install -r https://raw.githubusercontent.com/dnouri/kfkd-tutorial/master/requirements.txt
但是,如果您使用的是Git master的nolearn,请确保安装的千层面版本位于:


你找到了这个问题的解决方案了吗?我遇到了完全相同的错误消息。我遇到了一个类似的问题,这就解决了问题。谢谢!如果你在将数据发送到NeuralNet时无法确定数据的形状:对于分类任务,目标向量
y
必须具有一维仅限n。对于回归任务,无论回归目标的数量如何,它总是有两个维度。下面是一些代码来说明这一点:
pip uninstall Lasagne
pip uninstall nolearn
pip install -r https://raw.githubusercontent.com/dnouri/kfkd-tutorial/master/requirements.txt
pip uninstall Lasagne
pip install -r https://raw.githubusercontent.com/dnouri/nolearn/master/requirements.txt