matlab(2) Logistic Regression: 画出样本数据点plotData
画出data数据
data数据
34.62365962451697,78.0246928153624,0
30.28671076822607,43.89499752400101,0
35.84740876993872,72.90219802708364,0
60.18259938620976,86.30855209546826,1
79.0327360507101,75.3443764369103,1
45.08327747668339,56.3163717815305,0
61.10666453684766,96.51142588489624,1
75.02474556738889,46.55401354116538,1
76.09878670226257,87.42056971926803,1
84.43281996120035,43.53339331072109,1
ex2.m文件
%% Initialization(灰色代表注释)
clear ; close all; clc (clear: Clear variables and functions from memory; close: close figure; clc: Clear command window.)
%% Load Data
% The first two columns contains the exam scores and the third column
% contains the label.
data = load('ex2data1.txt');
X = data(:, [1, 2]); y = data(:, 3); (取data的第一列至第二列给X,取data的第三列给y)
%% ==================== Part 1: Plotting ====================
% We start the exercise by first plotting the data to understand the
% the problem we are working with.
fprintf(['Plotting data with + indicating (y = 1) examples and o ' ... (...表示与下一行相连)
'indicating (y = 0) examples.\n']);
plotData(X, y); (调用函数plotData(X,y),参见下面的plotData.m)
% Put some labels
hold on; (保持住现有的plot和所有的坐标属性,包括颜色和线条的style)
% Labels and Legend
xlabel('Exam 1 score') (给x轴加上label)
ylabel('Exam 2 score') (给y轴加上label)
% Specified in plot order
legend('Admitted', 'Not admitted') (给两种不同的点的标记加说明)
hold off; (hold 关闭)
fprintf('\nProgram paused. Press enter to continue.\n');
pause; (暂停运行,等待用户响应pause causes a procedure to stop and wait for the user to strike any key before continue)
plotData.m文件
function plotData(X, y) (在文件的开头应写上新定义的function,文件的名称(plotData.m)中的plotData应与function的名称一至)
%PLOTDATA Plots the data points X and y into a new figure
% PLOTDATA(x,y) plots the data points with + for the positive examples
% and o for the negative examples. X is assumed to be a Mx2 matrix.
% Create New Figure
figure; hold on; (figure:创建一个figure 窗口)
% ====================== YOUR CODE HERE ======================
% Instructions: Plot the positive and negative examples on a
% 2D plot, using the option 'k+' for the positive
% examples and 'ko' for the negative examples.
%
% Find indices of positive and negative example
pos = find(y==1); neg = find(y==0); (返回所有y==1的点的线性序列(linear indices (如上述data则返回(4,5,7,8,9,10)))
%plot example
plot(X(pos,1), X(pos,2), 'k+', 'LineWidth', 2, 'MarkerSize', 7); (将相应序列对应的X矩阵的元素画出(如第4行的第一列的值做为x轴的值,第4行的第二列的值做为y轴的值); k+表示线的颜色为黑色(black),形状为+; MarkerSize 表示+形状的大小 )
plot(X(neg,1), X(neg,2), 'ko', 'MarkerFaceColor', 'y', 'MarkerSize', 7); (MarkerFaceColor: 表示填充在o里面的颜色为黄色)
% =========================================================================
hold off;
end (表示plotData(X, y)函数的结束)
matlab(2) Logistic Regression: 画出样本数据点plotData的更多相关文章
- matlab(3) Logistic Regression: 求cost 和gradient \ 求sigmoid的值
sigmoid.m文件 function g = sigmoid(z)%SIGMOID Compute sigmoid functoon% J = SIGMOID(z) computes the si ...
- matlab(4) Logistic regression:求θ的值使用fminunc / 画decision boundary(直线)plotDecisionBoundary
画decision boundary(直线) %% ============= Part 3: Optimizing using fminunc =============% In this exer ...
- MATLAB 统计数据并画出统计直方图
统计FilmTrust(0.5-4.0分).CiaoDVD(1-5分).MovieLens(1-5分) 等 rating 数据集分值的分布: 以 统计FilmTrust(0.5-4.0分) 为例: ...
- Stanford机器学习---第三讲. 逻辑回归和过拟合问题的解决 logistic Regression & Regularization
原文:http://blog.csdn.net/abcjennifer/article/details/7716281 本栏目(Machine learning)包括单参数的线性回归.多参数的线性回归 ...
- week3编程作业: Logistic Regression中一些难点的解读
%% ============ Part : Compute Cost and Gradient ============ % In this part of the exercise, you wi ...
- matlab(6) Regularized logistic regression : plot data(画样本图)
Regularized logistic regression : plot data(画样本图) ex2data2.txt 0.051267,0.69956,1-0.092742,0.68494, ...
- Matlab实现线性回归和逻辑回归: Linear Regression & Logistic Regression
原文:http://blog.csdn.net/abcjennifer/article/details/7732417 本文为Maching Learning 栏目补充内容,为上几章中所提到单参数线性 ...
- matlab(7) Regularized logistic regression : mapFeature(将feature增多) and costFunctionReg
Regularized logistic regression : mapFeature(将feature增多) and costFunctionReg ex2_reg.m文件中的部分内容 %% == ...
- matlab(8) Regularized logistic regression : 不同的λ(0,1,10,100)值对regularization的影响,对应不同的decision boundary\ 预测新的值和计算模型的精度predict.m
不同的λ(0,1,10,100)值对regularization的影响\ 预测新的值和计算模型的精度 %% ============= Part 2: Regularization and Accur ...
随机推荐
- python实践项目一:Collatz函数
要求1:编写一个名为 collatz()的函数,它有一个名为 number 的参数.如果参数是偶数,那么 collatz()就打印出 number // 2, 并返回该值.如果 number 是奇数, ...
- 传输json数据到前台的时候,数据中包含日期数据
问题描述 当从数据库中查询的数据中包含有日期格式的数据的时候,数据传输到前台会报错. 解决方式 // 逐条将日期进行格式化后再传输 Date date = new SimpleDateFormat(& ...
- CentOS下使用yum安装Apache极为方便,只需要在终端键入以下命令即可
CentOS下使用yum安装Apache极为方便,只需要在终端键入以下命令即可 1.安装Apache yum install httpd 2.设置服务器开机自动启动Apache systemctl e ...
- python 之 前端开发( DOM操作)
11.47 DOM操作 查找节点: 11.471 直接查找 document.getElementById //根据ID获取唯一一个标签 document.getElementsByClassName ...
- C#中使用XML存储数据
创建XML文档 首先引用System.Xml命名空间 1.初始化一个实例 XmlDocument xd = new XmlDocument(); 2.创建XML头文件声明 XmlDeclaration ...
- oracle随笔之提示“ORA-01002: 提取违反顺序”
如果存储过程中有插入语句并且没有写COMMIT的话在调试时会提示:“ORA-01002: 提取违反顺序”
- PB笔记之数据窗体分组合计列
- 手动编译ts的经过
动机 以前写ts或者es6,都是用在脚手架搭建的项目中,比如vue和react,当时当我识图写一个ts的demo的,我还要创建一个完整的vue或者react项目?明显不合适,那就要研究一下如何手动搭建 ...
- django类视图as_view()方法解析
使用视图函数时,django完成URL解析之后,会直接把request对象以及URL解析器捕获的参数(比如re_path中正则表达捕获的位置参数或关键字参数)丢给视图函数,但是在类视图中,这些参数不能 ...
- redis有序集合数据类型---sortedset
一.概述 redis有序集合和集合一样,也是string类型元素的集合,且不允许重复的成员. 不同的是每个元素都会关联一个double类型的分数. redis正式通过分数来为集合中的重圆进行从小到大的 ...