**NOTE : The variable x contains 30 tuples of feature vector of 5 dimension. These values of x are transferred to x_train.x can be imagined to be the form of x = [[1.0 , 2.0 , 3,0 , 4.0 , 5.0 ], [11.0 , 12.0 , 13.0 , 14.0 , 15.0], [21.0 , 22.0 , 23.0 , 24.0 , 25,0], .. .. ..] and y = labels =[1,1,1 , 2,2,2 , 3,3,3...] I wish to apply PCA on x and reduce to two dimensions and then plot decision boundaries. I am able to plot the points but unable to plot to decision boundary **
x_train = x
y_train =labels
pca = PCA(n_components=2).fit(x_train)
pca_2d = pca.transform(x_train)
clf = svm.SVC(kernel='linear',C = 3)
clf.fit(pca_2d, y_train)
for i in range(1, pca_2d.shape[0]):
if y_train[i] == 1:
c1 = pl.scatter(pca_2d[i,0],pca_2d[i,1],c='r', s=50,marker='+')
elif y_train[i] == 2:
c2 = pl.scatter(pca_2d[i,0],pca_2d[i,1],c='r', s=50,marker='.')
elif y_train[i] == 3:
c3 = pl.scatter(pca_2d[i,0],pca_2d[i,1],c='r', s=50,marker=',')
elif y_train[i] == 4:
c4 = pl.scatter(pca_2d[i,0],pca_2d[i,1],c='r', s=50,marker='^')
elif y_train[i] == 5:
c5 = pl.scatter(pca_2d[i,0],pca_2d[i,1],c='r', s=50,marker='v')
elif y_train[i] == 6:
x_min, x_max = pca_2d[:, 0].min() - 1, pca_2d[:,0].max() + 1
y_min, y_max = pca_2d[:, 1].min() - 1, pca_2d[:, 1].max() + 1
xx, yy = np.meshgrid(np.arange(x_min, x_max, .01),np.arange(y_min,y_max, .01))
#************ ERROR ******#
Z = clf.predict(np.c_[xx.ravel(), yy.ravel()])
#************ ERROR ******#
Z = Z.reshape(xx.shape)
plt.contourf(xx, yy, Z, cmap=plt.cm.Paired, alpha=0.8)
pl.title('Support Vector Machine Decision Surface')
pl.axis('off')
pl.show()
## The error shown is :
Traceback (most recent call last):
File "D:\New folder_previous.2 - Copy.right\main_pos.py", line 354, in <module>
Z = clf.predict(np.c_[xx.ravel(), yy.ravel()])
File "C:\Python27\lib\site-packages\numpy\lib\index_tricks.py", line 338, in __getitem__
res = _nx.concatenate(tuple(objs), axis=self.axis)
MemoryError