机器学习-一对多(多分类)代码实现(matlab)
%% Machine Learning Online Class - Exercise 3 | Part 1: One-vs-all % Instructions
% ------------
%
% This file contains code that helps you get started on the
% linear exercise. You will need to complete the following functions
% in this exericse:
%
% lrCostFunction.m (logistic regression cost function)
% oneVsAll.m
% predictOneVsAll.m
% predict.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 %% Setup the parameters you will use for this part of the exercise
input_layer_size = 400; % 20x20 Input Images of Digits
num_labels = 10; % 10 labels, from 1 to 10
% (note that we have mapped "0" to label 10) %% =========== Part 1: Loading and Visualizing Data =============
% We start the exercise by first loading and visualizing the dataset.
% You will be working with a dataset that contains handwritten digits.
% % Load Training Data
fprintf('Loading and Visualizing Data ...\n') load('ex3data1.mat'); % training data stored in arrays X, y
m = size(X, 1);
size(X, ); X=* size(X, ) = 取行 size(X,) = 取列
解释
% Randomly select 100 data points to display
rand_indices = randperm(m);
sel = X(rand_indices(1:100), :); displayData(sel); fprintf('Program paused. Press enter to continue.\n');
pause; %% ============ Part 2: Vectorize Logistic Regression ============
% In this part of the exercise, you will reuse your logistic regression
% code from the last exercise. You task here is to make sure that your
% regularized logistic regression implementation is vectorized. After
% that, you will implement one-vs-all classification for the handwritten
% digit dataset.
% fprintf('\nTraining One-vs-All Logistic Regression...\n') lambda = 0.1;
[all_theta] = oneVsAll(X, y, num_labels, lambda); fprintf('Program paused. Press enter to continue.\n');
pause; %% ================ Part 3: Predict for One-Vs-All ================
% After ...
pred = predictOneVsAll(all_theta, X); fprintf('\nTraining Set Accuracy: %f\n', mean(double(pred == y)) * 100);
机器学习-一对多(多分类)代码实现(matlab)的更多相关文章
- 吴恩达机器学习笔记18-多类别分类:一对多(Multiclass Classification_ One-vs-all)
对于之前的一个,二元分类问题,我们的数据看起来可能是像这样: 对于一个多类分类问题,我们的数据集或许看起来像这样: 我用3 种不同的符号来代表3 个类别,问题就是给出3 个类型的数据集,我们如何得到一 ...
- [ZZ]计算机视觉、机器学习相关领域论文和源代码大集合
原文地址:[ZZ]计算机视觉.机器学习相关领域论文和源代码大集合作者:计算机视觉与模式 注:下面有project网站的大部分都有paper和相应的code.Code一般是C/C++或者Matlab代码 ...
- 【机器学习】--xgboost初始之代码实现分类
一.前述 上节我们讲解了xgboost的基本知识,本节我们通过实例进一步讲解. 二.具体 1.安装 默认可以通过pip安装,若是安装不上可以通过https://www.lfd.uci.edu/~goh ...
- 机器学习作业(三)多类别分类与神经网络——Matlab实现
题目太长了!下载地址[传送门] 第1题 简述:识别图片上的数字. 第1步:读取数据文件: %% Setup the parameters you will use for this part of t ...
- 【原】Spark之机器学习(Python版)(二)——分类
写这个系列是因为最近公司在搞技术分享,学习Spark,我的任务是讲PySpark的应用,因为我主要用Python,结合Spark,就讲PySpark了.然而我在学习的过程中发现,PySpark很鸡肋( ...
- 机器学习算法 - 最近邻规则分类KNN
上节介绍了机器学习的决策树算法,它属于分类算法,本节我们介绍机器学习的另外一种分类算法:最近邻规则分类KNN,书名为k-近邻算法. 它的工作原理是:将预测的目标数据分别跟样本进行比较,得到一组距离的数 ...
- 机器学习之KNN原理与代码实现
KNN原理与代码实现 本文系作者原创,转载请注明出处:https://www.cnblogs.com/further-further-further/p/9670187.html 1. KNN原理 K ...
- 机器学习之AdaBoost原理与代码实现
AdaBoost原理与代码实现 本文系作者原创,转载请注明出处: https://www.cnblogs.com/further-further-further/p/9642899.html 基本思路 ...
- 机器学习之支持向量机—SVM原理代码实现
支持向量机—SVM原理代码实现 本文系作者原创,转载请注明出处:https://www.cnblogs.com/further-further-further/p/9596898.html 1. 解决 ...
随机推荐
- NX二次开发-UFUN新建工程图UF_DRAW_create_drawing
NX9+VS2012 #include <uf.h> #include <uf_draw.h> #include <uf_part.h> UF_initialize ...
- jsonp的原理,应用场景,优缺点
在开发测试中,难免会在不同域下进行跨域操作,出于安全性考虑,浏览器中的同源策略阻止从一个域上加载的脚本获取或者操作 另一个域下的文档属性,这时需要进行跨域的方式进行解决,如:使用jsonp ,ifra ...
- python入门 元组tuple (三)
什么if while语句了 列表字典都太简单了 ,我直接跳过了, 开始写tuple了 增 元组格式是写在括号里,注意与列表(写在中括号里)的区别 tup1 = ('math', 'beijing', ...
- ionic-CSS:ionic tab(选项卡)
ylbtech-ionic-CSS:ionic tab(选项卡) 1.返回顶部 1. ionic tab(选项卡) ionic tab(选项卡) 是水平排列的按钮或者链接,用以页面间导航的切换.它可以 ...
- LeetCode 175. Combine Two Tables (组合两个表)
题目标签: 题目给了我们两个table,让我们合并,根据Person为主. 因为题目说了 提供person 信息,不管这个人有没有地址.所以这里用Left Join. Java Solution: R ...
- MDK(KEIL) 两步解决 中文乱码 及 中文光标 半个半个跳的问题
1. 如果已经用MDK(KEIL)的默认设置写了好多中文,那么先用notepad把文件一一打开然后转变编码格式为 utf-8 without ROM,如下: 2. 如果还没有开始编辑,或者已经用not ...
- i++ 和 ++i 的区别
先说运算规则吧. i++ 是先赋值后自增:++i 是先自增后赋值. 以下是代码示例: int a=0; int b=0; int i=0; a=i++; System.out.println(&quo ...
- 《DSP using MATLAB》Problem 8.44
代码: %% ------------------------------------------------------------------------ %% Output Info about ...
- java-day15
File类 文件和目录路径名的抽象表示,主要用于文件和目录的创建.查找和删除等操作 静态成员 static String pathSeparator 路径分隔符 File.pathSeparator ...
- 27-Ubuntu-远程管理命令-01-关机和重启
关机和重启--shutdown 注: 不指定选项和参数,默认表示1分钟之后关闭电脑 远程维护服务器时,最好不要关闭系统而应该重启 实例1:立刻关机 shutdown -h now 实例2:未带任何参数 ...