Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Classification of Text-Background Color Combination
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
s183927
Classification of Text-Background Color Combination
Commits
ab8ad738
Commit
ab8ad738
authored
Jan 9, 2019
by
s183897
Browse files
Options
Downloads
Patches
Plain Diff
Used nearest centroid algorithm, renamed accordingly
parent
5001d509
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
centroid.py
+2
-2
2 additions, 2 deletions
centroid.py
main (nearest centroid).py
+10
-10
10 additions, 10 deletions
main (nearest centroid).py
with
12 additions
and
12 deletions
K_means
.py
→
centroid
.py
+
2
−
2
View file @
ab8ad738
import
numpy
as
np
from
sklearn.cluster
import
KMeans
# function that finds c
luster of data points using K-means algorithm
def
km
(
X
):
# function that finds c
entroid of pre-labeled cluster of data points
def
centroid
(
X
):
kmeans
=
KMeans
(
n_clusters
=
1
)
kmeans
.
fit
(
X
)
c
=
kmeans
.
cluster_centers_
...
...
This diff is collapsed.
Click to expand it.
main (
K-means
).py
→
main (
nearest centroid
).py
+
10
−
10
View file @
ab8ad738
# -*- coding: utf-8 -*-
#
K-means
Text Color Chooser: Main
#
Nearest Centroid
Text Color Chooser: Main
import
pygame
import
os
import
numpy
as
np
...
...
@@ -7,7 +7,7 @@ import scipy
from
matplotlib
import
pyplot
from
mpl_toolkits.mplot3d
import
Axes3D
from
random
import
randint
from
K_means
import
km
from
centroid
import
centroid
from
matrixToFile
import
matrixToFile
# init
...
...
@@ -36,7 +36,7 @@ iconPic = pygame.image.load('icon.png')
pygame
.
display
.
set_icon
(
iconPic
)
# title of app
pygame
.
display
.
set_caption
(
'
K-means
Text Color Chooser 1.
1.1
'
)
pygame
.
display
.
set_caption
(
'
Nearest Centroid
Text Color Chooser 1.
2
'
)
# set fonts
smallfont
=
pygame
.
font
.
SysFont
(
'
comicsansms
'
,
25
)
...
...
@@ -86,13 +86,13 @@ while True:
text
(
'
press tab to show data
'
,
(
255
,
255
,
255
),
smallfont
,
width
-
275
,
10
)
# make prediction, display prediction above color box
whitec
luster
=
km
(
white
)
blackc
luster
=
km
(
black
)
whitec
ent
=
centroid
(
white
)
blackc
ent
=
centroid
(
black
)
y
=
np
.
reshape
(
color
,
(
-
1
,
3
))
if
len
(
points
)
>
1
:
if
scipy
.
spatial
.
distance
.
euclidean
(
y
,
whitec
luster
)
<
scipy
.
spatial
.
distance
.
euclidean
(
y
,
blackc
luster
):
if
scipy
.
spatial
.
distance
.
euclidean
(
y
,
whitec
ent
)
<
scipy
.
spatial
.
distance
.
euclidean
(
y
,
blackc
ent
):
display
.
blit
(
predPic
,
(
width
/
3
-
80
/
2
,
200
))
elif
scipy
.
spatial
.
distance
.
euclidean
(
y
,
whitec
luster
)
>
scipy
.
spatial
.
distance
.
euclidean
(
y
,
blackc
luster
):
elif
scipy
.
spatial
.
distance
.
euclidean
(
y
,
whitec
ent
)
>
scipy
.
spatial
.
distance
.
euclidean
(
y
,
blackc
ent
):
display
.
blit
(
predPic
,
(
width
/
1.5
-
80
/
2
,
200
))
else
:
display
.
blit
(
predPic
,
(
width
/
1.5
-
80
/
2
,
200
))
...
...
@@ -161,9 +161,9 @@ while True:
for
n
in
range
(
1
,
len
(
black
)):
ax
.
scatter
(
black
[
n
,
0
],
black
[
n
,
1
],
black
[
n
,
2
],
color
=
"
black
"
)
ax
.
scatter
(
color
[
0
],
color
[
1
],
color
[
2
],
color
=
"
blue
"
)
# display c
luster
s
ax
.
scatter
(
whitec
luster
[:,
0
],
whitec
luster
[:,
1
],
whitec
luster
[:,
2
],
marker
=
'
*
'
,
c
=
'
white
'
,
s
=
500
)
ax
.
scatter
(
blackc
luster
[:,
0
],
blackc
luster
[:,
1
],
blackc
luster
[:,
2
],
marker
=
'
*
'
,
c
=
'
black
'
,
s
=
500
)
# display c
entroid
s
ax
.
scatter
(
whitec
ent
[:,
0
],
whitec
ent
[:,
1
],
whitec
ent
[:,
2
],
marker
=
'
*
'
,
c
=
'
white
'
,
s
=
500
)
ax
.
scatter
(
blackc
ent
[:,
0
],
blackc
ent
[:,
1
],
blackc
ent
[:,
2
],
marker
=
'
*
'
,
c
=
'
black
'
,
s
=
500
)
# axis labels
ax
.
set_xlabel
(
'
R
'
,
fontsize
=
15
)
ax
.
set_ylabel
(
'
G
'
,
fontsize
=
15
)
...
...
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