In [2]:
from numpy import *
from PIL import *
import pickle
from pylab import *
import os

In [3]:
import pickle
import bayes
import imtools

In [4]:
with open('points_normal.pkl', 'r') as f:
    class_1 = pickle.load(f)
    class_2 = pickle.load(f)
    labels = pickle.load(f)

bc = bayes.BayesClassifier()
bc.train([class_1, class_2], [1, -1])

with open('points_normal_test.pkl', 'r') as f:
    class_1 = pickle.load(f)
    class_2 = pickle.load(f)
    labels = pickle.load(f)

print bc.classify(class_1[:10])[0]
print bc.classify(class_2[:10])[0]

# draw points and boundary line
def classify(x, y, bc=bc):
    points = vstack((x, y))
    return bc.classify(points.T)[0]

imtools.plot_2D_boundary([-6, 6, -6, 6], [class_1, class_2], classify, [1, -1])
show()


[1 1 1 1 1 1 1 1 1 1]
[-1 -1 -1 -1 -1 -1 -1 -1 -1 -1]

In [5]:
with open('points_normal.pkl', 'r') as f:
    class_1 = pickle.load(f)
    class_2 = pickle.load(f)
    labels = pickle.load(f)

In [7]:
import heuristic
heuristic = reload(heuristic)
bc = heuristic.BayesClassifier()

In [8]:
bc.train([class_1, class_2], [1, -1])

In [9]:
with open('points_normal_test.pkl', 'r') as f:
    class_1 = pickle.load(f)
    class_2 = pickle.load(f)
    labels = pickle.load(f)

In [10]:
print bc.classify(class_1[:10])[0]
print bc.classify(class_2[:10])[0]


[1 1 1 1 1 1 1 1 1 1]
[-1 -1 -1 -1 -1 -1 -1 -1 -1 -1]

In [11]:
def classify(x, y, bc=bc):
    points = vstack((x, y))
    return bc.classify(points.T)[0]

imtools.plot_2D_boundary([-6, 6, -6, 6], [class_1, class_2], classify, [1, -1])
show()



In [12]:
with open('points_ring.pkl', 'r') as f:
    class_1 = pickle.load(f)
    class_2 = pickle.load(f)
    labels = pickle.load(f)

bc = bayes.BayesClassifier()
bc.train([class_1, class_2], [1, -1])

with open('points_ring_test.pkl', 'r') as f:
    class_1 = pickle.load(f)
    class_2 = pickle.load(f)
    labels = pickle.load(f)

def classify(x, y, bc=bc):
    points = vstack((x, y))
    return bc.classify(points.T)[0]

imtools.plot_2D_boundary([-6, 6, -6, 6], [class_1, class_2], classify, [1, -1])
show()



In [14]:
import heuristic
heuristic = reload(heuristic)

with open('points_ring.pkl', 'r') as f:
    class_1 = pickle.load(f)
    class_2 = pickle.load(f)
    labels = pickle.load(f)

bc = heuristic.BayesClassifier()
bc.train([class_1, class_2], [1, -1])

with open('points_ring_test.pkl', 'r') as f:
    class_1 = pickle.load(f)
    class_2 = pickle.load(f)
    labels = pickle.load(f)

def classify(x, y, bc=bc):
    points = vstack((x, y))
    return bc.classify(points.T)[0]

imtools.plot_2D_boundary([-6, 6, -6, 6], [class_1, class_2], classify, [1, -1])
show()



In [ ]: