5
5
6
6
# UCI의 와인 데이터 세트를 사용.
7
7
# 외부에서 데이터를 불러오고 정제하는 과정.
8
- red = pd .read_csv ('http://archive.ics.uci.edu/ml/machine-learning-databases/wine-quality/winequality-red.csv' , sep = ';' )
9
- white = pd .read_csv ('http://archive.ics.uci.edu/ml/machine-learning-databases/wine-quality/winequality-white.csv' , sep = ';' )
10
- #print(red.head())
11
- #print(white.head())
8
+ red = pd .read_csv ('http://archive.ics.uci.edu/ml/machine-learning-databases/wine-quality/winequality-red.csv' ,
9
+ sep = ';' )
10
+ white = pd .read_csv ('http://archive.ics.uci.edu/ml/machine-learning-databases/wine-quality/winequality-white.csv' ,
11
+ sep = ';' )
12
+ # print(red.head())
13
+ # print(white.head())
12
14
13
15
# 와인이 레드(0)와인인지 화이트(1)와인인지 표시하는 속성('type')을 추가한다.
14
16
red ['type' ] = 0
23
25
# 데이터프레임 wine의 type 속성만 히스토그램으로 출력한다.
24
26
# 현재 데이터셋에서는 레드보다 화이트와인이 약 3배 많은 상황.
25
27
plt .hist (wine ['type' ])
26
- plt .xticks ([0 ,1 ])
28
+ plt .xticks ([0 , 1 ])
27
29
plt .show ()
28
30
# print(wine['type'].value_counts())
29
31
32
34
# 현재 모두 non-null이고, float64거나 int64이므로 정규화 진행 가능하다.
33
35
# print(wine.info())
34
36
35
- wine_norm = ( wine - wine .min () ) / ( wine .max () - wine .min () )
37
+ wine_norm = (wine - wine .min ()) / (wine .max () - wine .min ())
36
38
# print(wine_norm.head())
37
39
# print(wine_norm.describe()) # 속성들의 min값이 0, max값이 1이므로 정규화가 잘 진행되었다.
38
40
47
49
# print(wine_np[:5])
48
50
49
51
# 데이터 셋의 80%를 학습 데이터로, 20%를 테스트 데이터로 분할하는 과정.
50
- train_idx = int (len (wine_np )* 0.8 ) # 데이터셋을 나눌 구분점이 되는 인덱스. 데이터셋의 80% 지점.
52
+ train_idx = int (len (wine_np )* 0.8 ) # 데이터셋을 나눌 구분점이 되는 인덱스. 데이터셋의 80% 지점.
51
53
train_X , train_Y = wine_np [:train_idx , :- 1 ], wine_np [:train_idx , - 1 ]
52
54
# 구분점까지의 모든 IV들 (마지막 한칸을 제외한 전부)은 X에, 구분점까지의 모든 DV들 (마지막 한 칸)은 Y에 저장.
53
55
test_X , test_Y = wine_np [train_idx :, :- 1 ], wine_np [train_idx :, - 1 ]
100
102
101
103
history = model .fit (train_X , train_Y , epochs = 25 , batch_size = 32 , validation_split = 0.25 )
102
104
103
- plt .figure (figsize = (12 ,4 ))
104
- plt .subplot (1 ,2 , 1 )
105
+ plt .figure (figsize = (12 , 4 ))
106
+ plt .subplot (1 , 2 , 1 )
105
107
plt .plot (history .history ['loss' ], 'b-' , label = 'loss' )
106
108
plt .plot (history .history ['val_loss' ], 'r--' , label = 'val_loss' )
107
109
plt .xlabel ('Epoch' )
108
110
plt .legend ()
109
111
110
- plt .subplot (1 ,2 , 2 )
112
+ plt .subplot (1 , 2 , 2 )
111
113
plt .plot (history .history ['accuracy' ], 'g--' , label = 'accuracy' )
112
114
plt .plot (history .history ['val_accuracy' ], 'k--' , label = 'val_accuracy' )
113
115
plt .xlabel ('Epoch' )
114
116
plt .legend ()
115
117
116
- plt .show ()
118
+ plt .show ()
0 commit comments