-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathtest.py
executable file
·45 lines (31 loc) · 1.46 KB
/
test.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
# Purpose - Receive the call for testing a page from the Chrome extension and return the result (SAFE/PHISHING)
# for display. This file calls all the different components of the project (The ML model, features_extraction) and
# consolidates the result.
import joblib
import features_extraction
import sys
import numpy as np
from features_extraction import LOCALHOST_PATH, DIRECTORY_NAME
def get_prediction_from_url(test_url):
features_test = features_extraction.main(test_url)
# Due to updates to scikit-learn, we now need a 2D array as a parameter to the predict function.
features_test = np.array(features_test).reshape((1, -1))
clf = joblib.load(LOCALHOST_PATH + DIRECTORY_NAME + '/classifier/random_forest.pkl')
pred = clf.predict(features_test)
return int(pred[0])
def main():
url = sys.argv[1]
prediction = get_prediction_from_url(url)
# Print the probability of prediction (if needed)
# prob = clf.predict_proba(features_test)
# print 'Features=', features_test, 'The predicted probability is - ', prob, 'The predicted label is - ', pred
# print "The probability of this site being a phishing website is ", features_test[0]*100, "%"
if prediction == 1:
# print "The website is safe to browse"
print("SAFE")
elif prediction == -1:
# print "The website has phishing features. DO NOT VISIT!"
print("PHISHING")
# print 'Error -', features_test
if __name__ == "__main__":
main()