Selaa lähdekoodia

Merge branch 'master' of git.tflucke.name:tflucke/SSH-Master-Thesis

Thomas Flucke 6 vuotta sitten
vanhempi
commit
eff037d4f0

+ 9 - 0
ethan_data_processing_scripts/README.md

@@ -0,0 +1,9 @@
+### Using classifier.py
+
+The train(classifications: int, data: list, results: list, testdata: list, testresults: list) function should be used.
+
+Data and Testdata should be arrays of arrays of features, ex:
+
+Suppose there are 3 features, each a float from 0 to 1. Data could be: [[.3, .2, .3], [.3, .3, .3], [.3, .4, .5]...]
+
+Results should be ints in an array, each result accoring to the list of features it should represent the classification of.

+ 50 - 0
ethan_data_processing_scripts/classifier.py

@@ -0,0 +1,50 @@
+import tensorflow as tf
+
+
+def main():
+    # train(4, [[.1, .2, .3], [.3, .2, .3], [.3, .3, .3], [.3, .4, .5]], [1,2,3,0], [[.1, .2, .3], [.3, .2, .3], [.3, .3, .3], [.3, .4, .5]], [1,2,3,0])
+    pass
+    '''
+    mnist = tf.keras.datasets.mnist
+
+    (x_train, y_train), (x_test, y_test) = mnist.load_data()
+
+    x_train = tf.keras.utils.normalize(x_train, axis=1)
+    x_test = tf.keras.utils.normalize(x_test, axis=1)
+
+    print(x_train[0])
+
+    model = tf.keras.models.Sequential()
+    model.add(tf.keras.layers.Flatten())
+    model.add(tf.keras.layers.Dense(128, activation=tf.nn.relu))
+    model.add(tf.keras.layers.Dense(128, activation=tf.nn.relu))
+    model.add(tf.keras.layers.Dense(10, activation=tf.nn.softmax))
+
+    model.compile(optimizer='SGD',
+                  loss='sparse_categorical_crossentropy',
+                  metrics=['accuracy'])
+    model.fit(x_train, y_train, epochs=3)
+    '''
+
+
+# data and results arrays (training and testing) should be paired. Classifications is number of ways to classify data.
+def train(classifications: int, data: list, results: list, testdata: list, testresults: list):
+    numberOfNeurons = (len(data[0]) + classifications)/2
+    model = tf.keras.models.Sequential()
+    model.add(tf.keras.layers.Flatten())
+    model.add(tf.keras.layers.Dense(numberOfNeurons, activation=tf.nn.relu))
+    model.add(tf.keras.layers.Dense(numberOfNeurons, activation=tf.nn.relu))
+    model.add(tf.keras.layers.Dense(classifications, tf.nn.softmax))
+
+    model.compile(optimizer='SGD',
+                  loss='sparse_categorical_crossentropy',
+                  metrics=['accuracy'])
+    model.fit(data, results, epochs=5)
+
+    loss, accuracy = model.evaluate(testdata, testresults)
+    print(loss)
+    print(accuracy)
+
+
+if __name__ == '__main__':
+    main()

+ 17 - 0
ethan_data_processing_scripts/logs.py

@@ -0,0 +1,17 @@
+import sys
+
+
+def main():
+    file = open(sys.argv[1], "r")
+    line = file.readline()
+    x = ""
+    while line:
+        x += line[27:28]
+        line = file.readline()
+
+    print(x)
+    file.close()
+
+
+if __name__ == '__main__':
+    main()

+ 5 - 0
ethan_data_processing_scripts/pcap.py

@@ -0,0 +1,5 @@
+import pyshark
+
+shark_cap = pyshark.FileCapture('/Users/ethangoldfarb/Desktop/tomthesis/SSH-Master-Thesis/data/packets/thesis-capture-2019-05-03.0.pcap')
+for packet in shark_cap:
+    print("%s" % packet)