Reputation: 2470
I am working on a project that predicts drug synergy values based on various input features related to them. The synergy values are floating point numbers and so I would like to set an accuracy range for my neural network. eg - Say the actual value is 1.342423 and my model predicts 1.30123 then the output this should be treated as correct ouput. In other words I would like to limit the amount of decimal places that are checked to compare the actual answer and the predicted answer. Neural Net :
model = Sequential()
act = 'relu'
model.add(Dense(430, input_shape=(3,)))
model.add(Activation(act))
model.add(Dense(256))
model.add(Activation(act))
model.add(Dropout(0.42))
model.add(Dense(148))
model.add(Activation(act))
model.add(Dropout(0.3))
model.add(Dense(1))
model.compile(loss='mean_squared_error', optimizer='adam', metrics=['accuracy'])
Complete source code for learning and train/test data : https://github.com/tanmay-edgelord/Drug-Synergy-Models/blob/master Please ask for any additional details that are required (Using Keras with TensorFlow backend)
Upvotes: 1
Views: 3338
Reputation: 86610
Create a custom metric:
import keras.backend as K
def myAccuracy(y_true, y_pred):
diff = K.abs(y_true-y_pred) #absolute difference between correct and predicted values
correct = K.less(diff,0.05) #tensor with 0 for false values and 1 for true values
return K.mean(correct) #sum all 1's and divide by the total.
Then use it in the model compilation:
model.compile(metrics=[myAccuracy],....)
Upvotes: 4