Skip to content
Snippets Groups Projects
Commit 3ef4274a authored by Fabian Pedregosa's avatar Fabian Pedregosa
Browse files

Add another svm example.

This time with nonseparable data.

From: Fabian Pedregosa <fabian.pedregosa@inria.fr>

git-svn-id: https://scikit-learn.svn.sourceforge.net/svnroot/scikit-learn/trunk@560 22fbfee3-77ab-4535-9bad-27d1bd3bc7d8
parent 7dc5f077
No related branches found
No related tags found
No related merge requests found
import numpy as np
import pylab as pl
from scikits.learn import svm
xx, yy = np.meshgrid(np.linspace(-5, 5), np.linspace(-5, 5))
X = np.random.randn(300, 2)
Y = np.logical_xor(X[:,0]>0, X[:,1]>0)
# fit the model
clf = svm.SVC(impl='nu_svc', kernel='rbf', C=100)
clf.fit(X, Y)
# plot the line, the points, and the nearest vectors to the plane
Z = clf.predict(np.c_[xx.ravel(), yy.ravel()])
Z = Z.reshape(xx.shape)
pl.set_cmap(pl.cm.Paired)
pl.pcolormesh(xx, yy, Z)
pl.scatter(X[:,0], X[:,1], c=Y)
pl.axis('tight')
pl.show()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment