从nnet_ts模块使用TimeSeriesNnet()方法会引发NameError [英] Using the TimeSeriesNnet() method from the nnet_ts module throws NameError

查看:152
本文介绍了从nnet_ts模块使用TimeSeriesNnet()方法会引发NameError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用python模块nnet-ts创建一个神经网络. 它具有一个名为TimeSeriesNnet()的内置方法,该方法带有两个参数. 隐藏层和激活功能.

I am trying to create a neural network using the python module nnet-ts. It has a built-in method named TimeSeriesNnet(), which takes two arguments; hidden_layers and activation_functions.

请参阅此模块的文档以及README.md中的示例:

See documentation for this module, as well as example in the README.md:

https://github.com/hawk31/nnet-ts

我正在运行python版本2.7.13

I am running python version 2.7.13

nnet-ts模块具有对5个特定软件包的依赖关系,我将在下面列出这些软件包以及正在使用的当前版本:

The nnet-ts module has dependencies to 5 particular packages, which I am listing below together with the current versions I am using:

numpy-1.13.0,pandas-0.20.2,scipy-0.19.0,theano-0.9.0和keras-2.0.5

numpy-1.13.0, pandas-0.20.2, scipy-0.19.0, theano-0.9.0 and keras-2.0.5

按照README(上面的链接)中的示例,我的代码如下:

Following the example in the README (link above), my code reads as follows:

from nnet_ts import *
neural_net = TimeSeriesNnet(hidden_layers = [7, 3], activation_functions = ['tanh', 'tanh'])

执行此代码将引发NameError.输出:

Execution of this code results in a NameError being thrown. Output:

NameError: name 'TimeSeriesNnet' is not defined

我的猜测是,此错误的原因可能与不同的模块版本有关,因为代码与README中给出的示例几乎相同.非常感谢您的帮助.

My guess is that the reason for this error could have something to do with different module versions, as the code is nearly identical to the example given in the README. Any help is much appreciated.

推荐答案

当然,您的代码部署有问题.对于您的Python开发,我建议始终使用本地虚拟环境.对于此神经网络时间序列,您可以使用python setup.py build命令在本地构建它,它将在build/lib.linux-x86_64-2.7目录中构建必要的文件.假设您具有所有依赖关系,那么应该没有任何问题.在部署中,您只需要将PYTHONPATH设置到该目录,或者只通过sys.path.insert()方法将此路径包含在运行时中即可.
例如,假设我在nnet-ts目录中,则按照以下步骤构建并运行nnet-ts:

Definitely, there is something wrong with your deployment of the code. For your Python developments, I suggest always use a local virtual environment. For this Neural Network Timeseries, you can build it locally with the python setup.py build command, it will build necessary files in the build/lib.linux-x86_64-2.7 directory. Assuming you have all dependencies, there shouldn't be any problem. In the deployment, you just have to set your PYTHONPATH to this directory, or you just include this path in the runtime with sys.path.insert() method.
For example, assuming I am in nnet-ts directory, I have built and run nnet-ts as follow:

    $ python setup.py build
    $ python
    > import sys
    > sys.path.insert(0, 'build/lib.linux-x86_64-2.7')
    > from nnet_ts import *
    > time_series = np.array(pd.read_csv("nnet_ts/AirPassengers.csv")["x"]) 
    > neural_net = TimeSeriesNnet(hidden_layers = [20, 15, 5], activation_functions = ['sigmoid', 'sigmoid', 'sigmoid'])

这篇关于从nnet_ts模块使用TimeSeriesNnet()方法会引发NameError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆