Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
Image classification
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Danjou Pierre
Image classification
Commits
4093c7bd
Commit
4093c7bd
authored
7 months ago
by
Danjou Pierre
Browse files
Options
Downloads
Patches
Plain Diff
commi
parent
fb477c85
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
knn.py
+25
-4
25 additions, 4 deletions
knn.py
results.png
+0
-0
0 additions, 0 deletions
results.png
results/knn.png
+0
-0
0 additions, 0 deletions
results/knn.png
with
25 additions
and
4 deletions
knn.py
+
25
−
4
View file @
4093c7bd
...
@@ -45,6 +45,26 @@ def evaluate_knn(data_train, labels_train, data_test, labels_tests, k):
...
@@ -45,6 +45,26 @@ def evaluate_knn(data_train, labels_train, data_test, labels_tests, k):
accuracy
=
(
labels_tests
==
result_test
).
sum
()
/
N
accuracy
=
(
labels_tests
==
result_test
).
sum
()
/
N
return
(
accuracy
)
return
(
accuracy
)
def
bench_knn
():
k_indices
=
[
i
for
i
in
range
(
20
)
if
i
!=
0
]
accuracies
=
[]
# Loop on the k_indices to get all the accuracies
for
k
in
k_indices
:
accuracy
=
evaluate_knn
(
data_train
,
labels_train
,
data_test
,
labels_test
,
k
)
accuracies
.
append
(
accuracy
)
print
(
accuracy
)
# Save and show the graph of accuracies
fig
=
plt
.
figure
()
plt
.
plot
(
k_indices
,
accuracies
)
plt
.
title
(
"
Accuracy as function of k
"
)
plt
.
show
()
plt
.
savefig
(
r
'
C:\Users\danjo\Documents\GitHub\image-classification\results
'
)
return
()
...
@@ -55,14 +75,15 @@ if __name__ == "__main__":
...
@@ -55,14 +75,15 @@ if __name__ == "__main__":
data
,
labels
=
read_cifar
(
main_path
)
data
,
labels
=
read_cifar
(
main_path
)
data_train
,
data_test
,
labels_train
,
labels_test
=
split_dataset
(
data
,
labels
,
0.9
)
data_train
,
data_test
,
labels_train
,
labels_test
=
split_dataset
(
data
,
labels
,
0.9
)
print
(
labels_test
)
dists
=
distance_matrix
(
data_test
,
data_train
)
dists
=
distance_matrix
(
data_test
,
data_train
)
#print(dists)
r
=
knn_predict
(
dists
,
labels_train
,
10
)
r
=
knn_predict
(
dists
,
labels_train
,
10
)
accurancy
=
evaluate_knn
(
data_train
,
labels_train
,
data_test
,
labels_test
,
10
)
accurancy
=
evaluate_knn
(
data_train
,
labels_train
,
data_test
,
labels_test
,
10
)
print
(
r
)
print
(
accurancy
)
print
(
accurancy
)
bench_knn
()
This diff is collapsed.
Click to expand it.
results.png
0 → 100644
+
0
−
0
View file @
4093c7bd
2.34 KiB
This diff is collapsed.
Click to expand it.
results/knn.png
0 → 100644
+
0
−
0
View file @
4093c7bd
25.6 KiB
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