Advertisement
Guest User

Untitled

a guest
Aug 17th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. MOV = movingaverage(TimeSEries,5).tolist()
  2. STD = np.std(MOV)
  3. events= []
  4. ind = []
  5. for ii in range(len(TimeSEries)):
  6. if TimeSEries[ii] > MOV[ii]+STD:
  7. events.append(TimeSEries[ii])
  8.  
  9. import sys
  10. sys.path.insert(1,"../../../")
  11. import h2o
  12.  
  13. def anomaly(ip, port):
  14. h2o.init(ip, port)
  15.  
  16. print "Deep Learning Anomaly Detection MNIST"
  17.  
  18. train = h2o.import_frame(h2o.locate("bigdata/laptop/mnist/train.csv.gz"))
  19. test = h2o.import_frame(h2o.locate("bigdata/laptop/mnist/test.csv.gz"))
  20.  
  21. predictors = range(0,784)
  22. resp = 784
  23.  
  24. # unsupervised -> drop the response column (digit: 0-9)
  25. train = train[predictors]
  26. test = test[predictors]
  27.  
  28. # 1) LEARN WHAT'S NORMAL
  29. # train unsupervised Deep Learning autoencoder model on train_hex
  30. ae_model = h2o.deeplearning(x=train[predictors], training_frame=train, activation="Tanh", autoencoder=True,
  31. hidden=[50], l1=1e-5, ignore_const_cols=False, epochs=1)
  32.  
  33. # 2) DETECT OUTLIERS
  34. # anomaly app computes the per-row reconstruction error for the test data set
  35. # (passing it through the autoencoder model and computing mean square error (MSE) for each row)
  36. test_rec_error = ae_model.anomaly(test)
  37.  
  38. # 3) VISUALIZE OUTLIERS
  39. # Let's look at the test set points with low/median/high reconstruction errors.
  40. # We will now visualize the original test set points and their reconstructions obtained
  41. # by propagating them through the narrow neural net.
  42.  
  43. # Convert the test data into its autoencoded representation (pass through narrow neural net)
  44. test_recon = ae_model.predict(test)
  45.  
  46. # In python, the visualization could be done with tools like numpy/matplotlib or numpy/PIL
  47.  
  48. if __name__ == '__main__':
  49. h2o.run_test(sys.argv, anomaly)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement