Created
June 27, 2020 04:04
-
-
Save srinathperera/eb9c14dd3c0a343e902e8d0a516c0c0e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def adjust_predictions4nighbourhood(y_test, predict_test): | |
slack = 5 | |
y_test = y_test.values | |
length = len(y_test) | |
adjusted_forecasts = np.copy(predict_test) | |
for i in range(length): | |
if y_test[i] == predict_test[i]: | |
adjusted_forecasts[i] = predict_test[i] | |
elif predict_test[i] == 1: #FP | |
if np.sum(y_test[i-slack:i+slack]) > 0: | |
#print(y_test[i - slack:i + slack], "=", np.sum(y_test[i - slack:i + slack])) | |
adjusted_forecasts[i] = 0 #there is anomaly within 20 in actual, so 1 OK | |
elif predict_test[i] == 0: # FN | |
if np.sum(predict_test[i-slack:i+slack]) > 0: | |
#print(predict_test[i - slack:i + slack], "=", np.sum(predict_test[i - slack:i + slack])) | |
adjusted_forecasts[i] = 1 #there is anomaly within 20 in predicted, so OK | |
return adjusted_forecasts |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment