118 lines
2.8 KiB
Plaintext
118 lines
2.8 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"id": "ghWhD6ZCmrmn"
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"import pandas as pd\n",
|
|
"import numpy as np\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"id": "d1jF1kTSmwlP"
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"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": "rz76LOfVm8d_"
|
|
},
|
|
"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]"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"colab": {
|
|
"base_uri": "https://localhost:8080/"
|
|
},
|
|
"id": "IZXlTkdUnX55",
|
|
"outputId": "351bdbd0-ab97-49ca-c8d1-4bd5ce55f2c2"
|
|
},
|
|
"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",
|
|
"log_classifier = LogisticRegression()\n",
|
|
"log_classifier.fit(training_samples, training_targets)\n",
|
|
"predictions = log_classifier.predict(testing_samples)\n",
|
|
"accuracy = 100.0*accuracy_score(testing_targets, predictions)\n",
|
|
"print(\"Logistic Regression 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": "Logistic Regression implementation.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
|
|
}
|