我正在研究不同类型数据质量的拟合精度结果的比较。 “好数据”是特征值中没有任何NA的数据。 “坏数据”是特征值中具有 NA 的数据。 “坏数据”应该通过一些值修正来修复。作为值修正,它可能会用零或平均值替换 NA。
在我的代码中,我尝试执行多个拟合过程。
查看简化的代码:
from keras import backend as K
...
xTrainGood = ... # the good version of the xTrain data
xTrainBad = ... # the bad version of the xTrain data
...
model = Sequential()
model.add(...)
...
historyGood = model.fit(..., xTrainGood, ...) # fitting the model with
# the original data without
# NA, zeroes, or the feature mean values
检查拟合精度图,基于historyGood
data:
之后,代码重置存储的模型并使用“坏”数据重新训练模型:
K.clear_session()
historyBad = model.fit(..., xTrainBad, ...)
检查拟合过程结果,基于historyBad
data:
正如人们所注意到的,初始精度> 0.7
,这意味着模型“记住”之前的拟合。
为了进行比较,这是“坏”数据的独立拟合结果:
如何将模型重置到“初始”状态?
K.clear_session()
不足以重置状态并确保可重复性。您还需要:
- 设置(和重置)随机种子
- 重置 TensorFlow 默认图
- 删除之前的模型
完成下面每一项的代码。
reset_seeds()
model = make_model() # example function to instantiate model
model.fit(x_good, y_good)
del model
K.clear_session()
tf.compat.v1.reset_default_graph()
reset_seeds()
model = make_model()
model.fit(x_bad, y_bad)
请注意,如果其他变量引用该模型,您应该del
他们也 - 例如model = make_model(); model2 = model
--> del model, model2
- 否则他们可能会坚持下去。最后,tf
随机种子不像random
's or numpy
的,并要求事先清除图表。
Function/modules used:
import tensorflow as tf
import numpy as np
import random
import keras.backend as K
def reset_seeds():
np.random.seed(1)
random.seed(2)
if tf.__version__[0] == '2':
tf.random.set_seed(3)
else:
tf.set_random_seed(3)
print("RANDOM SEEDS RESET")
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)