-
Notifications
You must be signed in to change notification settings - Fork 8
/
malwareML.py
47 lines (32 loc) · 1.26 KB
/
malwareML.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import numpy as np
import pandas as pd
from sklearn import tree
from sklearn.ensemble import RandomForestClassifier
from sklearn.neighbors import KNeighborsClassifier
def machineLearnMalware() :
dataSet = pd.read_csv('../CyberMachine/MalwareArtifacts.csv')
fileData = pd.read_csv('../CyberMachine/inputData.csv')
features = dataSet.iloc[:,[0,1,2,3,4,5,6,7]].values
ifMalware = dataSet.iloc[:,8].values
fileFeatures = fileData.iloc[:,[0,1,2,3,4,5,6,7]].values
print("The model is training using a total of 137444 data ...\n")
print("Prediction using Decision Trees ...\n")
dtModel = tree.DecisionTreeClassifier()
dtModel.fit(features, ifMalware)
dtpredict = dtModel.predict(fileFeatures)
print(dtpredict)
print("\n")
print("Prediction using Random Forest ...\n")
rfModel = RandomForestClassifier()
rfModel.fit(features, ifMalware)
rfpredict = rfModel.predict(fileFeatures)
print(rfpredict)
print("\n")
print("Prediction using Kneighbors ...\n")
knnModel = KNeighborsClassifier(n_neighbors=1)
knnModel.fit(features, ifMalware)
knpredict = knnModel.predict(fileFeatures)
print(knpredict)
print("\n")
predict = int(knpredict + dtpredict + rfpredict)
return predict