Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Q
qbe
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lifo
A
Anaïs Halftermeyer
queryByExample
qbe
Commits
c4168778
Commit
c4168778
authored
Sep 26, 2025
by
Elias
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
to number of word occurrences
parent
03786cc6
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
58 additions
and
0 deletions
+58
-0
README.md
README.md
+5
-0
TopMotsParBin.py
TopMotsParBin.py
+53
-0
No files found.
README.md
View file @
c4168778
...
@@ -70,6 +70,11 @@ python3 frequency_grouping.py
...
@@ -70,6 +70,11 @@ python3 frequency_grouping.py
```
bash
```
bash
python3 graphics.py
python3 graphics.py
```
```
**TopMotsParBin.py :**
Bar chart to display top number of word occurrences per Bin.
```
bash
python3 TopMotsParBin.py
```
# Clustering methods
# Clustering methods
...
...
TopMotsParBin.py
0 → 100755
View file @
c4168778
import
csv
from
collections
import
defaultdict
import
matplotlib.pyplot
as
plt
input_file
=
"res7_Random.csv"
# Dictionnaire : Bin : liste de tuples (mot, train)
bin_mots
=
defaultdict
(
list
)
with
open
(
input_file
,
mode
=
"r"
,
newline
=
""
)
as
f
:
reader
=
csv
.
reader
(
f
)
next
(
reader
)
for
row
in
reader
:
mot
=
row
[
0
]
train
=
int
(
row
[
1
])
bin_val
=
int
(
row
[
4
])
if
train
>=
1
:
bin_mots
[
bin_val
]
.
append
((
mot
,
train
))
# Récupérer les 2 mots les plus fréquents dans chaque bin, si un seul mot par bin, on le prend
top_mots_par_bin
=
{}
for
bin_val
,
mots
in
bin_mots
.
items
():
sorted_mots
=
sorted
(
mots
,
key
=
lambda
x
:
x
[
1
],
reverse
=
True
)
top_mots_par_bin
[
bin_val
]
=
sorted_mots
[:
2
]
# Trier les bins par ordre croissant
bins
=
sorted
(
top_mots_par_bin
.
keys
())
labels
=
[]
values
=
[]
for
bin_val
in
bins
:
for
mot
,
train_val
in
top_mots_par_bin
[
bin_val
]:
labels
.
append
(
f
"{mot}
\n
(Bin {bin_val})"
)
values
.
append
(
train_val
)
# Affichage du bar chart
plt
.
figure
(
figsize
=
(
12
,
6
))
bars
=
plt
.
bar
(
labels
,
values
,
color
=
'lightcoral'
)
# Ajouter les valeurs au-dessus
for
bar
in
bars
:
height
=
bar
.
get_height
()
plt
.
text
(
bar
.
get_x
()
+
bar
.
get_width
()
/
2
,
height
+
0.5
,
str
(
height
),
ha
=
'center'
,
va
=
'bottom'
,
fontsize
=
9
)
plt
.
title
(
"Top words by Bin according to the train frequency"
)
plt
.
ylabel
(
"Occurrences in Train"
)
plt
.
xticks
(
rotation
=
45
,
ha
=
'right'
)
plt
.
tight_layout
()
plt
.
grid
(
axis
=
'y'
,
linestyle
=
'--'
,
alpha
=
0.5
)
plt
.
show
()
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