Mentions légales du service
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
NutriMorph
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
DEBREUVE Eric
NutriMorph
Commits
ab5192ae
Commit
ab5192ae
authored
4 years ago
by
NADAL Morgane
Browse files
Options
Downloads
Patches
Plain Diff
new plotting options to discriminate features based on the kmeans clusters
parent
904906c0
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
features_analysis.py
+45
-4
45 additions, 4 deletions
features_analysis.py
with
45 additions
and
4 deletions
features_analysis.py
+
45
−
4
View file @
ab5192ae
...
...
@@ -406,6 +406,47 @@ def KmeansOnDF(df: pd_.DataFrame(),
pl_
.
savefig
(
f
"
{
save_in
}
\\
feat_boxplot_
{
column
}
_
{
comb
}
_k=
{
nb_cluster
}
.png
"
)
pl_
.
close
()
# Do the same thing but separating durations
cond_col_df_dur
=
pd_
.
concat
((
cond_col_df
,
df
[
"
duration
"
]),
axis
=
1
)
groupby_dur_
=
cond_col_df_dur
.
groupby
(
"
duration
"
)
fig
=
pl_
.
figure
(
constrained_layout
=
False
,
figsize
=
(
15
,
10
))
gs
=
fig
.
add_gridspec
(
ncols
=
3
,
nrows
=
1
)
ax1
=
fig
.
add_subplot
(
gs
[
0
,
0
])
ax2
=
fig
.
add_subplot
(
gs
[
0
,
1
])
ax3
=
fig
.
add_subplot
(
gs
[
0
,
2
])
ax
=
[
ax1
,
ax2
,
ax3
]
# Plot a histogram and kernel density estimate
# print(f"Plot a histogram and kernel density estimate for feature {column}")
x
=
0
for
dur_
,
val
in
groupby_dur_
:
for
comb
,
color
in
zip
(
itertools
.
product
(
conditions
,
labels
),
sb_
.
color_palette
(
"
deep
"
,
n_colors
=
len
(
labels
)
*
len
(
conditions
))):
to_plot
=
val
.
loc
[(
val
[
'
condition
'
]
==
comb
[
0
])]
to_plot
=
to_plot
.
loc
[(
to_plot
[
'
label
'
]
==
comb
[
1
])]
# Kernel estimate of the histogram
sb_
.
distplot
(
to_plot
[[
column
]],
hist
=
False
,
color
=
color
,
ax
=
ax
[
x
])
lines
=
[
Line2D
([
0
],
[
0
],
color
=
c
,
linewidth
=
3
,
linestyle
=
'
-
'
)
for
c
in
sb_
.
color_palette
(
"
deep
"
,
n_colors
=
len
(
labels
)
*
len
(
conditions
))]
lb
=
list
(
itertools
.
product
(
conditions
,
labels
))
ax
[
x
].
legend
(
lines
,
lb
)
ax
[
x
].
set_title
(
f
'
{
dur_
}
'
,
fontsize
=
11
)
# ax[x].set_xlim(min(val[column]), max(val[column]))
# ax[x].set_ylim()
ax
[
x
].
set_xlabel
(
"
Distribution kernel estimate
"
)
ax
[
x
].
set_ylabel
(
"
Features values
"
)
x
+=
1
fig
.
suptitle
(
f
'
{
column
}
distribution
{
title
}
'
)
# pl_.tight_layout()
if
save_in
is
not
None
:
pl_
.
savefig
(
f
"
{
save_in
}
\\
feat_kernel_estimate_
{
column
}
_k=
{
nb_cluster
}
_dur.png
"
)
pl_
.
close
()
# Representation on the image
if
rep_on_image
:
RepresentationOnImages
(
labeled_somas
,
kmeans
,
nb_cluster
)
...
...
@@ -814,7 +855,7 @@ if __name__ == "__main__":
# -- PCA with all the features
print
(
"
\n
SELECTED FEATURES
\n
"
)
# Between the two conditions, regardless the duration of experiment (2 conditions, all durations)
PCAOnDF
(
df
,
PCAOnDF
(
selected_
df
,
target
=
"
condition
"
,
targets
=
[
"
CHO
"
,
"
DIO
"
],
colors
=
[
"
b
"
,
"
r
"
],
...
...
@@ -824,7 +865,7 @@ if __name__ == "__main__":
)
# # Between the two conditions, for each duration (2 conditions, 3 durations)
# groupby_duration = df.groupby("duration")
# groupby_duration =
selected_
df.groupby("duration")
# for duration, values in groupby_duration:
# # duration: str, values: pd_.DataFrame()
# PCAOnDF(values,
...
...
@@ -841,7 +882,7 @@ if __name__ == "__main__":
# -- K-means with all the features (2 conditions)
# Between the two conditions, regardless the duration of experiment (2 conditions, all durations)
kmeans
=
KmeansOnDF
(
df
,
kmeans
=
KmeansOnDF
(
selected_
df
,
target
=
"
condition
"
,
nb_clusters
=
(
2
,
3
,
4
,
5
),
elbow
=
False
,
...
...
@@ -853,7 +894,7 @@ if __name__ == "__main__":
)
# # Between the two conditions, for each duration (2 conditions, 3 durations)
# groupby_duration = df.groupby("duration")
# groupby_duration =
selected_
df.groupby("duration")
# for duration, values in groupby_duration:
# kmeans = KmeansOnDF(values,
# target="condition",
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment