Исходя из графика потерь и обучения, приведенного в ссылке ниже, моя модель соответствует или недостаточно подходит? Какое количество эпох лучше? И как мне сократить разрыв между тренировкой и потерей проверки? Ниже приведен мой код, и набор данных состоит из 6 столбцов независимых переменных (целых) и 1 столбца зависимой переменной (двоичный результат, т. Е. 0 или 1).
График потерь при обучении и проверке
from keras.models import Sequential
from keras.layers.core import Dense, Dropout
from numpy import loadtxt
from keras.optimizers import SGD, RMSprop
#from keras.utils import np_utils, generic_utils
*#import theano (*not sure if this is required to plot the validation and #training loss. I've tested the code without this import function, seems #to work)*
#import os *(Same remark as above *)*
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
#import cv2 *(Same remark as above *)*
from sklearn.model_selection import train_test_split
from sklearn.model_selection import cross_validate
# load the dataset
dataset = loadtxt('numbers.csv', delimiter=',')
# split into input (X) and output (y) variables
X = dataset[:,0:6]
y = dataset[:,6]
# define the keras model
model = Sequential()
model.add(Dense(32, input_dim=6, activation='relu'))
model.add(Dropout(0.40))
model.add(Dense(16, activation='sigmoid'))
model.add(Dense(1, activation='sigmoid'))
# compile the keras model
model.compile(loss='binary_crossentropy', optimizer='SGD', metrics=['accuracy'])
# fit the keras model on the dataset
epochs=50
nb_epoch=epochs
batch_size=100
batch_size=batch_size
model.fit(X, y, nb_epoch, batch_size)
# Split the data
X_train_new, X_val_new, y_train_new,y_val_new = train_test_split(X, y,
test_size=0.2, random_state=4)
# Train the model
hist = model.fit(X_train_new, y_train_new, validation_data=(X_val_new,y_val_new),
batch_size=batch_size,nb_epoch = nb_epoch, shuffle=True, verbose=2)
# Evaluate the model
score = model.evaluate(X_val_new, y_val_new, batch_size=batch_size)
print('Test score:', score[0])
print('Test accuracy:', score[1])
# Plot the results
train_loss=hist.history['loss']
val_loss=hist.history['val_loss']
train_acc=hist.history['accuracy']
val_acc=hist.history['val_accuracy']
xc=range(50)
plt.figure(1,figsize=(7,5))
plt.plot(xc,train_loss)
plt.plot(xc,val_loss)
plt.xlabel('num of Epochs')
plt.ylabel('loss')
plt.title('train_loss vs val_loss')
plt.grid(True)
plt.legend(['train','val'])
plt.style.use(['classic'])
plt.figure(2,figsize=(7,5))
plt.plot(xc,train_acc)
plt.plot(xc,val_acc)
plt.xlabel('num of Epochs')
plt.ylabel('accuracy')
plt.title('train_acc vs val_acc')
plt.grid(True)
plt.legend(['train','val'],loc=4)
plt.style.use(['classic'])