Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
2020-092
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
2020 - 092
2020-092
Commits
cd445c79
Commit
cd445c79
authored
Nov 02, 2020
by
Ashen Udayanga Sudugala
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload Volumetric.py File
parent
c45f28eb
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
116 additions
and
0 deletions
+116
-0
Volumetric.py
Volumetric.py
+116
-0
No files found.
Volumetric.py
0 → 100644
View file @
cd445c79
# Importing the libraries
import
numpy
as
np
import
matplotlib.pyplot
as
plt
import
pandas
as
pd
from
sklearn.impute
import
SimpleImputer
from
sklearn.metrics
import
accuracy_score
from
sklearn.metrics
import
f1_score
from
sklearn.metrics
import
confusion_matrix
from
sklearn.metrics
import
precision_score
from
sklearn.metrics
import
recall_score
from
sklearn.model_selection
import
train_test_split
from
sklearn.tree
import
DecisionTreeClassifier
# Importing the dataset
train
=
pd
.
read_csv
(
"/Users/ASHEN/Education/SLIIT/Research/Wanheda_Server/MobileBotNet/packet_data.csv"
,
index_col
=
0
,
low_memory
=
False
)
train
.
shape
# Feature Scaling
from
sklearn
import
preprocessing
for
f
in
train
.
columns
:
if
train
[
f
]
.
dtype
==
'object'
:
label
=
preprocessing
.
LabelEncoder
()
label
.
fit
(
list
(
train
[
f
]
.
values
))
train
[
f
]
=
lbl
.
transform
(
list
(
train
[
f
]
.
values
))
train
.
fillna
((
-
999
),
inplace
=
True
)
train
=
np
.
array
(
train
)
train
=
train
.
astype
(
float
)
Y
=
train
[
'Label'
]
X
=
train
.
drop
(
"Label"
,
axis
=
1
)
print
(
train
.
shape
)
print
(
X
.
shape
)
print
(
Y
.
shape
)
# Spliting the dataset into the training set and test set
seed
=
7
test_size
=
0.33
X_train
,
X_test
,
y_train
,
y_test
=
train_test_split
(
X
,
Y
,
test_size
=
test_size
,
random_state
=
seed
)
print
(
X_train
.
shape
)
print
(
y_train
.
shape
)
print
(
X_test
.
shape
)
print
(
y_test
.
shape
)
# Fitting Decision Tree to the training set
model
=
DecisionTreeClassifier
(
max_depth
=
5
,
random_state
=
0
)
model
.
fit
(
X_train
,
y_train
)
y_pred
=
model
.
predict
(
X_test
)
print
(
model
)
# Plotting the tree, here it should access graph's first element
from
sklearn
import
tree
from
sklearn.externals.six
import
StringIO
import
pydot
dot_data
=
StringIO
()
tree
.
export_graphviz
(
model
,
out_file
=
dot_data
)
graph
=
pydot
.
graph_from_dot_data
(
dot_data
.
getvalue
())
graph
[
0
]
.
write_pdf
(
"tree.pdf"
)
# Predicting the data[round(value) for value in y_pred]
y_pred
=
model
.
predict
(
X_test
)
# Creating confusion metrics to check the performance of algorithm
cm
=
confusion_matrix
(
y_test
,
y_pred
)
print
(
"confusion matrix:
\n
"
,
cm
)
# Accuracy
accuracy
=
accuracy_score
(
y_test
,
y_pred
)
print
(
"accuracy:"
,
accuracy
)
# F1 Score
f1score
=
f1_score
(
y_test
,
y_pred
)
print
(
"f1_score:"
,
f1score
)
# Precision Score
pr
=
precision_score
(
y_test
,
y_pred
)
print
(
"Precision:"
,
pr
)
# Recall Score
rs
=
recall_score
(
y_test
,
y_pred
)
print
(
"Recall_score:"
,
rs
)
# Misclassified Samples
misclassified_samples
=
X_test
[
y_test
!=
y_pred
]
mc
=
misclassified_samples
.
shape
[
0
]
print
(
"Misclassified :"
,
mc
)
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment