2015-09-25 96 views
1

为Andrew Ng的Cousera课程“机器学习”我开始使用OctaveOctave绘图一步一步(!)一个成本函数和梯度下降

有关线性回归的分配被提供(一个变量)代码创建该原始数据与拟合线的散点图,弓形成本函数J(theta_0, theta_1)和的等高线图。

但是:所有这些图只提供最终结果。

我希望看到一步一步的情节发展,以更好地了解发生了什么事情。一步一步的意思是:创建一个数字,添加第一个值,然后第二个,然后第三个等,直到到达最终结果。

(1)从一个演讲视频截图:是否有可能可视化这个,添加粉红色然后是绿色,然后红色等点?

Screenshot from one lecture video: Is it possible to visualise this, i.e. adding the pink, then the green dot, then red dot, etc dot?

(2.1)中搜索正确的参数,梯度下降步骤1

(2.2)中搜索正确的参数,梯度下降最终步骤第一步:所有单步骤是否包括

(2) First step in searching for the correct parameters, i.e. gradient Descent Step 1

enter image description here

注意1:有关屏幕截图散点图+等高线图:在散点图中总是显示一行,但它逐步改变。在等高线图中出现一个点。

注2:这不是转让请求! 我只想学习在Octave中绘图,并希望将它与学习梯度下降如何“真正”起作用。

非常感谢所有提供一些代码帮助的人!

+0

你提到倍频很多 - 但标签问题'matplotlib',这是一个Python库(用于绘图)。如果你确实是指Octave,你应该将问题重新标记为八度并删除matplotlib –

+0

是的,** Andrew是这个ML课程的优秀讲师**。享受车程!使用Octave,检查MATLAB的所有绘图教程,这些将帮助您向前推进。 – user3666197

+0

啊...抱歉错了标签 - 我确实是指octacve。 – user2006697

回答

2

使用hold all(或只是hold on,但颜色增量将不会自动) ColorOrder是轴属性,可以进行默认用于随后的图中的轴,如部分地描述here

# start with a blank page 
clf 

# the curve (full line, blue) 
x = -5:0.1:10; 
y = x.^2; 
plot(x, y, '-b') 

# successive colors for the points 
N_colors = 6; 
colororder_map = cool(N_colors); 
set(gcf, 'defaultaxesColorOrder', colororder_map) 

# this will add the following plots, instead of replacing the old one 
hold all 
# note: "hold on" does the same, except the colors are not incremented 

# the progression 
x_p = [10, 7, 3, 1, 0]; 
y_p = x_p .^2; 

# plot the progression 
for cpt = 1:numel(x_p) 
    x_current = x_p(cpt); 
    y_current = y_p(cpt); 
    plot(x_current, y_current, 'o') 
    pause 
endfor 

sample plot

+0

对不起,迟到了,我生病了。将尝试你的代码 - 感谢一百万! – user2006697

+0

您使用的是什么版本的Octave?我无法使用https://saturnapi.com/fullstack/plotting-a-cost-function – FullStack

+1

@FullStack该脚本在八度3.8.2和4.0.0下运行良好,均使用本机图形或gnuplot。但是这是'saturnapi'命令产生的失败。只是注释掉'暂停',图表显示正常。 – ederag