EMClustering.java 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package classifier;
  2. import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Packet;
  3. import weka.clusterers.EM;
  4. import weka.core.Instance;
  5. import weka.core.Instances;
  6. /**
  7. * Expectation Maximization Clustering Approach
  8. * @author Andreas T. Meyer-Berg
  9. */
  10. public class EMClustering extends BasicPacketClassifier {
  11. /**
  12. * EM cluster which is used
  13. */
  14. private EM clusterer;
  15. /**
  16. * Initialize the clusterer
  17. */
  18. public EMClustering() {
  19. clusterer = new EM();
  20. }
  21. @Override
  22. public void trainModel(Instances instances) {
  23. try {
  24. clusterer.buildClusterer(instances);
  25. } catch (Exception e) {
  26. // TODO Auto-generated catch block
  27. e.printStackTrace();
  28. }
  29. }
  30. @Override
  31. public void classifyInstance(Instance instance, Packet origin) {
  32. try {
  33. clusterer.clusterInstance(instance);
  34. } catch (Exception e) {
  35. System.out.println("EM: Anomaly Detected on Packet: "+origin.getTextualRepresentation());
  36. }
  37. }
  38. @Override
  39. public long getClassificationStart() {
  40. return 3600000;
  41. }
  42. }