728x90
반응형
MNIST 선형 회귀
import tensorflow as tf
mnist = tf.keras.datasets.mnist
(X, YT), (x, yt) = mnist.load_data() #60000개의 학습데이터, 10000개의 검증데이터
X, x = X/255, x/255 # 60000x28x28, 10000x28x28
X, x = X.reshape((60000,784)), x.reshape((10000,784))
model = tf.keras.Sequential([
tf.keras.Input(shape=(784,)),
tf.keras.layers.Dense(512, activation='relu'),
tf.keras.layers.Dense(256, activation='relu'), # 은닉화
tf.keras.layers.Dense(128, activation='relu'), # 은닉화
tf.keras.layers.Dense(1, activation='linear')
]) # 신경망 모양 결정(W, B 내부적 준비)
model.compile(optimizer='adam',
loss='mse')
model.fit(X,YT,epochs=20)
y=model.predict(x)
print(y[0])
import matplotlib.pyplot as plt
x=x.reshape(10000,28,28)
plt.figure(figsize=(10,10))
for i in range(25):
plt.subplot(5,5,i+1)
plt.xticks([])
plt.yticks([])
plt.imshow(x[i], cmap=plt.cm.binary)
plt.xlabel(f'y{y[i]} yt{yt[i]}')
plt.show()
728x90
반응형
'즐거운프로그래밍' 카테고리의 다른 글
[딥러닝] 딥러닝 활용하기(cifar10 데이터 셋 학습하기) (0) | 2023.10.30 |
---|---|
[딥러닝] 딥러닝 활용하기(패션 MNIST 데이터 셋 학습하기) (0) | 2023.10.30 |
[딥러닝] 딥러닝 활용하기(손글씨 숫자 데이터 인식) (0) | 2023.10.30 |
[딥러닝] 딥러닝 목표값 변경, 은닉층 늘리기, 학습 후 모델 내보내기, 모델 불러와 예측하기 (0) | 2023.10.30 |
[딥러닝] 딥러닝 출력층에 linear 함수 적용해보기 (0) | 2023.10.30 |