Introduction à Deep Learning avec Keras
Miguel Esteban
Data Scientist & Founder


# Entraîner un modèle et sauvegarder son historique history = model.fit(X_train, y_train, epochs=100, metrics=['accuracy'])print(history.history['loss'])
[0.6753975939750672, ..., 0.3155936544282096]
print(history.history['accuracy'])
[0.7030952412741525, ..., 0.8604761900220599]
# Entraîner un modèle et sauvegarder son historique history = model.fit(X_train, y_train, epochs=100, validation_data=(X_test, y_test), metrics=['accuracy'])print(history.history['val_loss'])
[0.7753975939750672, ..., 0.4155936544282096]
print(history.history['val_accuracy'])
[0.6030952412741525, ..., 0.7604761900220599]
# Tracer l'exactitude entraînement vs test par époque plt.figure()# Utiliser les mesures de l'historique plt.plot(history.history['accuracy']) plt.plot(history.history['val_accuracy'])# Soigner la présentation plt.title('Exactitude du modèle') plt.ylabel('Exactitude') plt.xlabel('Époque') plt.legend(['Entraînement', 'Test']) plt.show()


# Importer l'arrêt hâtif depuis keras.callbacks from tensorflow.keras.callbacks import EarlyStopping# Instancier un rappel d'arrêt hâtif early_stopping = EarlyStopping(monitor='val_loss', patience=5)# Entraîner le modèle avec le rappel model.fit(X_train, y_train, epochs=100, validation_data=(X_test, y_test), callbacks = [early_stopping])
# Importer la sauvegarde de modèle depuis keras.callbacks from keras.callbacks import ModelCheckpoint# Instancier un rappel de point de contrôle du modèle model_save = ModelCheckpoint('best_model.hdf5', save_best_only=True)# Entraîner le modèle avec le rappel model.fit(X_train, y_train, epochs=100, validation_data=(X_test, y_test), callbacks = [model_save])
Introduction à Deep Learning avec Keras