-
Notifications
You must be signed in to change notification settings - Fork 0
/
keras05_RMSE.py
45 lines (32 loc) · 1.17 KB
/
keras05_RMSE.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
38
39
40
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
import numpy as np
from numpy import array
#np.array()
#array()
#1.데이터
x_train = np.array([1,2,3,4,5,6,7,8,9,10])
y_train = np.array([1,2,3,4,5,6,7,8,9,10])
x_test = array([11,12,13,14,15])
y_test = array([11,12,13,14,15])
x_pred = array([16,17,18]) #예측값 x에 대한 y를 예측
#2.모델구성
model = Sequential()
model.add(Dense(10, input_dim=1, activation='relu'))
model.add(Dense(20))
model.add(Dense(5))
model.add(Dense(1))
#3. 컴파일, 훈련
model.compile(loss='mse', optimizer='adam', metrics=['mae'])
model.fit(x_train, y_train, epochs=100, batch_size=1, validation_split=0.2)
#4. 평가, 예측
results = model.evaluate(x_test, y_test, batch_size=1)
print('results : ', results)
y_predict = model.predict(x_test) #x_pred를 넣어서 예측한 값
#print('y_predict : ', y_predict)
#사이킷런이 뭔지 2분 검색 sikit-learn
from sklearn.metrics import mean_squared_error
def RMSE(y_test, y_predict) :
return np.sqrt(mean_squared_error(y_test, y_predict)) #sqrt는 루트
print("RMSE :" , RMSE(y_test, y_predict))
# 실습 RMSE를 0.1이하로 낮추시오!!