Regularized logistic regression :  plot data(画样本图)

ex2data2.txt

0.051267,0.69956,1
-0.092742,0.68494,1
-0.21371,0.69225,1
-0.375,0.50219,1
-0.51325,0.46564,1
-0.52477,0.2098,1
-0.39804,0.034357,1
-0.30588,-0.19225,1
0.016705,-0.40424,1
0.13191,-0.51389,1
0.38537,-0.56506,1
...........................

ex2_reg.m

%% Machine Learning Online Class - Exercise 2: Logistic Regression
%
% Instructions
% ------------
%
% This file contains code that helps you get started on the second part
% of the exercise which covers regularization with logistic regression.
%
% You will need to complete the following functions in this exericse:
%
% sigmoid.m
% costFunction.m
% predict.m
% costFunctionReg.m
%
% For this exercise, you will not need to change any code in this file,
% or any other files other than those mentioned above.
%

%% 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 X values and the third column
% contains the label (y).

data = load('ex2data2.txt');
X = data(:, [1, 2]); y = data(:, 3);

plotData(X, y);   %调用下面的plotData.m里面的函数plotData(X,y)

% Put some labels
hold on;

% Labels and Legend
xlabel('Microchip Test 1')
ylabel('Microchip Test 2')

% Specified in plot order
legend('y = 1', 'y = 0')
hold off;

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则返回(1,2,3,4,5,6...)))

%plot example
plot(X(pos,1), X(pos,2), 'k+', 'LineWidth', 2, 'MarkerSize', 7); (将相应序列对应的X矩阵的元素画出(如第4行的第一列的值做为x轴的值,第4行的第二列的值做为y轴的值);  k+表示线的颜色为黑色,形状为+; MarkerSize 表示+形状的大小 )
plot(X(neg,1), X(neg,2), 'ko', 'MarkerFaceColor', 'y', 'MarkerSize', 7); (MarkerFaceColor: 表示填充在o里面的颜色为黄色)

% =========================================================================  

hold off;

end  (表示plotData(X, y)函数的结束)

最新文章

  1. gzip的使用
  2. requirejs(一)
  3. Microsoft Word 段前距设置和页眉设置
  4. sql 如果关联表 没有值 设置 默认值
  5. 【bzoj3991】 寻宝游戏
  6. Java开发环境的搭建
  7. 设置button不同状态下的背景色,即把这个颜色变成图片设置成,背景图片
  8. 设计模式-原型模式(Prototype)
  9. qt http 下载文件
  10. 一步步学习Python-django开发-Mac下搭建Python-Django环境
  11. THINKCMF-NGINX伪静态
  12. docker registry私有仓库部署
  13. jerasure 2.0译文
  14. 第九节:深究并行编程Parallel类中的三大方法 (For、ForEach、Invoke)和几大编程模型(SPM、APM、EAP、TAP)
  15. sqlserver存储过程的使用
  16. js长整型的失真问题解决
  17. python实现http get请求
  18. Servlet线程安全性
  19. 谷歌浏览器怎么调试js 谷歌浏览器调试javascript教程
  20. spring+mybatis 多数据源切换

热门文章

  1. ACL 实验
  2. LeetCode 172. 阶乘后的零(Factorial Trailing Zeroes)
  3. 037 Android Glide图片加载开源框架使用
  4. apache 代理配置
  5. [WCF] - Odata Service 访问失败,查看具体错误信息的方法
  6. TypeScript TSLint(TypeScript代码检查工具)
  7. java8 time包的简单使用
  8. django使用pyecharts(2)----django加入echarts_前后台分离
  9. Python re模块前的正则表达式常用语法小总结
  10. jdk 8 特性