MCPcopy Create free account
hub / github.com/lazyprogrammer/machine_learning_examples / get_spiral

Function get_spiral

numpy_class/exercises/ex8.py:13–45  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

11import matplotlib.pyplot as plt
12
13def get_spiral():
14 # Idea: radius -> low...high
15 # (don't start at 0, otherwise points will be "mushed" at origin)
16 # angle = low...high proportional to radius
17 # [0, 2pi/6, 4pi/6, ..., 10pi/6] --> [pi/2, pi/3 + pi/2, ..., ]
18 # x = rcos(theta), y = rsin(theta) as usual
19
20 radius = np.linspace(1, 10, 100)
21 thetas = np.empty((6, 100))
22 for i in range(6):
23 start_angle = np.pi*i / 3.0
24 end_angle = start_angle + np.pi / 2
25 points = np.linspace(start_angle, end_angle, 100)
26 thetas[i] = points
27
28 # convert into cartesian coordinates
29 x1 = np.empty((6, 100))
30 x2 = np.empty((6, 100))
31 for i in range(6):
32 x1[i] = radius * np.cos(thetas[i])
33 x2[i] = radius * np.sin(thetas[i])
34
35 # inputs
36 X = np.empty((600, 2))
37 X[:,0] = x1.flatten()
38 X[:,1] = x2.flatten()
39
40 # add noise
41 X += np.random.randn(600, 2)*0.5
42
43 # targets
44 Y = np.array([0]*100 + [1]*100 + [0]*100 + [1]*100 + [0]*100 + [1]*100)
45 return X, Y
46
47
48X, Y = get_spiral()

Callers 2

ex9.pyFile · 0.90
ex8.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected