Tabular Classification
Scikit-learn
Joblib
English
malware-detection
lightgbm
scikit-learn
Eval Results (legacy)
Instructions to use mihai-chindris/malware-detection-lgbm with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Scikit-learn
How to use mihai-chindris/malware-detection-lgbm with Scikit-learn:
from huggingface_hub import hf_hub_download import joblib model = joblib.load( hf_hub_download("mihai-chindris/malware-detection-lgbm", "sklearn_model.joblib") ) # only load pickle files from sources you trust # read more about it here https://skops.readthedocs.io/en/stable/persistence.html - Notebooks
- Google Colab
- Kaggle
Upload folder using huggingface_hub
Browse files- README.md +129 -0
- feature_names.json +24 -0
- preprocessing_pipeline.joblib +3 -0
- production_model.joblib +3 -0
README.md
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
tags:
|
| 4 |
+
- tabular-classification
|
| 5 |
+
- malware-detection
|
| 6 |
+
- lightgbm
|
| 7 |
+
- cybersecurity
|
| 8 |
+
- pe-analysis
|
| 9 |
+
- sklearn
|
| 10 |
+
datasets:
|
| 11 |
+
- custom
|
| 12 |
+
metrics:
|
| 13 |
+
- accuracy
|
| 14 |
+
- roc_auc
|
| 15 |
+
model-index:
|
| 16 |
+
- name: malware-detection-lgbm
|
| 17 |
+
results:
|
| 18 |
+
- task:
|
| 19 |
+
type: tabular-classification
|
| 20 |
+
name: Binary Malware Classification
|
| 21 |
+
metrics:
|
| 22 |
+
- name: AUC
|
| 23 |
+
type: roc_auc
|
| 24 |
+
value: 0.9978
|
| 25 |
+
- name: Accuracy
|
| 26 |
+
type: accuracy
|
| 27 |
+
value: 0.9895
|
| 28 |
+
library_name: sklearn
|
| 29 |
+
pipeline_tag: tabular-classification
|
| 30 |
+
---
|
| 31 |
+
|
| 32 |
+
# Malware Detection — LightGBM (Static PE Features)
|
| 33 |
+
|
| 34 |
+
A LightGBM binary classifier for detecting malware from static Portable Executable (PE) header attributes. Trained on the Brazilian Malware Dataset (~50,000 samples) and optimized with Optuna Bayesian hyperparameter search.
|
| 35 |
+
|
| 36 |
+
## Model Details
|
| 37 |
+
|
| 38 |
+
| Property | Value |
|
| 39 |
+
|----------|-------|
|
| 40 |
+
| **Algorithm** | LightGBM (Gradient Boosted Decision Trees) |
|
| 41 |
+
| **Estimators** | 200 trees |
|
| 42 |
+
| **Hyperparameter Tuning** | Optuna (Bayesian Optimization) |
|
| 43 |
+
| **Input Features** | 22 numeric PE header attributes |
|
| 44 |
+
| **Output** | Binary probability — `0` = goodware, `1` = malware |
|
| 45 |
+
| **Serialization** | joblib (scikit-learn compatible) |
|
| 46 |
+
| **Training Framework** | LightGBM 4.6.0, scikit-learn 1.6.1 |
|
| 47 |
+
| **Python Version** | 3.12 |
|
| 48 |
+
|
| 49 |
+
## Performance
|
| 50 |
+
|
| 51 |
+
### 10-Fold Stratified Cross-Validation (Training Set)
|
| 52 |
+
|
| 53 |
+
| Model | AUC (mean ± std) | Accuracy (mean ± std) |
|
| 54 |
+
|-------|------------------|-----------------------|
|
| 55 |
+
| **LightGBM** | **0.9982 ± 0.0004** | **0.9869 ± 0.0015** |
|
| 56 |
+
| XGBoost | 0.9979 ± 0.0005 | 0.9856 ± 0.0021 |
|
| 57 |
+
| Random Forest | 0.9979 ± 0.0008 | 0.9882 ± 0.0017 |
|
| 58 |
+
| CatBoost | 0.9965 ± 0.0006 | 0.9809 ± 0.0023 |
|
| 59 |
+
| PyTorch MLP | 0.9872 ± 0.0018 | 0.9503 ± 0.0062 |
|
| 60 |
+
| Decision Tree | 0.9800 ± 0.0019 | 0.9807 ± 0.0017 |
|
| 61 |
+
| SVM (RBF) | 0.9685 ± 0.0027 | 0.9282 ± 0.0054 |
|
| 62 |
+
| Logistic Regression | 0.8772 ± 0.0056 | 0.8136 ± 0.0052 |
|
| 63 |
+
|
| 64 |
+
### Hold-Out Test Set (20%)
|
| 65 |
+
|
| 66 |
+
| Metric | Value |
|
| 67 |
+
|--------|-------|
|
| 68 |
+
| AUC | 0.9978 |
|
| 69 |
+
| Accuracy | 0.9895 |
|
| 70 |
+
|
| 71 |
+
**Confusion Matrix:** `[[4146, 78], [45, 5768]]`
|
| 72 |
+
|
| 73 |
+
- False Positives: 78 (goodware flagged as malware)
|
| 74 |
+
- False Negatives: 45 (malware missed)
|
| 75 |
+
|
| 76 |
+
## Input Features (22)
|
| 77 |
+
|
| 78 |
+
`BaseOfCode`, `BaseOfData`, `Characteristics`, `DllCharacteristics`, `Entropy`, `FileAlignment`, `ImageBase`, `Machine`, `Magic`, `NumberOfRvaAndSizes`, `NumberOfSections`, `NumberOfSymbols`, `PE_TYPE`, `PointerToSymbolTable`, `Size`, `SizeOfCode`, `SizeOfHeaders`, `SizeOfImage`, `SizeOfInitializedData`, `SizeOfOptionalHeader`, `SizeOfUninitializedData`, `TimeDateStamp`
|
| 79 |
+
|
| 80 |
+
## Files
|
| 81 |
+
|
| 82 |
+
| File | Description |
|
| 83 |
+
|------|-------------|
|
| 84 |
+
| `production_model.joblib` | Trained LightGBM model (Optuna-optimized) |
|
| 85 |
+
| `preprocessing_pipeline.joblib` | scikit-learn Pipeline: median imputation + standard scaling |
|
| 86 |
+
| `feature_names.json` | Ordered list of 22 input feature names |
|
| 87 |
+
|
| 88 |
+
## Usage
|
| 89 |
+
|
| 90 |
+
```python
|
| 91 |
+
import joblib
|
| 92 |
+
import json
|
| 93 |
+
import numpy as np
|
| 94 |
+
|
| 95 |
+
# Load artifacts
|
| 96 |
+
model = joblib.load("production_model.joblib")
|
| 97 |
+
pipeline = joblib.load("preprocessing_pipeline.joblib")
|
| 98 |
+
with open("feature_names.json") as f:
|
| 99 |
+
feature_names = json.load(f)
|
| 100 |
+
|
| 101 |
+
# Prepare input (22 features in the correct order)
|
| 102 |
+
sample = np.array([[...]]) # shape: (1, 22)
|
| 103 |
+
transformed = pipeline.transform(sample)
|
| 104 |
+
probability = model.predict_proba(transformed)[0][1]
|
| 105 |
+
label = "MALWARE" if probability >= 0.5 else "GOODWARE"
|
| 106 |
+
print(f"{label} (confidence: {probability:.4f})")
|
| 107 |
+
```
|
| 108 |
+
|
| 109 |
+
## Preprocessing Pipeline
|
| 110 |
+
|
| 111 |
+
1. **Median imputation** — fitted on training data only (leakage-safe)
|
| 112 |
+
2. **Standard scaling** — fitted on training data only
|
| 113 |
+
3. Non-numeric columns dropped
|
| 114 |
+
|
| 115 |
+
The pipeline is exported as a single `preprocessing_pipeline.joblib` and must be applied before inference.
|
| 116 |
+
|
| 117 |
+
## Dataset
|
| 118 |
+
|
| 119 |
+
**Brazilian Malware Dataset** (~50,000 PE samples, 27 raw features, binary target)
|
| 120 |
+
|
| 121 |
+
> Ceschin, F., Pinage, F., Castilho, M., Menotti, D., Oliveira, L.S., and Gregio, A. "The Need for Speed: An Analysis of Brazilian Malware Classifiers." *IEEE Security & Privacy*, 16(6), 31–41, 2018. doi: [10.1109/MSEC.2018.2875369](https://doi.org/10.1109/MSEC.2018.2875369)
|
| 122 |
+
|
| 123 |
+
## Source Code
|
| 124 |
+
|
| 125 |
+
Full training pipeline, Flask web app, and CI/CD: [github.com/chindris-mihai-alexandru/malware-detection-ml](https://github.com/chindris-mihai-alexandru/malware-detection-ml)
|
| 126 |
+
|
| 127 |
+
## License
|
| 128 |
+
|
| 129 |
+
MIT
|
feature_names.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[
|
| 2 |
+
"BaseOfCode",
|
| 3 |
+
"BaseOfData",
|
| 4 |
+
"Characteristics",
|
| 5 |
+
"DllCharacteristics",
|
| 6 |
+
"Entropy",
|
| 7 |
+
"FileAlignment",
|
| 8 |
+
"ImageBase",
|
| 9 |
+
"Machine",
|
| 10 |
+
"Magic",
|
| 11 |
+
"NumberOfRvaAndSizes",
|
| 12 |
+
"NumberOfSections",
|
| 13 |
+
"NumberOfSymbols",
|
| 14 |
+
"PE_TYPE",
|
| 15 |
+
"PointerToSymbolTable",
|
| 16 |
+
"Size",
|
| 17 |
+
"SizeOfCode",
|
| 18 |
+
"SizeOfHeaders",
|
| 19 |
+
"SizeOfImage",
|
| 20 |
+
"SizeOfInitializedData",
|
| 21 |
+
"SizeOfOptionalHeader",
|
| 22 |
+
"SizeOfUninitializedData",
|
| 23 |
+
"TimeDateStamp"
|
| 24 |
+
]
|
preprocessing_pipeline.joblib
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f4c7eac20f462d59d516083a1063fcf8eb77f33c8a085ef7c57230fdb6989604
|
| 3 |
+
size 2417
|
production_model.joblib
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:99d7c6b8961a86a3537abe9f29b405ecb4b45e67a87afb9cef0d98ecde4bbaa0
|
| 3 |
+
size 2284004
|