µ¥ÀÌÅÍ Ã³¸®½Ã, ÈÆ·Ã¿ë µ¥ÀÌÅÍ, °ËÁõ µ¥ÀÌÅÍ, Å×½ºÆ® µ¥ÀÌÅÍ·Î ³ª´²¼ Çϴ°ÍÀÌ ÁÁ´Ù. ÈÆ·Ã¿ë ¼Â(Train Set) : ÇнÀ¿¡ »ç¿ëµÇ´ÂÈÆ·Ã¿ë µ¥ÀÌÅÍ °ËÁõ¿ë ¼Â(Validation Set) : ÇнÀÁß¿¡ »ç¿ëµÇ´Â Æò°¡ µ¥ÀÌÅÍ Å×½ºÆ® ¼Â(Test Set) : ÇнÀÈÄ¿¡ »ç¿ëµÇ´Â Å×½ºÆ® µ¥ÀÌÅÍ validation_data´Â epoch 1¹øÀ» µ¹¶§¸¶´Ù °Ë»çÇÏ¿© w¸¦ ¼öÁ¤ÇÏ°Ô µÈ´Ù. fit(ÈÆ·Ã)Àº [x_train, y_train] ¿Í [x_val, y_val] »ç¿ë evaluate(Æò°¡)´Â [x_test, y_test] »ç¿ë ¼Ò½º´Â ´ÙÀ½°ú °°´Ù. # 1. µ¥ÀÌÅÍ Àüó¸®
from keras.models import Sequential from keras.layers import Dense import numpy as np x_train = np.linspace(1, 10, 10) y_train = x_train x_val = np.array([100,200,300,400,500]) y_val = x_val x_test = np.linspace(11, 20, 10) y_test = x_test # 2. ¸ðµ¨ ±¸¼º model = Sequential() model.add(Dense(10, input_dim=1, activation='linear')) model.add(Dense(10, activation='linear')) model.add(Dense(8, activation='linear')) model.add(Dense(1)) # 3. ¸ðµ¨ ÈÆ·Ã model.compile(optimizer='adam', loss='mse', metrics=['mae']) model.fit(x_train, y_train, epochs=100, verbose=0) # 4. ¸ðµ¨ Æò°¡ ¿¹Ãø loss_met = model.evaluate(x_test, y_test, batch_size=1) print(loss_met) predict = model.predict(x_test) print('y_test', y_test, ' predict: \n', predict) # ±×·¡ÇÁ ±×¸®±â import matplotlib.pyplot as plt plt.plot(x_test, predict, 'b', x_test, y_test, 'k.') plt.legend(['predict', 'y_test']) °á°ú) |