How to plot the OR function along with the decision boundary of a Perceptron? I've written a small program that predicts correctly the OR function output. The problem is that when I try to plot the decision boundary, I don't know what to do. Should I plot the final weights?. Does the weights vector mean the same thing as with linear regression?. Meaning is it the linear coefficients of x1 and x2?
This is the code:
from numpy import *

def sign(colVector):
    cp = where(colVector > 0, 1, 0)
    return cp

input = array([ [0,0],
            [0,1],
            [1,0],
            [1,1]
          ])

bias = ones((4,1))

input = concatenate( (bias, input), axis=1 )

target = array([ [0],
             [1],
             [1],
             [1]
           ])

weights = random.random( (3,1) )

def forward(input, weights):
    y = dot(input, weights)

    return  sign(y)

def update(input, weights):
    alpha = 0.25
    y = forward(input, weights)
    weights = weights + alpha * dot(input.T , (target - y) )

    return weights

def learn(input, weights):
    iterations = 10

    for iter in list(range(iterations)):
        weights= update(input, weights)
    return weights


weights = learn(input, weights)
print( "\nFinal hypothesis:\n{}".format(forward(input, weights)) )

Also:
plt.scatter(input[:,0], input[:,1])
plt.show()

outputs all four data points as the same color. How can I give the (0,0) one a different color or shape?
 A: Your problem is to find a bound for an equation:
$$
w_1 * x + w_2 * y + b = 0
$$
Where the $b$ is bias, $w_1$ and $w_2$ are weights and $x$, $y$ are your input data.
Let's assume that inputs can be continuous. After training procedure you have weights and bias, so your input data is unknown in this formula.
Also we know that algorithm make linear bounds for the problem, so we can easy find the solution for the equation above. We must check two cases. First one is when $x = 0$ and $y \neq 0$. Second one is when $x \neq 0$ and $y = 0$. Other results we can interpolate linearly. Now we have two equations.
$$
w_1 * x + b = 0
$$
$$
w_2 * y + b = 0
$$
So, the solution is clear.
$$
x = -b / w_1
$$
$$
y = -b / w_2
$$
These two values are the bounds. From these two values we can build the line equation.
$$
f(z) = c * z + d
$$
Now we have another two equations and two unknowns.
$$
f(0) = c * 0 + d = y
$$
$$
f(x) = c * x + d = 0
$$
Solution is also very simple.
$$
d = y
$$
$$
c = -d / x = -y / x
$$
When I run your algorithms I got the weights:
[[-0.17007879]
 [ 0.51599933]
 [ 0.75514129]]

And now we can apply these equations in code.
# After your code
import matplotlib.pyplot as plt
plt.style.use('ggplot')

b, w1, w2 = weights
x = -b / w1
y = -b / w2

d = y
c = -y / x

line_x_coords = array([0, x])
line_y_coords = c * line_x_coords + d

plt.plot(line_x_coords, line_y_coords)
plt.scatter(*input[:, 1:].T, c=target, s=75)
plt.show()


If you want make your code reproducible, set up seed before generate the weights for your network
random.seed(0)

Monte Carlo method
Also you can always run a simple Monte Carlo method and check your intuition if you don't know what to do with the problem.
points = []
outputs = []
for _ in range(10000):
    point = random.random((2))
    points.append(point)
    input_vector = concatenate([[1], point], axis=1)
    network_output = forward(input_vector, weights)
    outputs.append(network_output)

plt.scatter(*array(points).T, c=outputs, s=75)
plt.show()


