forked from Introtocs/Week10_Lec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.py
36 lines (29 loc) · 1.02 KB
/
util.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import random
import sample
import matplotlib.pylab as pylab
LABELS = ('a','b','c')
def genDistribution(xMean=0, xSD=1, yMean=0, ySD=1, n=20, namePrefix=''):
samples = []
for s in range(n):
x = random.gauss(xMean, xSD)
y = random.gauss(yMean, ySD)
samples.append(sample.Sample(namePrefix+str(s), [x, y]))
return samples
def label(E):
return E.getLabel()
def make_cmap():
colors = ('b', 'g', 'r', 'c', 'm', 'y', 'k')
return colors
def make_cmarkers():
markers = ('o', 'v', '^', '<', '>', '8',
's', 'p', '*', 'h', 'H', 'D', 'd')
return markers
def plot_data(data):
MARKERS = make_cmarkers()
COLORS = make_cmap()
for l in range(len(LABELS)):
m = MARKERS[l]
x = [ data[d].getFeatures()[0] for d in range(len(data)) if data[d].getLabel() == LABELS[l] ]
y = [ data[d].getFeatures()[1] for d in range(len(data)) if data[d].getLabel() == LABELS[l] ]
pylab.scatter(x,y,label=LABELS[l],marker=m,color=COLORS[l])
pylab.show()