-
Notifications
You must be signed in to change notification settings - Fork 2
/
PhishingDetection.py
39 lines (31 loc) · 1.07 KB
/
PhishingDetection.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
import numpy as np
import FeatureExtraction
from sklearn.ensemble import RandomForestClassifier as rfc
#from sklearn.svm import SVC
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression as lr
from flask import jsonify
def getResult(url):
#Importing dataset
data = np.loadtxt("dataset.csv", delimiter = ",")
#Seperating features and labels
X = data[: , :-1]
y = data[: , -1]
#Seperating training features, testing features, training labels & testing labels
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2)
clf = rfc()
clf.fit(X_train, y_train)
score = clf.score(X_test, y_test)
print(score*100)
X_new = []
X_input = url
X_new=FeatureExtraction.generate_data_set(X_input)
X_new = np.array(X_new).reshape(1,-1)
try:
prediction = clf.predict(X_new)
if prediction == -1:
return "Phishing URL"
else:
return "Legitimate URL"
except:
return "Phishing URL"