** HINWEIS: Die Variable x enthält 30 Tupel des Merkmalsvektors von 5 Dimension. Diese Werte von x werden an x_train übergeben. X kann als die Form von 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], .. .. ..] und y = labels = [1,1,1, 2,2,2, 3,3,3 ...] Ich möchte PCA anwenden auf x und auf zwei Dimensionen reduzieren und dann Entscheidungsgrenzen plotten. Ich bin in der Lage, die Punkte zu zeichnen, aber nicht in der Lage zu Entscheidungsgrenze plotten **Hier ist der Code zur Visualisierung der SVM-Entscheidungsgrenze. Ich kann den Fehler nicht erkennen. Bitte werfen Sie einen Blick auf
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
Hilft das? https://docs.python.org/2/library/exceptions.html#exceptions.MemoryError – cel