【发布时间】:2019-01-03 07:19:59
【问题描述】:
我只想将 y_pred 输出设为 +1 或 -1。它不应该有中间实数值,甚至不应该是零。
classifier = Sequential()
#adding layers
# Adding the input layer and the first hidden l`enter code here`ayer
classifier.add(Dense(output_dim = 6, init = 'uniform', activation ='relu', input_shape = (22,)))
# Adding the second hidden layer classifier.add(Dense(output_dim = 6, init = 'uniform', activation = 'relu'))
# Adding the output layer
classifier.add(Dense(output_dim = 1, init = 'uniform', activation = 'tanh'))
# Compiling Neural Network
classifier.compile(optimizer = 'adam', loss = 'binary_crossentropy', metrics = ['accuracy'])
# Fitting our model
classifier.fit(x_train, y_train, batch_size = 10, epochs = 100)
# Predicting the Test set results
y_pred = classifier.predict(x_test)
y_pred 的输出值在 [-1,1] 范围内,但我希望值只能是 1 或 -1。
【问题讨论】:
-
设置一个阈值,比如 0,高于 0 为 1,低于 0 为 -1
-
@Oswald 在修改中我可以在损失或激活参数中进行,而不是将 y_pred 修改为 y_pred[y_pred > 0] = 1 y_pred[y_pred
标签: python-3.x machine-learning keras deep-learning anaconda