Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Alessio Cosenza
giomi-ai
Commits
5b0c013c
Commit
5b0c013c
authored
5 years ago
by
Alessio Cosenza
🐲
Browse files
Options
Download
Email Patches
Plain Diff
Testing
parent
67b5fbf0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
15 deletions
+31
-15
.gitignore
.gitignore
+2
-0
DataAnalyzer.py
DataAnalyzer.py
+27
-13
main.py
main.py
+2
-2
No files found.
.gitignore
0 → 100644
View file @
5b0c013c
__pycache__/*
model.*
\ No newline at end of file
This diff is collapsed.
Click to expand it.
DataAnalyzer.py
View file @
5b0c013c
...
...
@@ -26,7 +26,6 @@ class DataAnalyzer:
def
applyPCA
(
self
,
dataframe
:
pd
.
DataFrame
):
pca
=
PCA
(
n_components
=
self
.
n_components
)
fitted
=
pca
.
fit_transform
(
dataframe
[
self
.
metrics
])
dataframe
[
self
.
axis
[:
self
.
n_components
]]
=
pd
.
DataFrame
(
fitted
,
index
=
dataframe
.
index
)
def
applyKMeans
(
self
,
dataframe
:
pd
.
DataFrame
,
n_clusters
:
int
)
->
KMeans
:
...
...
@@ -45,26 +44,30 @@ class DataAnalyzer:
def
plot
(
self
,
dataframe
:
pd
.
DataFrame
,
labels
:
List
[
int
],
centroids
:
List
[
List
[
float
]]):
if
self
.
n_components
==
2
:
ax
=
plt
.
subplot
(
1
,
1
,
1
)
scat
=
ax
.
scatter
(
dataframe
[
'x'
],
dataframe
[
'y'
],
c
=
labels
,
cmap
=
self
.
cmap
,
label
=
labels
)
#
scat = ax.scatter(dataframe['x'], dataframe['y'], c=labels, cmap=self.cmap, label=labels)
else
:
fig
=
plt
.
figure
()
ax
=
Axes3D
(
fig
)
scat
=
ax
.
scatter
(
dataframe
[
'x'
],
dataframe
[
'y'
],
dataframe
[
'z'
],
c
=
labels
,
cmap
=
self
.
cmap
,
label
=
labels
)
# legend = ax.legend(*scat.legend_elements(), loc='upper right', title='Clusters')
# ax.add_artist(legend)
# scat = ax.scatter(dataframe['x'], dataframe['y'], dataframe['z'], c=labels, cmap=self.cmap, label=labels)
#legend = ax.legend(*scat.legend_elements(), loc='upper right', title='Clusters')
#ax.add_artist(legend)
# , marker='°'
arr
=
np
.
arange
(
len
(
centroids
))
ax
.
scatter
(
centroids
[:,
0
],
centroids
[:,
1
],
c
=
arr
,
cmap
=
self
.
cmap
,
marker
=
'*'
,
s
=
500
,
lw
=
1.5
,
edgecolor
=
(
0
,
0
,
0
,
1
))
ax
.
scatter
(
centroids
[:,
0
],
centroids
[:,
1
],
c
=
arr
,
cmap
=
self
.
cmap
,
marker
=
'*'
,
s
=
400
,
lw
=
1.5
,
edgecolor
=
(
0
,
0
,
0
,
1
))
# ax.set_xlim([-1000000, 8000000])
# ax.set_ylim([0, 2600])
# if (self.n_components == 3):
# ax.set_zlim([-80, 80])
ax
.
set_xticklabels
([])
ax
.
set_yticklabels
([])
if
(
self
.
n_components
==
3
):
ax
.
set_zticklabels
([])
return
ax
,
plt
def
addPatientPoint
(
self
,
dataframe
:
pd
.
DataFrame
,
ax
:
Axes
,
processInstanceId
:
str
,
lastOrKM
:
bool
):
def
addPatientPoint
(
self
,
dataframe
:
pd
.
DataFrame
,
ax
:
Axes
,
processInstanceId
:
str
,
lastOrKM
:
bool
,
kmeans
:
KMeans
):
#If lastOrKM is true it plots the cluster of all patient's data
patientData
=
dataframe
[
dataframe
[
'processInstanceId'
]
==
processInstanceId
]
...
...
@@ -76,15 +79,26 @@ class DataAnalyzer:
pointToPlot
=
patientData
.
tail
(
1
)[
self
.
axis
[:
self
.
n_components
]].
to_numpy
()[
0
]
if
self
.
n_components
==
2
:
ax
.
scatter
(
pointToPlot
[
0
],
pointToPlot
[
1
],
marker
=
'*'
,
c
=
'black'
,
s
=
4
50
)
ax
.
scatter
(
pointToPlot
[
0
],
pointToPlot
[
1
],
c
=
kmeans
.
predict
(
pointToPlot
.
reshape
(
1
,
-
1
))
,
s
=
2
50
,
marker
=
'x'
)
else
:
ax
.
scatter
(
pointToPlot
[
0
],
pointToPlot
[
1
],
pointToPlot
[
2
],
marker
=
'
*
'
,
c
=
'black'
,
s
=
450
)
ax
.
scatter
(
pointToPlot
[
0
],
pointToPlot
[
1
],
pointToPlot
[
2
],
c
=
kmeans
.
predict
(
pointToPlot
.
reshape
(
1
,
-
1
)),
s
=
250
,
marker
=
'
x
'
,
c
map
=
self
.
cmap
)
return
pointToPlot
def
addAllPatientPoints
(
self
,
dataframe
:
pd
.
DataFrame
,
ax
:
Axes
,
processInstanceId
:
str
):
patientData
=
dataframe
[
dataframe
[
'processInstanceId'
]
==
processInstanceId
]
data
=
patientData
[
self
.
axis
[:
self
.
n_components
]].
to_numpy
()
if
self
.
n_components
==
2
:
x
=
data
[:,
0
]
y
=
data
[:,
1
]
ax
.
quiver
(
x
[:
-
1
:
4
],
y
[:
-
1
:
4
],
x
[
1
::
4
]
-
x
[:
-
1
:
4
],
y
[
1
::
4
]
-
y
[:
-
1
:
4
])
#ax.plot(data[:, 0], data[:, 1], c='green')
else
:
x
=
data
[:,
0
]
y
=
data
[:,
1
]
z
=
data
[:,
2
]
ax
.
quiver
(
x
[:
-
1
],
y
[:
-
1
],
z
[:
-
1
],
x
[
1
:]
-
x
[:
-
1
],
y
[
1
:]
-
y
[:
-
1
],
z
[
1
:]
-
z
[:
-
1
],
length
=
10
,
normalize
=
True
,
arrow_length_ratio
=
0.9
)
This diff is collapsed.
Click to expand it.
main.py
View file @
5b0c013c
...
...
@@ -21,8 +21,8 @@ def main(n_dimensions: int, n_clusters: int, processInstanceId: str, method: str
method
=
True
if
method
==
'cluster'
else
False
point
=
da
.
addPatientPoint
(
df
,
ax
,
processInstanceId
,
method
)
#
da.addAllPatientPoints(df, ax, processInstanceId)
#
point = da.addPatientPoint(df, ax, processInstanceId,
True, kmeans
)
da
.
addAllPatientPoints
(
df
,
ax
,
processInstanceId
)
#distance = kmeans.transform(point.reshape(1, -1))
#normalizedDistance = (distance / np.linalg.norm(distance, ord=2, axis=1, keepdims=True))[0]
# out = {
...
...
This diff is collapsed.
Click to expand it.
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