Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
TP-Clustering
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IA et Machine Learning
TP-Clustering
Commits
73f1d8e7
Commit
73f1d8e7
authored
1 year ago
by
thibault.capt
Browse files
Options
Downloads
Patches
Plain Diff
correct plot error*
parent
1f6f9abe
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
perceptron-tp3.py
+8
-11
8 additions, 11 deletions
perceptron-tp3.py
with
8 additions
and
11 deletions
perceptron-tp3.py
+
8
−
11
View file @
73f1d8e7
...
...
@@ -47,13 +47,12 @@ if __name__ == '__main__':
# Paramètres d'apprentissage
learning_rate
=
0.034
max_iterations
=
2000
num_hidden
=
20
0
num_hidden
=
1
0
# Initialiser les poids pour l'entrée dans la couche cachée et masqués dans la couche de sortie
weights_input_hidden
=
np
.
random
.
rand
(
num_features
+
1
,
num_hidden
)
-
0.5
weights_hidden_output
=
np
.
random
.
rand
(
num_hidden
+
1
)
-
0.5
errors_x
=
[]
errors_y
=
[]
error_points
=
np
.
empty
((
0
,
2
))
print
(
"
Weights input to hidden:
"
,
weights_input_hidden
)
print
(
"
Weights hidden to output:
"
,
weights_hidden_output
)
...
...
@@ -79,12 +78,6 @@ if __name__ == '__main__':
total_error
+=
(
target
-
output
)
**
2
/
2
# Ajouter les coordonnées des erreurs à la liste
if
target
!=
round
(
output
):
errors_x
.
append
(
X
[
i
,
0
])
errors_y
.
append
(
X
[
i
,
1
])
if
(
iteration
%
10
==
0
)
or
iteration
==
0
:
# print tous les 5 iterations
print
(
f
"
Iteration
{
iteration
+
1
}
: Error =
{
total_error
}
"
)
...
...
@@ -97,6 +90,8 @@ if __name__ == '__main__':
pred
=
1
if
output
>=
0.5
else
0
if
pred
==
target
:
correct_classifications
+=
1
else
:
error_points
=
np
.
vstack
((
error_points
,
X
[
i
]))
accuracy
=
correct_classifications
/
len
(
X
)
print
(
f
"
Taux de classifications correctes:
{
accuracy
*
100
}
%
"
)
...
...
@@ -105,9 +100,11 @@ if __name__ == '__main__':
plt
.
figure
()
plt
.
scatter
(
X
[
y
==
0
][:,
0
],
X
[
y
==
0
][:,
1
],
color
=
'
green
'
,
label
=
'
Classe 0
'
)
plt
.
scatter
(
X
[
y
==
1
][:,
0
],
X
[
y
==
1
][:,
1
],
color
=
'
blue
'
,
label
=
'
Classe 1
'
)
plt
.
scatter
(
error
s_x
,
errors_y
,
color
=
'
red
'
,
marker
=
'
x
'
,
label
=
'
Erreurs
'
)
plt
.
title
(
'
Données
'
)
plt
.
scatter
(
error
_points
[:,
0
],
error_points
[:,
1
],
color
=
'
red
'
,
label
=
'
Erreurs
'
)
plt
.
title
(
'
Données
avec Points d
\'
Erreur en Rouge
'
)
plt
.
xlabel
(
'
Norm_Grade_1
'
)
plt
.
ylabel
(
'
Norm_Grade_2
'
)
plt
.
legend
()
plt
.
show
()
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