Machine Learning 5 Basic Operations

Machine Learning 5 Basic Operations

5-4 Plotting data

  • T = [0:0.1:1]
  • Y1 = sin(2*pi*4*t)
  • Plot(t,y1) //绘图程序
  • Hold on 在原图基础上绘制
  • Xlabel(‘time’)
  • Ylabel(‘value’)
  • Legend(‘sin’,’cos’) 为线进行标注
  • Title(‘my plot’) 标题
  • Print -dpng ‘myplot.png’ 保存
  • Close 关闭图像
  • Figure(1); plot(t,y1);
  • Figute(2);plot(t,y2);
  • Subplot(1,2,1); %Divides plot a 1x2 grid
  • Axis([0.5 1 -1 1])
  • Clf 干掉所有的图片
  • Imagesc(A) 可视化矩阵
  • Imagesc(A), colorbar, colormap gray; 为图片添加bar,设置颜色为灰色

5-5 Control Statements for, while, if statements

语法上不对缩进有要求

  • for
for i = 1:10,
    v(i) =  2^i;
    end;
indices = 1:10;
for i = indices.
    disp(i);
end;
  • while
while i <= 5,
    v(i) = 100;
    i = i+1;
end;
  • break
while true,
    v(i) = 999;
    i = i + 1;
    if(i == 6),
        break;
    end;
end;
  • if else
if v(1) == 1,
    disp('The value is one');
    elseif v(1) == 2,
        disp('The value is two');
    else
        disp('end');
end;
  • exit/quit 退出octave
  • function 使用时,要把函数放在当前空间
function y = squareThisNumber(x)
y = x^2;
function [y1, y2] = squareAndCubeThisNumber(x); % 返回多个值
y1 = x^2;
y2 = x^3;
function J = costFunctionJ(X, y, theta)
% X is the "design matrix" containing our training examples.
% y i the class labels
m = size(X, 1); % number of training examples
predictions = X*theta; % predictions of hypothesis on all m examples
sqrErrors = (predictions - y).^2; % squared errors

J = 1/(2*m) * sum(sqrErrors);
  • addpath 添加搜索路径
addpath('C:\users\ang\Desktop')

Vectorization

  • 向量化可以降低计算时间,提升编程效率

Working on and submitting programming exercises

cd '作业所在目录'
submit()
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值