AI & Data Analysis/인공지능 스터디
[모두의 딥러닝] #10장: 모델 설계하기
by 로토마
2022. 1. 25.
본격적인 딥러닝 모델 설계하기의 첫 걸음이다. tensorflow의 keras를 통해 모델을 설계하는 방법을 공부했다.
딥러닝 구조를 짜고, 층을 설정하고, 컴파일하는 방법, 또 실행하여 정확도를 출력하여 모델이 잘 구축되었는지 확인하며, 실습을 통해 더 알차게 공부할 수 있었다.
실습 코드)
폐암 수술 환자의 생존율 예측하기
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
|
Open In Colab
# 딥러닝을 구동하는 데 필요한 케라스 함수를 불러옵니다.
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
# 필요한 라이브러리를 불러옵니다.
import numpy as np
import tensorflow as tf
# 실행할 때마다 같은 결과를 출력하기 위해 설정하는 부분입니다.
np.random.seed(3)
tf.random.set_seed(3)
# 준비된 수술 환자 데이터를 불러들입니다.
Data_set = np.loadtxt("dataset/ThoraricSurgery.csv", delimiter=",")
# 환자의 기록과 수술 결과를 X와 Y로 구분하여 저장합니다.
X = Data_set[:,0:17]
Y = Data_set[:,17]
# 딥러닝 구조를 결정합니다(모델을 설정하고 실행하는 부분입니다).
model = Sequential()
model.add(Dense(30, input_dim=17, activation='relu'))
model.add(Dense(1, activation='sigmoid'))
# 딥러닝을 실행합니다.
입력)
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
model.fit(X, Y, epochs=100, batch_size=10)
Epoch 1/100
47/47 [==============================] - 1s 2ms/step - loss: 0.6482 - accuracy: 0.8128
Epoch 2/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4890 - accuracy: 0.8468
Epoch 3/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4416 - accuracy: 0.8511
Epoch 4/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4863 - accuracy: 0.8489
Epoch 5/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4430 - accuracy: 0.8532
Epoch 6/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4303 - accuracy: 0.8532
Epoch 7/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4421 - accuracy: 0.8511
Epoch 8/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4363 - accuracy: 0.8489
Epoch 9/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4165 - accuracy: 0.8489
Epoch 10/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4317 - accuracy: 0.8489
Epoch 11/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4458 - accuracy: 0.8489
Epoch 12/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4384 - accuracy: 0.8532
Epoch 13/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4651 - accuracy: 0.8532
Epoch 14/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4475 - accuracy: 0.8319
Epoch 15/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4934 - accuracy: 0.8255
Epoch 16/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4472 - accuracy: 0.8447
Epoch 17/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4747 - accuracy: 0.8383
Epoch 18/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4488 - accuracy: 0.8468
Epoch 19/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4407 - accuracy: 0.8511
Epoch 20/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4380 - accuracy: 0.8511
Epoch 21/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4331 - accuracy: 0.8532
Epoch 22/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4242 - accuracy: 0.8511
Epoch 23/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4183 - accuracy: 0.8532
Epoch 24/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4303 - accuracy: 0.8489
Epoch 25/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4246 - accuracy: 0.8511
Epoch 26/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4335 - accuracy: 0.8532
Epoch 27/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4492 - accuracy: 0.8383
Epoch 28/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4241 - accuracy: 0.8532
Epoch 29/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4212 - accuracy: 0.8532
Epoch 30/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4136 - accuracy: 0.8511
Epoch 31/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4389 - accuracy: 0.8511
Epoch 32/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4188 - accuracy: 0.8553
Epoch 33/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4428 - accuracy: 0.8532
Epoch 34/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4102 - accuracy: 0.8489
Epoch 35/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4178 - accuracy: 0.8489
Epoch 36/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4136 - accuracy: 0.8532
Epoch 37/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4429 - accuracy: 0.8511
Epoch 38/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4258 - accuracy: 0.8489
Epoch 39/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4715 - accuracy: 0.8319
Epoch 40/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4041 - accuracy: 0.8574
Epoch 41/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4210 - accuracy: 0.8511
Epoch 42/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4419 - accuracy: 0.8447
Epoch 43/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4097 - accuracy: 0.8511
Epoch 44/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4032 - accuracy: 0.8511
Epoch 45/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4066 - accuracy: 0.8532
Epoch 46/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4025 - accuracy: 0.8532
Epoch 47/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4131 - accuracy: 0.8447
Epoch 48/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4027 - accuracy: 0.8532
Epoch 49/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4078 - accuracy: 0.8511
Epoch 50/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4098 - accuracy: 0.8511
Epoch 51/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4126 - accuracy: 0.8553
Epoch 52/100
47/47 [==============================] - 0s 2ms/step - loss: 0.3969 - accuracy: 0.8553
Epoch 53/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4120 - accuracy: 0.8511
Epoch 54/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4065 - accuracy: 0.8468
Epoch 55/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4105 - accuracy: 0.8532
Epoch 56/100
47/47 [==============================] - 0s 2ms/step - loss: 0.3924 - accuracy: 0.8532
Epoch 57/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4078 - accuracy: 0.8489
Epoch 58/100
47/47 [==============================] - 0s 2ms/step - loss: 0.3995 - accuracy: 0.8574
Epoch 59/100
47/47 [==============================] - 0s 2ms/step - loss: 0.3986 - accuracy: 0.8532
Epoch 60/100
47/47 [==============================] - 0s 2ms/step - loss: 0.3900 - accuracy: 0.8596
Epoch 61/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4048 - accuracy: 0.8553
Epoch 62/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4243 - accuracy: 0.8468
Epoch 63/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4066 - accuracy: 0.8511
Epoch 64/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4320 - accuracy: 0.8532
Epoch 65/100
47/47 [==============================] - 0s 2ms/step - loss: 0.3904 - accuracy: 0.8553
Epoch 66/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4313 - accuracy: 0.8511
Epoch 67/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4164 - accuracy: 0.8489
Epoch 68/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4091 - accuracy: 0.8511
Epoch 69/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4020 - accuracy: 0.8511
Epoch 70/100
47/47 [==============================] - 0s 2ms/step - loss: 0.3999 - accuracy: 0.8574
Epoch 71/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4027 - accuracy: 0.8511
Epoch 72/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4202 - accuracy: 0.8362
Epoch 73/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4013 - accuracy: 0.8532
Epoch 74/100
47/47 [==============================] - 0s 2ms/step - loss: 0.3905 - accuracy: 0.8511
Epoch 75/100
47/47 [==============================] - 0s 2ms/step - loss: 0.3895 - accuracy: 0.8553
Epoch 76/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4111 - accuracy: 0.8553
Epoch 77/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4200 - accuracy: 0.8383
Epoch 78/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4083 - accuracy: 0.8532
Epoch 79/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4149 - accuracy: 0.8426
Epoch 80/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4020 - accuracy: 0.8468
Epoch 81/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4054 - accuracy: 0.8553
Epoch 82/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4185 - accuracy: 0.8489
Epoch 83/100
47/47 [==============================] - 0s 2ms/step - loss: 0.3944 - accuracy: 0.8532
Epoch 84/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4342 - accuracy: 0.8468
Epoch 85/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4052 - accuracy: 0.8489
Epoch 86/100
47/47 [==============================] - 0s 2ms/step - loss: 0.3925 - accuracy: 0.8468
Epoch 87/100
47/47 [==============================] - 0s 2ms/step - loss: 0.3978 - accuracy: 0.8511
Epoch 88/100
47/47 [==============================] - 0s 2ms/step - loss: 0.3968 - accuracy: 0.8511
Epoch 89/100
47/47 [==============================] - 0s 2ms/step - loss: 0.3885 - accuracy: 0.8489
Epoch 90/100
47/47 [==============================] - 0s 2ms/step - loss: 0.3968 - accuracy: 0.8617
Epoch 91/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4218 - accuracy: 0.8511
Epoch 92/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4208 - accuracy: 0.8489
Epoch 93/100
47/47 [==============================] - 0s 2ms/step - loss: 0.3949 - accuracy: 0.8532
Epoch 94/100
47/47 [==============================] - 0s 2ms/step - loss: 0.3878 - accuracy: 0.8489
Epoch 95/100
47/47 [==============================] - 0s 2ms/step - loss: 0.3850 - accuracy: 0.8553
Epoch 96/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4252 - accuracy: 0.8426
Epoch 97/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4158 - accuracy: 0.8426
Epoch 98/100
47/47 [==============================] - 0s 2ms/step - loss: 0.3860 - accuracy: 0.8617
Epoch 99/100
47/47 [==============================] - 0s 2ms/step - loss: 0.4063 - accuracy: 0.8511
Epoch 100/100
47/47 [==============================] - 0s 2ms/step - loss: 0.3829 - accuracy: 0.8468
<keras.callbacks.History at 0x7f69f02adc10>
|