Support Vector Machine classification example


In [ ]:
training_data = [[1,1],[2,2],[3,3],[4,4]]
labels = ['a','b','c','d']

from sklearn import svm
svc = svm.SVC()
svc.fit(X, labels)

In [ ]:
svc.predict([[2.1, 2.5]])

In [ ]:
svc.predict([[0.5, 1.4]])

Gaussian Naive Bayes example


In [ ]:
from sklearn.naive_bayes import GaussianNB
gnb = GaussianNB()

In [ ]:
from pandas import DataFrame

labels = ["hot", "warm", "cool", "cold"] * 25
random.shuffle(labels)

#Generate random points
N = 100
data = DataFrame(np.random.randint(0, 100, size=(N, 2)), columns = ["x", "y"], index = labels)

In [ ]:
gnb = GaussianNB()
gnb.fit(data,labels)

In [ ]:
test_point = DataFrame({"x": [15], "y": [30]})
gnb.predict(test_point)

Compare SVM vs GNB


In [ ]:
svc.fit(data,labels)

In [ ]:
svc.predict(test_point)

In [ ]: