ÄÉ¶ó½º °á°ú¸¦ ±×·¡ÇÁ·Î ±×·Á¼ ¿¹Ãø °ª°ú ½ÇÁ¦ °ªÀÌ ¾î¶»°Ô ´Ù¸¥Áö È®ÀÎ Çغ¸ÀÚ. ±×·¡ÇÁ´Â matplotlib·Î ±×¸°´Ù. # 1. µ¥ÀÌÅÍ Àüó¸®
from keras.models import Sequential from keras.layers import Dense import numpy as np x = np.linspace(1, 10, 10) y = x # 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, y, epochs=100, verbose=0) # 4. ¸ðµ¨ Æò°¡ ¿¹Ãø loss_met = model.evaluate(x, y, batch_size=1) print(loss_met) predict = model.predict(x) print('y', y, ' predict: \n', predict) # RMSE ±¸Çϱâ from sklearn.metrics import mean_squared_error def RMSE(y_test, y_predict): return np.sqrt(mean_squared_error(y_test, y_predict)) print('RMSE : ', RMSE(y, predict)) # R2 ±¸Çϱâ from sklearn.metrics import r2_score r2_predict = r2_score(y, predict) print('R2 : ', r2_predict) # ±×·¡ÇÁ ±×¸®±â import matplotlib.pyplot as plt plt.plot(x, predict, 'b', x, y, 'k.') plt.legend(['predict', 'y']) °á°ú) matplotlibÀÇ 3ÁÙ ¸¸À¸·Î À§ÀÇ ±×·¡ÇÁ¸¦ ±×¸±¼ö ÀÖ´Ù. import matplotlib.pyplot as plt
plt.plot(x, predict, 'b', x, y, 'k.') plt.legend(['predict', 'y']) plt.plot(x, predict, 'b', x, y, 'k.')¿¡¼ µÎ°³ÀÇ ±×·¡ÇÁ¸¦ ±×¸®°í ÀÖ´Ù. x¿Í predict °ªÀ¸·Î ÆĶõ»ö 'b' ¶óÀÎÀ» ±×¸°´Ù. x¿Í y °ªÀ¸·Î °ËÀº»ö 'k.' Á¡À» ±×¸°´Ù. plt.legend(['predict', 'y']) ¹ü·Ê 'predict', 'y'¸¦ ±×¸°´Ù. Âü°í) matplotlib¿¡¼ ¿©·¯°³ÀÇ ±×·¡ÇÁ ±×¸®±â https://dsbook.tistory.com/275 |