728x90
반응형
Linear Rgression Architecture
import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.optimizers import SGD.Adam
from tensorflow.keras.layers import Flatten, Dense
import numpy as np
# 모델 생성
x_data = np.array([[..], [..], ..., [..]])
t_data = np.array([..])
# 모델 구축
model = Sequential()
model.add(Dense(1, input_shape(3,), activation = 'linear'))
# 모델 컴파일
model.compile(optimizer = SGD(learning_rate = 1e-2), loss = 'mse')
model.summary()
# 모델 학습
hist = model.fit(x_data, t_data, epochs = 1000)
# 모델 평가 및 예측
test_data [[...], [...], ..., [...]]
ret_val = [2*data[0] - 3*data[1] + 2*data[2] for data in test_data]
prediction_val = model.predict(np.array(test_data))
# 모델 입력
print(model.input)
# 모델 출력
print(model.output)
# 모델 가중치
print(model.weight)
# matplotlib를 이용한 시각화
import matplotlib.pyplot as plt
plt.title('Lostt Trend')
plt.xlabel('epochs')
plt.ylabel('loss')
plt.grid()
plt.plot(hist.history['loss'], label = 'trend loss')
plt.legend(loc = 'best')
plt.show()
반응형
'IT > 머신러닝공부' 카테고리의 다른 글
(Linear Regression Classification)피마 인디언 부족의 당뇨병 발병 여부를 예측하는 데이터 실습 (0) | 2022.12.25 |
---|---|
Logistic Regression - Classfication 요약 정리 (0) | 2022.12.25 |
머신러닝의 회귀(Regression)과 손실함수, GDA에 대한 간단정의 (0) | 2022.12.25 |
TensoFlow 및 Keras의 특장점 및 예제 코드 (0) | 2022.12.25 |
Docceptor 머신러닝 강의 학습 후기 (0) | 2022.12.19 |