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
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Audard Lucile
Image classification
Commits
6c0a1bf6
Commit
6c0a1bf6
authored
1 year ago
by
Audard Lucile
Browse files
Options
Downloads
Patches
Plain Diff
Update knn.py
parent
7a96330d
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
knn.py
+10
-20
10 additions, 20 deletions
knn.py
with
10 additions
and
20 deletions
knn.py
+
10
−
20
View file @
6c0a1bf6
...
...
@@ -43,35 +43,25 @@ def evaluate_knn(data_train, labels_train, data_test, labels_test, k):
return
accuracy
if
__name__
==
"
__main__
"
:
# Extraction of the data from Cifar database
data
,
labels
=
read_cifar
(
"
./data/cifar-10-batches-py
"
)
data_train
,
labels_train
,
data_test
,
labels_test
=
split_dataset
(
data
,
labels
,
0.9
)
# Formatting the data into training and testing sets
data_train
,
labels_train
,
data_test
,
labels_test
=
split_dataset
(
data
,
labels
,
0.1
)
# Data to plot
k_list
=
[
k
for
k
in
range
(
1
,
21
)]
accuracy
=
[
evaluate_knn
(
data_train
,
labels_train
,
data_test
,
labels_test
,
k
)
for
k
in
range
(
1
,
21
)]
# Plot the graph
plt
.
close
()
plt
.
plot
(
k_list
,
accuracy
)
plt
.
title
(
"
Variation of k-nearest neighbors method accuracy for k from 1 to 20
"
)
plt
.
xlabel
(
"
k value
"
)
plt
.
ylabel
(
"
Accuracy
"
)
plt
.
grid
(
True
,
which
=
'
both
'
)
plt
.
savefig
(
"
results/knn.png
"
)
# x_test = np.array([[1,2],[4,6]])
# x_labels_test = np.array([0,1])
# x_train = np.array([[2,4],[7,2],[4,6]])
# x_labels_train = np.array([0,1,1])
# dist = distance_matrix(x_test, x_train)
# accuracy = evaluate_knn(x_train, x_labels_train, x_test, x_labels_test, 1)
# print(accuracy)
plt
.
show
()
#plt.savefig("results/knn.png")
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