Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/314.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 我试图定义LSTM并得到错误;TypeError:add()缺少1个必需的位置参数:';层'&引用;_Python_Lstm_Add - Fatal编程技术网

Python 我试图定义LSTM并得到错误;TypeError:add()缺少1个必需的位置参数:';层'&引用;

Python 我试图定义LSTM并得到错误;TypeError:add()缺少1个必需的位置参数:';层'&引用;,python,lstm,add,Python,Lstm,Add,x_火车形状 (1271, 322) x_scaler=MinMaxScaler() x_列=x_定标器。拟合变换(x_列) y_train.shape (1271, 161) y_scaler=MinMaxScaler() y_列=y_定标器。拟合变换(y_列) x_列=x_列。重塑(1271321) reg=顺序 注册添加(LSTM(单位=200,激活='relu',输入形状=(322,1))) 注册添加(密度(161)) TypeError回溯(最近一次调用上次) 在() 1 reg=顺

x_火车形状 (1271, 322) x_scaler=MinMaxScaler() x_列=x_定标器。拟合变换(x_列) y_train.shape (1271, 161) y_scaler=MinMaxScaler() y_列=y_定标器。拟合变换(y_列) x_列=x_列。重塑(1271321) reg=顺序 注册添加(LSTM(单位=200,激活='relu',输入形状=(322,1))) 注册添加(密度(161))


TypeError回溯(最近一次调用上次)
在()
1 reg=顺序
---->2注册添加(LSTM(单位=200,激活='relu',输入形状=(322,1)))
3条例增补(密度(161))
/usr/local/lib/python3.6/dist-packages/tensorflow/python/training/tracking/base.py in_method_wrapper(self,*args,**kwargs)
455 self._self_setattr_tracking=False#pylint:disable=protected access
456试试:
-->457结果=方法(自身、*args、**kwargs)
458最后:
459 self._self_setattr_tracking=上一个值#pylint:disable=受保护访问
TypeError:add()缺少1个必需的位置参数:“层”

这个模型定义对我来说很好:


TypeError                                 Traceback (most recent call last)
<ipython-input-43-ab4dcb49e16c> in <module>()
      1 reg = Sequential
----> 2 reg.add(LSTM(units = 200, activation = 'relu', input_shape = (322, 1)))
      3 reg.add(Dense(161))

/usr/local/lib/python3.6/dist-packages/tensorflow/python/training/tracking/base.py in _method_wrapper(self, *args, **kwargs)
    455     self._self_setattr_tracking = False  # pylint: disable=protected-access
    456     try:
--> 457       result = method(self, *args, **kwargs)
    458     finally:
    459       self._self_setattr_tracking = previous_value  # pylint: disable=protected-access

TypeError: add() missing 1 required positional argument: 'layer'
还要检查您是否编写了
reg=Sequential
,我认为应该是这样的
reg=Sequential()

尝试在序列之后添加paradensis“()”,它应该可以解决问题。

TypeError                                 Traceback (most recent call last)
<ipython-input-43-ab4dcb49e16c> in <module>()
      1 reg = Sequential
----> 2 reg.add(LSTM(units = 200, activation = 'relu', input_shape = (322, 1)))
      3 reg.add(Dense(161))

/usr/local/lib/python3.6/dist-packages/tensorflow/python/training/tracking/base.py in _method_wrapper(self, *args, **kwargs)
    455     self._self_setattr_tracking = False  # pylint: disable=protected-access
    456     try:
--> 457       result = method(self, *args, **kwargs)
    458     finally:
    459       self._self_setattr_tracking = previous_value  # pylint: disable=protected-access

TypeError: add() missing 1 required positional argument: 'layer'
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import layers
from tensorflow.keras import Sequential
from tensorflow.keras.layers import LSTM,Dense


reg = Sequential()
reg.add(LSTM(units = 200, activation = 'relu', input_shape = (322, 1))) 
reg.add(Dense(161))