Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
monticore
EmbeddedMontiArc
generators
EMAM2Middleware
Commits
a1a1de51
Commit
a1a1de51
authored
Mar 14, 2019
by
Alexander David Hellwig
Browse files
Add script to visualize silhouette results
parent
96647481
Pipeline
#111613
canceled with stages
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/test/resources/silhouetteVisualisation.py
0 → 100644
View file @
a1a1de51
import
json
import
matplotlib.pyplot
as
plt
import
argparse
def
visualise_silhouette_result
(
filename
,
modelName
):
with
open
(
filename
)
as
data_file
:
data_raw
=
json
.
load
(
data_file
)
data
=
[]
for
d
in
data_raw
:
data
.
append
((
d
[
"NumberOfClusters"
],
d
[
"Score"
]))
#sort by cluster size
data
.
sort
(
key
=
lambda
d
:
d
[
0
])
clusters
=
[
cluster
for
(
cluster
,
score
)
in
data
]
score
=
[
score
for
(
cluster
,
score
)
in
data
]
min_score
=
min
(
score
)
max_score
=
max
(
score
)
#plot
fig
,
ax
=
plt
.
subplots
()
ax
.
plot
(
clusters
,
score
,
marker
=
'.'
,
linestyle
=
'none'
)
ax
.
set_ylim
(
bottom
=-
1
,
top
=
1
)
ax
.
set
(
xlabel
=
'Cluster size'
,
ylabel
=
'Silhouette score'
,
title
=
'Silhouette score of the '
+
modelName
+
' model ordered by clustering size'
)
ax
.
grid
()
textstr
=
'
\n
'
.
join
((
"min = "
+
str
(
round
(
min_score
,
3
)),
"max= "
+
str
(
round
(
max_score
,
3
))))
props
=
dict
(
boxstyle
=
'round'
,
facecolor
=
'wheat'
,
alpha
=
0.5
)
ax
.
text
(
0.95
,
0.05
,
textstr
,
transform
=
ax
.
transAxes
,
fontsize
=
14
,
verticalalignment
=
'bottom'
,
ha
=
'right'
,
bbox
=
props
)
plt
.
show
()
def
parse_args
():
parser
=
argparse
.
ArgumentParser
(
description
=
'Get json files'
)
parser
.
add_argument
(
'autopilot'
,
metavar
=
'autopilot'
,
help
=
'montecarloresult json location of autopilot'
)
parser
.
add_argument
(
'pacman'
,
metavar
=
'pacman'
,
help
=
'clusteringResults.json location of pacman'
)
parser
.
add_argument
(
'supermario'
,
metavar
=
'supermario'
,
help
=
'clusteringResults.json location of supermario'
)
parser
.
add_argument
(
'daimler'
,
metavar
=
'daimler'
,
help
=
'clusteringResults.json location of daimlermodel'
)
return
parser
.
parse_args
()
args
=
parse_args
()
visualise_silhouette_result
(
args
.
autopilot
,
"Autopilot"
)
visualise_silhouette_result
(
args
.
pacman
,
"Pacman"
)
visualise_silhouette_result
(
args
.
supermario
,
"Supermario"
)
visualise_silhouette_result
(
args
.
daimler
,
"Daimler"
)
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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