-
Notifications
You must be signed in to change notification settings - Fork 0
/
Keras04_validation.py
37 lines (31 loc) · 1.22 KB
/
Keras04_validation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import numpy as np
import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
# y=wx + b
# 1. 데이터 셋
x_train = np.array([1,2,3,4,5])
y_train = np.array([1,2,3,4,5])
x_validation = np.array([6,7,8])#(머신이)검증용 데이터
y_validation = np.array([6,7,8])#array 안에 list형태로 넣기
x_test = np.array([9,10,11]) #(사람이)테스트 데이터
y_test = np.array([9,10,11])
# 2.모델
model = Sequential()
model.add(Dense(5, input_dim = 1, activation= 'relu'))
model.add(Dense(3)) #안쓰면 디폴트 값 있음. linear
model.add(Dense(4))
model.add(Dense(1))
# 3. 컴파일, 훈련
#model.compile(loss='mse', optimizer='adam', metrics=['accuracy'])#accuracy = 정확도
#model.compile(loss='mse', optimizer='adam', metrics=['mse'])#MSE (Mean Squared Error)
model.compile(loss='mse', optimizer='adam', metrics=['mae'])#MAE (Mean Absolute Error)
model.fit(x_train, y_train, epochs=100, batch_size=1,
validation_data=(x_validation, y_validation)#검증 set을 더 신뢰할 수 있음
)
# 4. 평가
loss = model.evaluate(x_test, y_test, batch_size=1)
print('loss : ', loss)
#result = model.predict([9])
result = model.predict(x_train)
print('result : ', result)