predict 는 probability를 predict_class 는 label 을 제공한다.
다음 코드를 보자
import numpy as np
from keras.models import Sequential
from keras.layers.core import Dense
np.random.seed(5)
# 1. 데이터 로드
dataset = np.loadtxt('../data/xor.csv', delimiter=',')
#dataset.shape[0] = 4
#dataset.shape[1] = 3
# 2. 데이터셋 생성
x_train = dataset[:dataset.shape[0], 0:dataset.shape[1]-1]
y_train = dataset[:dataset.shape[0], dataset.shape[1]-1]
# 3. 모델 구성
model = Sequential()
model.add(Dense(64, input_dim=dataset.shape[1]-1, activation='relu'))
model.add(Dense(1, activation='sigmoid'))
# 4. 학습과정 설정
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
# 5. 모델 학습
model.fit(x_train, y_train, epochs=500, batch_size=1)
# 6. 예측
y = model.predict(x_train)
print(y)
y = model.predict_classes(x_train)
print(y)
-------------------------------------------------------
predict 의 경우
[[0.22520512]
[0.9520419 ]
[0.9672848 ]
[0.02690617]]
predict_classes 의 경우
[[0]
[1]
[1]
[0]]
'machine learning' 카테고리의 다른 글
인공지능 음악 선생님 뮤아이 muai (0) | 2018.10.29 |
---|