Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/335.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 Keras模型分类为每个模型重新编译返回不同的结果_Python_Tensorflow_Keras_Deep Learning - Fatal编程技术网

Python Keras模型分类为每个模型重新编译返回不同的结果

Python Keras模型分类为每个模型重新编译返回不同的结果,python,tensorflow,keras,deep-learning,Python,Tensorflow,Keras,Deep Learning,我从Keras开始创建一个模型,通过输入两个文本特征和一个输出对文本标签进行分类。我有一个特定的函数来创建模型,还有一个函数使用不同的数据集来测试模型 我仍在尝试微调模型预测,但我想尝试理解为什么每次重新创建模型时,我的测试函数都会得到不同的结果。通常是这样吗?另外,我也非常感谢任何提高模型准确性的建议 def创建模型(模型名称、数据、测试数据): def验证模型(模型名称、测试数据、标签): 我在下面读了你的培训代码 model.fit([x_train,y_train], z_train,

我从Keras开始创建一个模型,通过输入两个文本特征和一个输出对文本标签进行分类。我有一个特定的函数来创建模型,还有一个函数使用不同的数据集来测试模型

我仍在尝试微调模型预测,但我想尝试理解为什么每次重新创建模型时,我的测试函数都会得到不同的结果。通常是这样吗?另外,我也非常感谢任何提高模型准确性的建议

def创建模型(模型名称、数据、测试数据):

def验证模型(模型名称、测试数据、标签):


我在下面读了你的培训代码

model.fit([x_train,y_train], z_train,
                batch_size=batch_size,
                epochs=30,
                verbose=1,
                validation_split=0.1)
您正在使用[x_-train,y_-train]作为模型的特征,z_-train作为模型的标签。y_列是标签的原始形式,z_列是标签的编码形式


这样,您会将信息泄漏到训练集,从而导致过度拟合的情况。您的模型根本不是泛化的,因此会预测不相关的结果。

我不认为使用培训集进行培训是一种信息泄露,这到底发生在哪里?y_train正在接收第二个功能的“类别”列。标签名为“活动”。为什么那会太合适了?
from keras.models import model_from_json
test_data['Subject'] = test_data['Subject'] + " " + test_data['Description']
headlines = test_data['Subject'].astype(str)     
categories = test_data['Category'].astype(str)

# load json and create model
json_file = open("./outputs/my_model_"+model_name+".json", 'r') 
loaded_model_json = json_file.read()
json_file.close()
model = model_from_json(loaded_model_json)
# load weights into new model
model.load_weights('./outputs/my_model_'+model_name+'.h5')
print("Loaded model from disk")
# loading
import pickle
with open('./outputs/tokenizer'+model_name+'.pickle', 'rb') as handle:
    tokenizer = pickle.load(handle)    
# Subjects 
x_pred = tokenizer.texts_to_matrix(headlines, mode='tfidf')
# Categorias
y_pred = tokenizer.texts_to_matrix(categories, mode='tfidf')  
predictions = []
scores = []
predictions_vetor = model.predict({'main_input': x_pred, 'cat_input': y_pred}) 
model.fit([x_train,y_train], z_train,
                batch_size=batch_size,
                epochs=30,
                verbose=1,
                validation_split=0.1)