File size: 6,387 Bytes
7b54266
 
 
 
 
 
 
 
 
 
 
4ae907d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
---
license: mit
language: en
tags:
  - cybersecurity
  - malicious-url-detection
  - url-classification
  - machine-learning
  - phishing-detection
pipeline_tag: text-classification
---
# Malicious URL Detection Models

This directory contains trained machine learning models for detecting malicious URLs. The models are trained to classify URLs into four categories:
- **benign**
- **defacement**
- **malware**
- **phishing**

## Model Performance Summary

The following table summarizes the accuracy of each model on the test dataset:

| Model | Accuracy |
|-------|----------|
| **Extra Trees Classifier** | **97%** |
| **Random Forest** | **97%** |
| **Decision Tree** | **96%** |
| **MLP Classifier** | **96%** |
| **XGBoost** | **96%** |
| **Gradient Boosting Classifier** | **94%** |
| **Logistic Regression** | **87%** |
| **SGD Classifier** | **87%** |
| **Adaboost** | **85%** |
| **Gaussian Naive Bayes** | **80%** |

## Detailed Performance Reports

### Adaboost
- **Accuracy:** 0.85
- **Report:**
```
              precision    recall  f1-score   support

      benign       0.90      0.97      0.93     85778
  defacement       0.82      0.76      0.79     19104
     malware       0.55      0.74      0.63      6521
    phishing       0.68      0.42      0.52     18836

    accuracy                           0.85    130239
   macro avg       0.74      0.72      0.72    130239
weighted avg       0.84      0.85      0.84    130239
```

### Decision Tree
- **Accuracy:** 0.96
- **Report:**
```
              precision    recall  f1-score   support

      benign       0.97      0.98      0.98     85778
  defacement       0.98      0.99      0.98     19104
     malware       0.95      0.94      0.95      6521
    phishing       0.87      0.85      0.86     18836

    accuracy                           0.96    130239
   macro avg       0.95      0.94      0.94    130239
weighted avg       0.96      0.96      0.96    130239
```

### Extra Trees Classifier
- **Accuracy:** 0.97
- **Report:**
```
              precision    recall  f1-score   support

      benign       0.97      0.98      0.98     85778
  defacement       0.98      0.99      0.99     19104
     malware       0.98      0.94      0.96      6521
    phishing       0.91      0.86      0.88     18836

    accuracy                           0.97    130239
   macro avg       0.96      0.95      0.95    130239
weighted avg       0.97      0.97      0.97    130239
```

### Gaussian Naive Bayes
- **Accuracy:** 0.80
- **Report:**
```
              precision    recall  f1-score   support

      benign       0.86      0.90      0.88     85778
  defacement       0.67      0.99      0.80     19104
     malware       0.63      0.69      0.66      6521
    phishing       0.68      0.19      0.29     18836

    accuracy                           0.80    130239
   macro avg       0.71      0.69      0.66    130239
weighted avg       0.80      0.80      0.77    130239
```

### Gradient Boosting Classifier
- **Accuracy:** 0.94
- **Report:**
```
              precision    recall  f1-score   support

      benign       0.96      0.99      0.97     85778
  defacement       0.92      0.97      0.94     19104
     malware       0.94      0.80      0.87      6521
    phishing       0.89      0.78      0.83     18836

    accuracy                           0.94    130239
   macro avg       0.93      0.88      0.90    130239
weighted avg       0.94      0.94      0.94    130239
```

### Logistic Regression
- **Accuracy:** 0.87
- **Report:**
```
              precision    recall  f1-score   support

      benign       0.89      0.97      0.93     85778
  defacement       0.85      0.95      0.90     19104
     malware       0.81      0.69      0.74      6521
    phishing       0.77      0.42      0.55     18836

    accuracy                           0.87    130239
   macro avg       0.83      0.76      0.78    130239
weighted avg       0.87      0.87      0.86    130239
```

### MLP Classifier
- **Accuracy:** 0.96
- **Report:**
```
              precision    recall  f1-score   support

      benign       0.97      0.98      0.98     85778
  defacement       0.97      0.97      0.97     19104
     malware       0.95      0.90      0.92      6521
    phishing       0.88      0.83      0.86     18836

    accuracy                           0.96    130239
   macro avg       0.94      0.92      0.93    130239
weighted avg       0.96      0.96      0.96    130239
```

### Random Forest
- **Accuracy:** 0.97
- **Report:**
```
              precision    recall  f1-score   support

      benign       0.98      0.98      0.98     85778
  defacement       0.98      0.99      0.99     19104
     malware       0.98      0.94      0.96      6521
    phishing       0.91      0.87      0.89     18836

    accuracy                           0.97    130239
   macro avg       0.96      0.95      0.95    130239
weighted avg       0.97      0.97      0.97    130239
```

### SGD Classifier
- **Accuracy:** 0.87
- **Report:**
```
              precision    recall  f1-score   support

      benign       0.89      0.96      0.93     85778
  defacement       0.83      0.95      0.89     19104
     malware       0.79      0.71      0.75      6521
    phishing       0.74      0.40      0.52     18836

    accuracy                           0.87    130239
   macro avg       0.81      0.76      0.77    130239
weighted avg       0.86      0.87      0.85    130239
```

### XGBoost
- **Accuracy:** 0.96
- **Report:**
```
              precision    recall  f1-score   support

      benign       0.97      0.99      0.98     85778
  defacement       0.97      0.99      0.98     19104
     malware       0.98      0.92      0.95      6521
    phishing       0.91      0.84      0.88     18836

    accuracy                           0.96    130239
   macro avg       0.96      0.93      0.95    130239
weighted avg       0.96      0.96      0.96    130239
```

## Usage

To load a model in Python, you can use `joblib` or `pickle`.

### Using joblib

```python
import joblib

# Load the model
model = joblib.load('models/random_forest.pkl')

# Make predictions
prediction = model.predict(X_test)
```

### Using pickle

```python
import pickle

# Load the model
with open('models/random_forest.pkl', 'rb') as f:
    model = pickle.load(f)

# Make predictions
prediction = model.predict(X_test)
```