Learning Efficient Anomaly Detectors from $K$-NN Graphs