Multi-class Perceptron
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# Create a new graph
Graph().as_default()
X = placeholder()
# Create a weight matrix for 2 output classes:
# One with a weight vector (1, 1) for blue and one with a weight vector (-1, -1) for red
W = Variable([
[1, -1],
[1, -1]
])
b = Variable([0, 0])
p = softmax( add(matmul(X, W), b) )
# Create a session and run the perceptron on our blue/red points
session = Session()
output_probabilities = session.run(p, {
X: np.concatenate((blue_points, red_points))
})
# Print the first 10 lines, corresponding to the probabilities of the first 10 points
print(output_probabilities[:10])
Enter to Rename, Shift+Enter to Preview