-
Notifications
You must be signed in to change notification settings - Fork 0
/
phishing_detection.py
38 lines (30 loc) · 985 Bytes
/
phishing_detection.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
import numpy as np
import feature_extraction
from sklearn.ensemble import RandomForestClassifier as rfc
from sklearn.model_selection import train_test_split
from flask import jsonify
import joblib
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=feature_extraction.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"