Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F97562180
visu.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sun, Jan 5, 07:29
Size
1 KB
Mime Type
text/x-python
Expires
Tue, Jan 7, 07:29 (2 d)
Engine
blob
Format
Raw Data
Handle
23426878
Attached To
R13271 Optical_Trapping_ML
visu.py
View Options
import
matplotlib.pyplot
as
plt
import
seaborn
as
sns
from
sklearn.inspection
import
permutation_importance
def
plot_feature_importance
(
model
,
X_train
,
y_train
,
feature_names
,
output_path
):
result
=
permutation_importance
(
model
,
X_train
,
y_train
,
n_repeats
=
10
,
random_state
=
42
)
sorted_idx
=
result
.
importances_mean
.
argsort
()
plt
.
figure
(
figsize
=
(
12
,
8
))
plt
.
barh
(
range
(
len
(
sorted_idx
)),
result
.
importances_mean
[
sorted_idx
],
align
=
'center'
)
plt
.
yticks
(
range
(
len
(
sorted_idx
)),
[
feature_names
[
i
]
for
i
in
sorted_idx
])
plt
.
xlabel
(
"Permutation Importance"
)
plt
.
title
(
"Feature Importance"
)
plt
.
savefig
(
output_path
)
plt
.
close
()
def
plot_feature_correlation
(
dataframe
,
output_path
):
plt
.
figure
(
figsize
=
(
12
,
10
))
corr_matrix
=
dataframe
.
corr
()
sns
.
heatmap
(
corr_matrix
,
annot
=
True
,
fmt
=
".2f"
,
cmap
=
"coolwarm"
)
plt
.
title
(
"Feature Correlation Matrix"
)
plt
.
savefig
(
output_path
)
plt
.
close
()
def
plot_predicted_counts
(
predictions
,
df
,
output_path
):
df
[
'predictions'
]
=
predictions
result
=
df
.
groupby
(
'antibiotics_quantity'
)[
'predictions'
]
.
value_counts
()
.
unstack
()
.
fillna
(
0
)
# Plotting side-by-side bars
result
.
plot
(
kind
=
'bar'
,
color
=
[
'orange'
,
'blue'
],
width
=
0.8
)
plt
.
xlabel
(
'Antibiotics Quantity'
)
plt
.
ylabel
(
'Count'
)
plt
.
title
(
'Predicted Dead/Alive Bacteria per Antibiotic Level'
)
plt
.
legend
(
title
=
'Predictions'
,
labels
=
[
'Dead'
,
'Alive'
])
plt
.
savefig
(
output_path
)
plt
.
close
()
Event Timeline
Log In to Comment