[英]plot a decision curve for logistic regression with gaussian Kernel
我嘗試將Logistic回歸與多項式特征一起使用,幸運的是,它對我來說工作正常,而且我能夠繪制決策曲線。 我已將map_feature函數用於多項式特征。 (我引用了安德魯教授關於帶正則化的邏輯回歸的注釋): http : //openclassroom.stanford.edu/MainFolder/DocumentPage.php?course=MachineLearning&doc=exercises/ex5/ex5.html
現在,我試圖使用高斯核而不是采用多項式特征來實現相同的目標。 幸運的是,我的成本函數(j_theta)可以正常工作,並且在每次迭代后都會減少,我得到了最終的theta值。 我現在面臨的問題是如何在此處繪制決策邊界
I am using Octave to develop the algorithms and plot the graphs..
以下是我的數據集大小的詳細信息
原始數據集:
Data Set (x): [20*3] where the first column is the intercept or the bias column
1.00 2.0000 1.0000
1.00 3.0000 1.0000
1.00 4.0000 1.0000
1.00 5.0000 2.0000
1.00 5.0000 3.0000
.
.
.
實施高斯內核后具有新功能的數據集
Data set (f) : [20*21] the first column is the intercept column with all values as 1
1.0000e+000 1.0000e+000 6.0653e-001 1.3534e-001 6.7379e-003 . . . . . . . .
1.0000e+000 6.0653e-001 1.0000e+000 6.0653e-001 8.2085e-002 . . . . . . . .
1.0000e+000 1.3534e-001 6.0653e-001 1.0000e+000 3.6788e-001
1.0000e+000 6.7379e-003 8.2085e-002 3.6788e-001 1.0000e+000
. .
. .
. .
. .
. .
在對新的特征數據集(f)應用梯度下降后獲得的成本函數圖為:
因此,我得到了新的theta值:
theta: [21*1]
3.8874e+000
1.1747e-001
3.5931e-002
-8.5937e-005
-1.2666e-001
-1.0584e-001
.
.
.
我現在面臨的問題是如何在具有新要素數據集和theta值的原始數據集上構建決策曲線。 我不知道如何進行。
如果能獲得一些可以幫助我解決問題的線索,教程或鏈接,我將感到非常高興。
感謝您的幫助。 謝謝
引用的安德魯筆記實際上包含了一個很好的示例,說明了如何划定決策邊界。 另請參閱此 stackoverflow帖子。 遵循的基本步驟如下:
X
的范圍選擇分辨率。 Z
變量(輪廓圖上的高度),繪制輪廓曲線。 在下面的示例代碼中,我們假設2d特征空間的范圍為-1至200。我們選擇步長為1.5,然后對於網格中的每個點,我們將其稱為模型predictor
map_feature(u,v) x theta
來獲得分數。 最后,通過在Matlab中調用contour
函數來繪制圖。
在這里繪制決策邊界比在線性回歸中繪制最佳擬合曲線要復雜得多。 您將需要通過繪制輪廓線來隱式繪制$ \\ theta ^ T x = 0 $線。 這可以通過在代表原始$ u $和$ v $輸入的點網格上評估$ \\ theta ^ Tx $,然后繪制$ \\ theta ^ Tx $計算為零的線來完成。 下面給出了Matlab / Octave的繪圖實現。
% Define the ranges of the grid
u = linspace(-1, 1.5, 200);
v = linspace(-1, 1.5, 200);
% Initialize space for the values to be plotted
z = zeros(length(u), length(v));
% Evaluate z = theta*x over the grid
for i = 1:length(u)
for j = 1:length(v)
% Notice the order of j, i here!
z(j,i) = map_feature(u(i), v(j))*theta;
end
end
% Because of the way that contour plotting works
% in Matlab, we need to transpose z, or
% else the axis orientation will be flipped!
z = z'
% Plot z = 0 by specifying the range [0, 0]
contour(u,v,z, [0, 0], 'LineWidth', 2)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.