Plotting decision boundary for 3 classes [scikit learn python]

Viewed 856

I'm generating a classifier using scikit learn SVM in python that has 3 classes. I'm experimenting with sample weights so I would like to see the decision boundaries for these 3 classes.

This is what I have so far:

xx, yy = np.meshgrid(np.linspace(-4, 5, 200), np.linspace(-4, 5, 200))
zz, ww = np.meshgrid(np.linspace(-4, 5, 200), np.linspace(-4, 5, 200))
Z = clf.decision_function(np.c_[xx.ravel(), yy.ravel(), zz.ravel()])
Z

Out[0]:

array([[ 2.73029999, -0.95642619, -4.45127469],
       [ 2.76214465, -0.88802893, -4.39607632],
       [ 2.7930567 , -0.8203471 , -4.34072817],
       ..., 
       [-7.74579688, -9.31664158, -5.69664505],
       [-7.77555883, -9.37782922, -5.76493058],
       [-7.80441264, -9.43809765, -5.83257034]])

Usually for 2 classes I would do this next:

Z = Z.reshape(xx.shape) #This is where it throws an error if I attempt the 3 class approach 
axis.contourf(xx, yy, Z, alpha=0.75, cmap=plt.cm.seismic)
axis.scatter(X[:, 0], X[:, 1], c=Y, s=10 * sample_weight, alpha=0.9,cmap=plt.cm.seismic)

My training set has 3 variables for classification and 3 classes. Is it also possible (or only possible) to plot this in a 3d plot similar to matplotlib's 3dcontour?

Super-duper thanks to anyone that helps me out

0 Answers
Related