129 lines
3.0 KiB
Plaintext
129 lines
3.0 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"id": "epi_kAOf4BKs"
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"import pandas as pd\n",
|
|
"import numpy as np\n",
|
|
"from sklearn import *\n",
|
|
"from sklearn.metrics import accuracy_score"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"id": "CmlwL67D4OFb"
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"malware_dataset = pd.read_csv(\"MalwareArtifacts.csv\", delimiter=',')"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"id": "E9J1BzoQ4dIq"
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"#Extract artifacts samples fileds \"AddressOfEntryPoint\" and \"DLLCharacteristics\"\n",
|
|
"samples = malware_dataset.iloc[:, [0, 4]].values\n",
|
|
"targets = malware_dataset.iloc[:, 8].values"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"id": "gdXEI9GJ5HXD"
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"from sklearn.model_selection import train_test_split\n",
|
|
"training_samples, testing_samples, training_targets, testing_targets = train_test_split(samples, targets, test_size = 0.2, random_state = 0)\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"colab": {
|
|
"base_uri": "https://localhost:8080/"
|
|
},
|
|
"id": "4h33N4dB5bg-",
|
|
"outputId": "0f8f3fe6-20a3-416e-acc9-581c5722b70f"
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"from sklearn import tree\n",
|
|
"tree_classifer = tree.DecisionTreeClassifier()\n",
|
|
"tree_classifer.fit(training_samples, training_targets)\n",
|
|
"predictions = tree_classifer.predict(testing_samples)\n",
|
|
"accuracy = 100* accuracy_score(testing_targets, predictions)\n",
|
|
"print(\"Decision Tree accuracy: \" + str(accuracy))"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"from sklearn.metrics import classification_report , confusion_matrix\n",
|
|
"\n",
|
|
"print(\"Confusion Matrix:\")\n",
|
|
"print(confusion_matrix(testing_targets, predictions))\n",
|
|
"\n",
|
|
"print(\"\\nClassification Report:\")\n",
|
|
"print(classification_report(testing_targets, predictions))"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
}
|
|
],
|
|
"metadata": {
|
|
"colab": {
|
|
"name": "Udemy Malware detection with decision trees.ipynb",
|
|
"provenance": []
|
|
},
|
|
"kernelspec": {
|
|
"display_name": "Python 3",
|
|
"language": "python",
|
|
"name": "python3"
|
|
},
|
|
"language_info": {
|
|
"codemirror_mode": {
|
|
"name": "ipython",
|
|
"version": 3
|
|
},
|
|
"file_extension": ".py",
|
|
"mimetype": "text/x-python",
|
|
"name": "python",
|
|
"nbconvert_exporter": "python",
|
|
"pygments_lexer": "ipython3",
|
|
"version": "3.8.8"
|
|
},
|
|
"widgets": {
|
|
"application/vnd.jupyter.widget-state+json": {
|
|
"state": {},
|
|
"version_major": 2,
|
|
"version_minor": 0
|
|
}
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 4
|
|
}
|