조혁균

upload code and final report

This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
{
"cells": [
{
"cell_type": "code",
"execution_count": 49,
"metadata": {},
"outputs": [],
"source": [
"# importing modules \n",
"import numpy as np \n",
"import pandas as pd \n",
"import matplotlib.pyplot as plt\n",
"\n",
"%matplotlib inline\n",
"\n",
"# rawData = pd.read_csv(\"2nd_test_labeled.csv\" ,names=['Timestamp', 'ID', 'FLAG', 'DLC', 'DATA', 'attack'])\n",
"TrainData = pd.read_csv(\"2nd_labeled.csv\")\n",
"TestData = pd.read_csv(\"2nd_test_1_labeled.csv\")"
]
},
{
"cell_type": "code",
"execution_count": 50,
"metadata": {},
"outputs": [],
"source": [
"from sklearn.neighbors import KNeighborsClassifier"
]
},
{
"cell_type": "code",
"execution_count": 51,
"metadata": {
"scrolled": false
},
"outputs": [],
"source": [
"train_points = TrainData[['ID', 'FLAG', 'DLC', 'DATA']]\n",
"train_labels = TrainData[['attack']]\n",
"\n",
"test_points = TestData[['ID', 'FLAG', 'DLC', 'DATA']]\n",
"test_labels = TestData[['attack']]"
]
},
{
"cell_type": "code",
"execution_count": 54,
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/plain": [
"(1444688, 4)"
]
},
"execution_count": 54,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"test_points.shape"
]
},
{
"cell_type": "code",
"execution_count": 55,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"classifier = KNeighborsClassifier(n_neighbors= 4)"
]
},
{
"cell_type": "code",
"execution_count": 56,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"C:\\ProgramData\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:1: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" \"\"\"Entry point for launching an IPython kernel.\n"
]
},
{
"data": {
"text/plain": [
"KNeighborsClassifier(algorithm='auto', leaf_size=30, metric='minkowski',\n",
" metric_params=None, n_jobs=None, n_neighbors=4, p=2,\n",
" weights='uniform')"
]
},
"execution_count": 56,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"classifier.fit(train_points, train_labels)"
]
},
{
"cell_type": "code",
"execution_count": 58,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0.7255234348177599\n"
]
}
],
"source": [
"print(classifier.score(test_points, test_labels))"
]
}
],
"metadata": {
"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.7.1"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
This diff could not be displayed because it is too large.