Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CS-440_Assignments
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
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
draju2
CS-440_Assignments
Commits
c7d1e9b3
Commit
c7d1e9b3
authored
8 years ago
by
che12
Browse files
Options
Downloads
Patches
Plain Diff
latest code
parent
5a7b633f
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
MP4/Problem2_2/1-1.py
+23
-2
23 additions, 2 deletions
MP4/Problem2_2/1-1.py
with
23 additions
and
2 deletions
MP4/Problem2_2/1-1.py
+
23
−
2
View file @
c7d1e9b3
...
...
@@ -41,11 +41,32 @@ def classify(k,p):
neighbors_labels
=
[
trainimage_labels
[
index
]
for
index
in
neighbors_indices
]
counts
=
np
.
bincount
(
neighbors_labels
)
result
=
np
.
argmax
(
counts
)
print
result
#
print result
test_result
.
append
(
result
)
totalCount
=
len
(
testimage_labels
)
overallAccuracy
=
sum
(
testimage_labels
[
i
]
==
test_result
[
i
]
for
i
in
range
(
totalCount
))
print
"
overall accuracy
"
,
overallAccuracy
/
float
(
totalCount
)
classify
(
5
,
2
)
\ No newline at end of file
print
"
k is
"
,
k
confusion_matrix
=
[[
0
for
i
in
range
(
10
)]
for
j
in
range
(
10
)]
classCount
=
[
0
]
*
10
for
i
in
range
(
totalCount
):
experiment_class
=
test_result
[
i
]
real_class
=
testimage_labels
[
i
]
classCount
[
int
(
real_class
)]
+=
1
confusion_matrix
[
int
(
real_class
)][
int
(
experiment_class
)]
+=
1
for
i
in
range
(
10
):
for
j
in
range
(
10
):
confusion_matrix
[
i
][
j
]
/=
float
(
classCount
[
i
])
confusion_matrix
=
np
.
array
(
confusion_matrix
)
#np.set_printoptions(3)
print
(
confusion_matrix
)
'''
for i in range (9):
classify(i+1,2)
'''
classify
(
5
,
10
)
\ No newline at end of file
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