gpt4 book ai didi

python - 模块 'tensorflow' 没有带有股票预测的属性 'get_default_graph'

转载 作者:行者123 更新时间:2023-12-04 10:14:47 25 4
gpt4 key购买 nike

我试图在 page 中使用相同的代码但我在代码中间遇到错误。

    AttributeError                            Traceback (most recent call last)
<ipython-input-34-9ff70788070d> in <module>()
----> 1 model = Sequential()
2 model.add(LSTM(units=50, return_sequences=True,input_shape=(x_train.shape[1],1)))
3 model.add(LSTM(units=50, return_sequences=False))
4 model.add(Dense(units=25))
5 model.add(Dense(units=1))

1 frames
/usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py in get_uid(prefix)
66 """
67 global _GRAPH_UID_DICTS
---> 68 graph = tf.get_default_graph()
69 if graph not in _GRAPH_UID_DICTS:
70 _GRAPH_UID_DICTS[graph] = defaultdict(int)

AttributeError: module 'tensorflow' has no attribute 'get_default_graph'

这是我的进口 list :
    #Import the libraries
from tensorflow.keras import backend as K
from tensorflow.keras.models import Sequential, load_model
from tensorflow.keras.layers import LSTM, Dense, RepeatVector, Masking, TimeDistributed
from tensorflow. keras.utils import plot_model
import quandl
import numpy as np
from sklearn.linear_model import LinearRegression
from sklearn.svm import SVR
import pandas_datareader as web

from sklearn.model_selection import train_test_split
import math
from keras.models import Sequential


from keras.layers import Dense, LSTM
from sklearn.preprocessing import MinMaxScaler
#import tensorflow as tf
#newinv=inventory+str(add)
from tensorflow.keras.layers import Embedding

from matplotlib import pyplot as plt
python tensorflow machine-learning keras

更新:根据 Giorgos 的回答编辑代码后,不,我知道这是错误:
NameError                                 Traceback (most recent call last)
<ipython-input-20-9ff70788070d> in <module>()
----> 1 model = Sequential()
2 model.add(LSTM(units=50, return_sequences=True,input_shape=(x_train.shape[1],1)))
3 model.add(LSTM(units=50, return_sequences=False))
4 model.add(Dense(units=25))
5 model.add(Dense(units=1))

NameError: name 'Sequential' is not defined

这是我的进口 list :
       import math
import pandas_datareader as web
import numpy as np
import pandas as pd
from sklearn.preprocessing import MinMaxScaler
import quandl
import tensorflow as tf
model = tf.keras.Sequential()
from keras.layers import Dense, LSTM
import matplotlib.pyplot as plt
plt.style.use('fivethirtyeight')

这是我收到错误的地方:
#Build the LSTM network model
model = Sequential()
model.add(LSTM(units=50, return_sequences=True,input_shape=(x_train.shape[1],1)))
model.add(LSTM(units=50, return_sequences=False))
model.add(Dense(units=25))
model.add(Dense(units=1))

最佳答案

如果您使用 tf.keras , 代替

from keras.models import Sequential
from keras.layers import Dense, LSTM

使用以下内容:
import tensorflow as tf


model = tf.keras.Sequential()
model.add(tf.keras.layers.LSTM(units=50, return_sequences=True,input_shape=(x_train.shape[1],1)))
model.add(tf.keras.layers.LSTM(units=50, return_sequences=False))
model.add(tf.keras.layers.Dense(units=25))
model.add(tf.keras.layers.Dense(units=1))

并确保删除旧的导入 from keras.models import Sequential这样 Sequential()在命名空间中不会被覆盖。同样适用于 from keras.layers import Dense, LSTM .

关于python - 模块 'tensorflow' 没有带有股票预测的属性 'get_default_graph',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61123134/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com