Visualize Model Training
來自專欄數據挖掘與機器學習-Python零碎筆記
# Visualize training historyfrom keras.models import Sequentialfrom keras.layers import Denseimport matplotlib.pyplot as pltimport numpy# fix random seed for reproducibilityseed = 7numpy.random.seed(seed)# load pima indians datasetdataset = numpy.loadtxt("pima-indians-diabetes.csv", delimiter=",")# split into input (X) and output (Y) variablesX = dataset[:,0:8]Y = dataset[:,8]# create modelmodel = Sequential()model.add(Dense(12, input_dim=8, kernel_initializer=uniform, activation=relu))model.add(Dense(8, kernel_initializer=uniform, activation=relu))model.add(Dense(1, kernel_initializer=uniform, activation=sigmoid))# Compile modelmodel.compile(loss=binary_crossentropy, optimizer=adam, metrics=[accuracy])# Fit the modelhistory = model.fit(X, Y, validation_split=0.33, epochs=150, batch_size=10, verbose=0)# list all data in historyprint(history.history.keys())# summarize history for accuracyplt.plot(history.history[acc])plt.plot(history.history[val_acc])plt.title(model accuracy)plt.ylabel(accuracy)plt.xlabel(epoch)plt.legend([train, test], loc=upper left)plt.show()# summarize history for lossplt.plot(history.history[loss])plt.plot(history.history[val_loss])plt.title(model loss)plt.ylabel(loss)plt.xlabel(epoch)plt.legend([train, test], loc=upper left)plt.show()
推薦閱讀:
TAG:科技 | 計算機視覺 | 深度學習DeepLearning |