%% 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)的更多相关文章

  1. 吴恩达机器学习笔记18-多类别分类:一对多(Multiclass Classification_ One-vs-all)

    对于之前的一个,二元分类问题,我们的数据看起来可能是像这样: 对于一个多类分类问题,我们的数据集或许看起来像这样: 我用3 种不同的符号来代表3 个类别,问题就是给出3 个类型的数据集,我们如何得到一 ...

  2. [ZZ]计算机视觉、机器学习相关领域论文和源代码大集合

    原文地址:[ZZ]计算机视觉.机器学习相关领域论文和源代码大集合作者:计算机视觉与模式 注:下面有project网站的大部分都有paper和相应的code.Code一般是C/C++或者Matlab代码 ...

  3. 【机器学习】--xgboost初始之代码实现分类

    一.前述 上节我们讲解了xgboost的基本知识,本节我们通过实例进一步讲解. 二.具体 1.安装 默认可以通过pip安装,若是安装不上可以通过https://www.lfd.uci.edu/~goh ...

  4. 机器学习作业(三)多类别分类与神经网络——Matlab实现

    题目太长了!下载地址[传送门] 第1题 简述:识别图片上的数字. 第1步:读取数据文件: %% Setup the parameters you will use for this part of t ...

  5. 【原】Spark之机器学习(Python版)(二)——分类

    写这个系列是因为最近公司在搞技术分享,学习Spark,我的任务是讲PySpark的应用,因为我主要用Python,结合Spark,就讲PySpark了.然而我在学习的过程中发现,PySpark很鸡肋( ...

  6. 机器学习算法 - 最近邻规则分类KNN

    上节介绍了机器学习的决策树算法,它属于分类算法,本节我们介绍机器学习的另外一种分类算法:最近邻规则分类KNN,书名为k-近邻算法. 它的工作原理是:将预测的目标数据分别跟样本进行比较,得到一组距离的数 ...

  7. 机器学习之KNN原理与代码实现

    KNN原理与代码实现 本文系作者原创,转载请注明出处:https://www.cnblogs.com/further-further-further/p/9670187.html 1. KNN原理 K ...

  8. 机器学习之AdaBoost原理与代码实现

    AdaBoost原理与代码实现 本文系作者原创,转载请注明出处: https://www.cnblogs.com/further-further-further/p/9642899.html 基本思路 ...

  9. 机器学习之支持向量机—SVM原理代码实现

    支持向量机—SVM原理代码实现 本文系作者原创,转载请注明出处:https://www.cnblogs.com/further-further-further/p/9596898.html 1. 解决 ...

随机推荐

  1. OpenSceneGraph | OSG如何存储带纹理osgb格式可以节省空间

      在使用OSG(OpenSceneGraph)存储带纹理osgb格式的过程中,大家会遇到这样一种情况:存储后的osgb文件所占用的大小远大于原始文件的大小,几倍至几十倍.这是为何呢?原因是OSG默认 ...

  2. 使用RAS+AES对接口数据加解密

    在实际开发中,会遇到两个系统之间传输数据,为了对传输的数据进行保护,需要发送方对接口数据进行加密,接收方对数据解密. 对数据加密,采用RSA+AES双重加密,是数据更加安全. 使用前提: 如果客户端本 ...

  3. 转-pycharm建立项目

    转自:https://blog.csdn.net/m0_37544464/article/details/79171913 本文针对环境已经配置好的Pycharm建立新项目 1.第一步 2.第二步 在 ...

  4. c# ToString()格式大全(转)

    stringstr1 =string.Format("{0:N1}",56789);               //result: 56,789.0stringstr2 =str ...

  5. Python3 From Zero——{最初的意识:000~Initial consciousness}

    http://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000 a.编码 默认情况下,Python ...

  6. socket的多线程实现

    步骤: 1.服务端创建ServerSocket,循环调用accept()等待客户端连接: 2.客户端创建socket并请求与服务端对话: 3.服务端接收客户端的请求,创建socket与客户端进行专线连 ...

  7. python中oop

    转自  http://www.cnblogs.com/BeginMan/p/3510786.html 本文旨在Python复习和总结: 1.如何创建类和实例? # 创建类 class ClassNam ...

  8. Landsat数据下载与介绍

    1 数据下载 根据时间选择不同的Landsat卫星传感器 根据经纬度选择对应的条带: Lansdat Analysis Ready Data (ARD) Tile Conversion Tool: 把 ...

  9. 哈理工赛 H-小乐乐学数学 /// 筛法得素数表+树状数组

    题目大意: 给定n个数 m个询问 询问l r区间内的孤独数的个数 孤独数的定义为在该区间内与其他所有数互质的数 看注释 #include <bits/stdc++.h> using nam ...

  10. OpenCV3 VideoCapture buffer

    在ubuntu16.04下写关于opencv的工程,在调用摄像头时发现VideoCapture有5帧的buffer,所以采用5个capture>>mat来处理. if (FlagConti ...