Rename notebooks: data_exploration, model_training
Browse files
notebooks/{part1_data_exploration.ipynb β data_exploration.ipynb}
RENAMED
|
@@ -5,7 +5,7 @@
|
|
| 5 |
"id": "16aa53aa",
|
| 6 |
"metadata": {},
|
| 7 |
"source": [
|
| 8 |
-
"#
|
| 9 |
"\n",
|
| 10 |
"**Dataset:** Windows PE files, malware from MalwareBazaar and benign software from Scoop and winget, split by time (train β€ 2024, validation 2025, test 2026).\n",
|
| 11 |
"\n",
|
|
@@ -695,7 +695,7 @@
|
|
| 695 |
"id": "2576af6a",
|
| 696 |
"metadata": {},
|
| 697 |
"source": [
|
| 698 |
-
"41% of the files are larger than 1 MB. A model that reads only the first 1 MB, as my first version did, would never see the end of four files in ten. This is why the final model
|
| 699 |
"\n",
|
| 700 |
"Two other things stand out. Malware from 2025β2026 is about twice as large as malware from the training years (median 1.3β1.6 MB against 0.7 MB), so the data changes over time. And very large files (8β16 MB) are more often benign, which could be a shortcut; section 6.2 checks that file size alone does not predict the label."
|
| 701 |
]
|
|
@@ -1192,7 +1192,7 @@
|
|
| 1192 |
"name": "stdout",
|
| 1193 |
"output_type": "stream",
|
| 1194 |
"text": [
|
| 1195 |
-
"loss weight for the malware class
|
| 1196 |
]
|
| 1197 |
}
|
| 1198 |
],
|
|
@@ -1201,7 +1201,7 @@
|
|
| 1201 |
"bal[\"malware share\"] = (bal.malware / bal.sum(axis=1)).map(\"{:.1%}\".format)\n",
|
| 1202 |
"display(bal)\n",
|
| 1203 |
"n_neg, n_pos = (df[df.split == \"train\"].label == 0).sum(), (df[df.split == \"train\"].label == 1).sum()\n",
|
| 1204 |
-
"print(f\"loss weight for the malware class
|
| 1205 |
]
|
| 1206 |
},
|
| 1207 |
{
|
|
@@ -1211,7 +1211,7 @@
|
|
| 1211 |
"source": [
|
| 1212 |
"The training set is 61% malware, the validation set 48% and the test set 33%. The imbalance is mild, but it differs between splits because each split is simply everything collected for those years.\n",
|
| 1213 |
"\n",
|
| 1214 |
-
"
|
| 1215 |
]
|
| 1216 |
},
|
| 1217 |
{
|
|
@@ -1221,7 +1221,7 @@
|
|
| 1221 |
"source": [
|
| 1222 |
"## 5. Train / validation / test split\n",
|
| 1223 |
"The split is by **time**, not random: train = files first seen up to 2024, validation = 2025, test = 2026.\n",
|
| 1224 |
-
"
|
| 1225 |
]
|
| 1226 |
},
|
| 1227 |
{
|
|
@@ -1421,7 +1421,7 @@
|
|
| 1421 |
"id": "31cab477",
|
| 1422 |
"metadata": {},
|
| 1423 |
"source": [
|
| 1424 |
-
"
|
| 1425 |
"\n",
|
| 1426 |
"No file can be in two splits: each hash appears once in the manifest and has one date, and the check above confirms zero overlap. The time split also makes the test set genuinely hard: 1,003 of its 2,129 malware files are from a family that is new or unnamed, and 2,066 of its 4,281 benign files are from apps never seen in training. A fixed random seed (1337) is used wherever sampling was needed (the family cap and the library sampling), so the dataset is reproducible."
|
| 1427 |
]
|
|
@@ -1469,7 +1469,7 @@
|
|
| 1469 |
"id": "1241344b",
|
| 1470 |
"metadata": {},
|
| 1471 |
"source": [
|
| 1472 |
-
"### 6.1 Is the data learnable? (reference point for
|
| 1473 |
]
|
| 1474 |
},
|
| 1475 |
{
|
|
@@ -1545,7 +1545,7 @@
|
|
| 1545 |
"id": "bd98eea5",
|
| 1546 |
"metadata": {},
|
| 1547 |
"source": [
|
| 1548 |
-
"The data is learnable: a simple model on byte counts reaches an AUC of 0.98 on 2025 files and catches 80% of malware while flagging 1% of benign files. One year later, on 2026 files, the same model catches only 43%. These are the numbers the deep model
|
| 1549 |
]
|
| 1550 |
},
|
| 1551 |
{
|
|
@@ -2194,7 +2194,7 @@
|
|
| 2194 |
"| Split by time, not at random | a random split doubles the apparent detection rate (6.4) |\n",
|
| 2195 |
"| Collect about 60,000 training files | the learning curve is still rising (6.5) |\n",
|
| 2196 |
"\n",
|
| 2197 |
-
"**Reference for
|
| 2198 |
"\n",
|
| 2199 |
"**Main limitations.** The source of a file determines its label, benign software comes only from two package catalogues, and many test files are newer versions of things seen in training.\n",
|
| 2200 |
"\n",
|
|
|
|
| 5 |
"id": "16aa53aa",
|
| 6 |
"metadata": {},
|
| 7 |
"source": [
|
| 8 |
+
"# Data exploration and dataset creation\n",
|
| 9 |
"\n",
|
| 10 |
"**Dataset:** Windows PE files, malware from MalwareBazaar and benign software from Scoop and winget, split by time (train β€ 2024, validation 2025, test 2026).\n",
|
| 11 |
"\n",
|
|
|
|
| 695 |
"id": "2576af6a",
|
| 696 |
"metadata": {},
|
| 697 |
"source": [
|
| 698 |
+
"41% of the files are larger than 1 MB. A model that reads only the first 1 MB, as my first version did, would never see the end of four files in ten. This is why the final model reads the whole file, up to a 16 MB limit that applies to both classes.\n",
|
| 699 |
"\n",
|
| 700 |
"Two other things stand out. Malware from 2025β2026 is about twice as large as malware from the training years (median 1.3β1.6 MB against 0.7 MB), so the data changes over time. And very large files (8β16 MB) are more often benign, which could be a shortcut; section 6.2 checks that file size alone does not predict the label."
|
| 701 |
]
|
|
|
|
| 1192 |
"name": "stdout",
|
| 1193 |
"output_type": "stream",
|
| 1194 |
"text": [
|
| 1195 |
+
"loss weight for the malware class when training the model (benign / malware in train): 0.650\n"
|
| 1196 |
]
|
| 1197 |
}
|
| 1198 |
],
|
|
|
|
| 1201 |
"bal[\"malware share\"] = (bal.malware / bal.sum(axis=1)).map(\"{:.1%}\".format)\n",
|
| 1202 |
"display(bal)\n",
|
| 1203 |
"n_neg, n_pos = (df[df.split == \"train\"].label == 0).sum(), (df[df.split == \"train\"].label == 1).sum()\n",
|
| 1204 |
+
"print(f\"loss weight for the malware class when training the model (benign / malware in train): {n_neg / n_pos:.3f}\")"
|
| 1205 |
]
|
| 1206 |
},
|
| 1207 |
{
|
|
|
|
| 1211 |
"source": [
|
| 1212 |
"The training set is 61% malware, the validation set 48% and the test set 33%. The imbalance is mild, but it differs between splits because each split is simply everything collected for those years.\n",
|
| 1213 |
"\n",
|
| 1214 |
+
"When training the model I handle it in two ways. The loss gives malware examples a weight of 0.65, so both classes count equally during training. And I report measures that do not depend on the class mix: AUC, balanced accuracy, and the detection rate at a fixed false-positive rate."
|
| 1215 |
]
|
| 1216 |
},
|
| 1217 |
{
|
|
|
|
| 1221 |
"source": [
|
| 1222 |
"## 5. Train / validation / test split\n",
|
| 1223 |
"The split is by **time**, not random: train = files first seen up to 2024, validation = 2025, test = 2026.\n",
|
| 1224 |
+
"A stratified random split is the more common choice; section 6.4 measures what difference that makes."
|
| 1225 |
]
|
| 1226 |
},
|
| 1227 |
{
|
|
|
|
| 1421 |
"id": "31cab477",
|
| 1422 |
"metadata": {},
|
| 1423 |
"source": [
|
| 1424 |
+
"A stratified random split is the usual choice. I split by time instead, because an antivirus is trained on yesterday's files and used on tomorrow's. The cost is that the class mix is not identical across splits (section 4), which is why I avoid plain accuracy.\n",
|
| 1425 |
"\n",
|
| 1426 |
"No file can be in two splits: each hash appears once in the manifest and has one date, and the check above confirms zero overlap. The time split also makes the test set genuinely hard: 1,003 of its 2,129 malware files are from a family that is new or unnamed, and 2,066 of its 4,281 benign files are from apps never seen in training. A fixed random seed (1337) is used wherever sampling was needed (the family cap and the library sampling), so the dataset is reproducible."
|
| 1427 |
]
|
|
|
|
| 1469 |
"id": "1241344b",
|
| 1470 |
"metadata": {},
|
| 1471 |
"source": [
|
| 1472 |
+
"### 6.1 Is the data learnable? (reference point for the deep model)"
|
| 1473 |
]
|
| 1474 |
},
|
| 1475 |
{
|
|
|
|
| 1545 |
"id": "bd98eea5",
|
| 1546 |
"metadata": {},
|
| 1547 |
"source": [
|
| 1548 |
+
"The data is learnable: a simple model on byte counts reaches an AUC of 0.98 on 2025 files and catches 80% of malware while flagging 1% of benign files. One year later, on 2026 files, the same model catches only 43%. These are the numbers the deep model has to beat, and the gap between the two years is the main difficulty of this dataset."
|
| 1549 |
]
|
| 1550 |
},
|
| 1551 |
{
|
|
|
|
| 2194 |
"| Split by time, not at random | a random split doubles the apparent detection rate (6.4) |\n",
|
| 2195 |
"| Collect about 60,000 training files | the learning curve is still rising (6.5) |\n",
|
| 2196 |
"\n",
|
| 2197 |
+
"**Reference for the deep model.** The simple baseline scores an AUC of 0.980 on validation and 0.923 on test, with 80.0% and 43.3% of malware detected at 1% false positives.\n",
|
| 2198 |
"\n",
|
| 2199 |
"**Main limitations.** The source of a file determines its label, benign software comes only from two package catalogues, and many test files are newer versions of things seen in training.\n",
|
| 2200 |
"\n",
|
notebooks/{part2_model.ipynb β model_training.ipynb}
RENAMED
|
The diff for this file is too large to render.
See raw diff
|
|
|