【发布时间】:2021-10-10 20:52:36
【问题描述】:
我不确定是我遗漏了包裹还是问题出在了其他地方。既然我已经安装了 Miniforge 并制作了 venv 等,我就可以导入 TensorFlow。(对我为实现这一目标所做的工作并不完全有信心,但我能够在 TensorFlow 和基本 python env 之间切换。)我也能够创建和编译一个模型。但是,在运行 model.fit 时我并没有冗长,也无法从 model.history.history 获取训练历史记录。当我尝试获取历史记录时:
NameError: name 'model' is not defined'
我还注意到模型没有在 Vscode 中定义,它只是说加载。我试过设置 model.fit() = history 也没有帮助
我的尝试:
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
from tensorflow.keras import utils as np_utils
from keras.models import Sequential
from keras.layers import Dense, Activation
model = Sequential()
model.add(Dense(4, activation='relu'))
model.add(Dense(4, activation='relu'))
model.add(Dense(4, activation='relu'))
model.add(Dense(1))
#compiling the model, mean squared error is used for regression models
model.compile(optimizer='rmsprop', loss='mse')
model.fit(x = X_train,y=y_train,epochs=250, verbose=1)
model.history.history
数据:
' price feature1 feature2\n0 461.527929 999.787558 999.766096\n1 548.130011 998.861615 1001.042403\n2 410.297162 1000.070267 998.844015\n3 540.382220 999.952251 1000.440940\n4 546.024553 1000.446011 1000.338531\n.. ... ... ...\n995 476.526078 1000.018988 999.672732\n996 457.313186 998.855379 1000.020026\n997 456.720992 1001.451646 998.847606\n998 403.315576 1000.771023 998.562851\n999 599.367093 999.232244 1001.451407\n\n[1000 rows x 3 columns]' ```
【问题讨论】:
标签: python keras jupyter-notebook tensorflow2.0 tf.keras