2013-09-27 143 views
1

我很新的matplotlib和我工作的簡單的項目來熟悉它。我想知道我怎麼可能畫出決策邊界是形式的權值矢量W1,W2],基本上分開的兩個班可以說,C1和C2,使用matplotlib。情節決策邊界matplotlib

如果從(0,0)到點(w1,w2)(因爲W是「矢量」的權重)繪製一條線就很簡單,如果是這樣,如果我在兩個方向上如何擴展它需要?

現在所有我做的是:提前

import matplotlib.pyplot as plt 
    plt.plot([0,w1],[0,w2]) 
    plt.show() 

感謝。

回答

12

決策邊界一般是更復雜的,不只是一個線等(在2D維的情況),最好是使用一般的情況下,代碼,這也將很好地線性分類器工作。最簡單的想法是繪製決策功能

# X - some data in 2dimensional np.array 

x_min, x_max = X[:, 0].min() - 1, X[:, 0].max() + 1 
y_min, y_max = X[:, 1].min() - 1, X[:, 1].max() + 1 
xx, yy = np.meshgrid(np.arange(x_min, x_max, h), 
        np.arange(y_min, y_max, h)) 

# here "model" is your model's prediction (classification) function 
Z = model(np.c_[xx.ravel(), yy.ravel()]) 

# Put the result into a color plot 
Z = Z.reshape(xx.shape) 
plt.contourf(xx, yy, Z, cmap=pl.cm.Paired) 
plt.axis('off') 

# Plot also the training points 
plt.scatter(X[:, 0], X[:, 1], c=Y, cmap=pl.cm.Paired) 

一些例子的等高線圖,從sklearn文檔

enter image description here

+0

所以這裏ž將是導致權重向量? – anonuser0428

+0

沒有,'Z'是分類的矩陣,如果神經網絡只包含兩個權重(沒有偏置)'Z(X,Y)= SGN(W1 * X + W2 * Y)' – lejlot

+0

,從而在這種情況下在將參數傳遞給我的模型的行上,我實際上會傳遞我正在分析的數據?還是應該已經對我的分類器進行了培訓,然後傳遞了這些數據? – anonuser0428