コード例 #1
0
def train_net_intra(model, file):
    appX = []
    appy = []
    init = time.time()
    X, flash = prefilter.prepare_data(file, cutoff=[0.5, 30], fs=250.0)
    X_clean, y_clean = prefilter.clean_data(X, flash)
    appX.append(X_clean)
    appy.append(y_clean)
    X = [subject for subject in appX]
    y = [subject for subject in appy]
    X_train, X_valid, y_train, y_valid = train_test_split(np.vstack(X),
                                                          np.vstack(y),
                                                          test_size=0.1)
    history = model.fit(X_train,
                        y_train,
                        validation_data=(X_valid, y_valid),
                        batch_size=10,
                        epochs=50,
                        verbose=1)
    end = time.time()
    print("time elapsed training is:", (end - init) / 60, " minutes")
    return history.history['accuracy'], history.history[
        'val_accuracy'], history.history['loss'], history.history['val_loss']
コード例 #2
0
acc, val_acc, loss, val_loss = modeling.train_net(model, files)

plt.rcParams["figure.figsize"] = (10, 7)
plt.plot(acc)
plt.plot(val_acc)
plt.title('Model accuracy')
plt.ylabel('Accuracy')
plt.xlabel('Epoch')
plt.legend(['Train', 'Valid'], loc='upper left')
plt.show()

from sklearn.model_selection import train_test_split

X, Flash = prefilter.prepare_data(test_subject, cutoff=[0.5, 30], fs=250.0)
X_clean, y_clean = prefilter.clean_data(X, Flash)
X_train, X_test, y_train, y_test = train_test_split(X_clean,
                                                    y_clean,
                                                    test_size=0.1)
history = model.fit(X_train, y_train, batch_size=1, epochs=30)

plt.plot(history.history['accuracy'])
plt.title('Model accuracy')
plt.ylabel('Accuracy')
plt.xlabel('Epoch')
plt.legend(['Test'], loc='upper left')
plt.show()

# Plot test loss values
plt.plot(history.history['loss'])
plt.title('Model loss')