117 lines
2.6 KiB
Plaintext
117 lines
2.6 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"id": "BUTFBYKgAsSV"
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"import pandas as pd\n",
|
|
"import numpy as np\n",
|
|
"import matplotlib.pyplot as plt\n",
|
|
"\n",
|
|
"from sklearn.cluster import KMeans\n",
|
|
"from sklearn.metrics import silhouette_score\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"id": "ykmjXu5-A6FH"
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"malware_dataset = pd.read_csv(\"MalwareArtifacts.csv\", delimiter=',')"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"id": "-kbytUCHA8j6"
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"# Extracting artifacts smaples fields # MajourLinkerVersion, MajorImageVersion, MajorOperatingSystemVersion,DllCharacteristics\n",
|
|
"samples = malware_dataset.iloc[:, [1,2,3,4]].values\n",
|
|
"targets = malware_dataset.iloc[:, 8].values"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"colab": {
|
|
"base_uri": "https://localhost:8080/"
|
|
},
|
|
"id": "jXBwP8eLBijT",
|
|
"outputId": "f03022bb-020b-4227-a407-c9199da4f747"
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"k_means = KMeans(n_clusters=2, max_iter=100)\n",
|
|
"k_means.fit(samples)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"colab": {
|
|
"base_uri": "https://localhost:8080/"
|
|
},
|
|
"id": "nWi4BxSTDGDQ",
|
|
"outputId": "2485d298-eeb0-4906-c0ec-c6f91baec6f1"
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"print(\"K-Means labels: \" + str(k_means.labels_))\n",
|
|
"print(\"\\n K-means clustering reulsts \\n\\n\", pd.crosstab(targets, k_means.labels_, rownames = [\"Observerd\"], colnames=[\"Predicted\"]))\n",
|
|
"print (\"\\nSilhouette coefficient: %0.3f\" % silhouette_score(samples, k_means.labels_, metric='euclidean')) "
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
}
|
|
],
|
|
"metadata": {
|
|
"colab": {
|
|
"name": "Udemy Malware detection with K-Means.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
|
|
}
|