actiavation function → 출력을 지정하는 함수
ex) softmax, sigmoid, linear...
Dense(8, input_dim = 4, init = 'uniform', activation = 'relu') → 32개의 가중치를 학습해야함(input*output)
metrics를 지정해주면 학습과정을 볼 수 있다.
mae → mean absolute error 평균 절대 오차
epochs → 반복 횟수
batchsize → 몇 개를 잘라서 학습 할 지
get_weight
weight, bias를 출력해준다.
x = df[['걸음 수', '이동 거리', '정적인 시간(분)', '약간 활동적인 시간(분)', '상당히 활동적인 시간(분)', '매우 활동적인 시간(분)']]
y = df['칼로리 소모량']
x_train = x[:100]
y_train = y[:100]
x_test = x[100:]
y_test = y[100:]
속성별로 다른 스케일을 가진 데이터를 입력하면 스케일이 큰 속성에 영향을 많이 미치는 경우가 발생하기 때문에, 정규화 과정을 해주게 된다. 속성별로 평균을 구하고 각 인스턴스에 평균을 빼고 표준 편차로 나누어주었다.
-> 시험셋을 입력할때도 필요하는 값을 저장해둠
mean = x_train.mean(axis=0)
x_train -= mean
std = x_train.std(axis=0)
x_train /= std
model = Sequential([
Dense(16, input_dim=6, activation='relu'),
Dense(16, activation='relu'),
Dense(1)
])
model.compile(loss='mse', optimizer='rmsprop', metrics=['mae']) # 수치예측은 보통 mse다.
model.fit(x_train, y_train, epochs=5000, batch_size=32)
x_test -= mean
x_test /= std
y_pred = model.predict(x_test)
print(y_pred)
loss, mae = model.evaluate(x_test, y_test)
print(mae)