def build_model():
    model = Sequential()
    model.add(Dense(units = 4, activation = 'relu', input_shape = (8, )))
    model.add(Dense(units = 20, activation = 'relu'))
    model.add(Dense(units = 10, activation = 'relu'))
    model.add(Dense(units = 1, activation = 'linear'))

    # 옵티마이저의 learning rate를 설정하는 방법
    model.compile(tf.keras.optimizers.RMSprop(learning_rate = 0.001), loss = 'mse', metrics = ['mse', 'mae'])
    #model.compile('adam', 'mse')
    return model

model = build_model()
early_stop = tf.keras.callbacks.EarlyStopping(monitor = 'val_loss', patience = 10)
epoch_history = model.fit(X_train, y_train, epochs = 100000, validation_split = 0.2, callbacks = [early_stop])
# 콜백이란?? 프레임워크가 실행하는 코드. 코드 실행을 프레임워크에 맡기는 것

monitor 파라미터에는 감시할 평가 데이터를 대입하고 patience에는 몇번 동안 개선이 없으면 학습을 중단할 건지 대입한다. 이걸 fit의 callbacks에 배열로 대입하면 된다.epochs에 십만을 대입했지만 실제로는 200번대 에서 중단했다.

+ Recent posts