120 lines
2.8 KiB
Plaintext
120 lines
2.8 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"id": "o1E-avoFxNcn"
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"import pandas as pd\n",
|
|
"import numpy as np\n",
|
|
"from sklearn import *\n",
|
|
"from sklearn.linear_model import LogisticRegression\n",
|
|
"from sklearn.metrics import accuracy_score"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"id": "XviNmJlcxbem"
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"phishing_dataset = np.genfromtxt('datasets-2/phishing_dataset.csv', delimiter=',', dtype=np.int32)\n",
|
|
"samples = phishing_dataset[:,:-1]\n",
|
|
"targets = phishing_dataset[:, -1]\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"id": "do33z7f7xz8I"
|
|
},
|
|
"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)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"colab": {
|
|
"base_uri": "https://localhost:8080/"
|
|
},
|
|
"id": "5Q3Z13wVyFjM",
|
|
"outputId": "96f7d9e9-fd88-4a1a-f8dc-381f785fc588"
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"from sklearn import tree\n",
|
|
"tree_classifier = tree.DecisionTreeClassifier()\n",
|
|
"tree_classifier.fit(training_samples, training_targets)\n",
|
|
"predictions = tree_classifier.predict(testing_samples)\n",
|
|
"accuracy = 100.0* 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": {
|
|
"collapsed_sections": [],
|
|
"name": "Phishing 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
|
|
}
|