
178
8
章 オートエンコーダハンズオン
# Apply linear activation function to hidden layer
# Generate output layer with 29 nodes
model.add(Dense(units=29, activation='linear'))
# Compile the model
model.compile(optimizer='adam',
loss='mean_squared_error',
metrics=['accuracy'])
# Train the model
num_epochs = 10
batch_size = 32
history = model.fit(x=X_train_AE, y=X_train_AE,
epochs=num_epochs,
batch_size=batch_size,
shuffle=True,
validation_data=(X_train_AE, X_train_AE),
verbose=1)
# Evaluate on test set
predictions = model.predict(X_test, verbose=1)
anomalyScoresAE = anomalyScores(X_test, predictions)
preds, avgPrecision = plotResults(y_test, anomalyScoresAE, True) ...