Digit Recognizer

手写体数字识别  MNIST数据集

本赛 train 42000样例 test 28000样例,原始MNIST是 train 60000 test 10000

我分别用 Logistic Regression/ 784-200-200-10的Sparse AutoEncoder/Convolution AutoEncoder刷了下

===============方法一、 One-Vs-All 的Logistic Regression===================

%%
ccc
load digitData %%
input_layer_size = 28*28;
num_ys = 10; X = train_x;
[~,y] = max(train_y, [], 2); lambda = 0.1;
lambda = 100;
[all_theta] = oneVsAll(X, y, num_ys, lambda); %% ================ Part: Predict for One-Vs-All ================
% After ...
pred = predictOneVsAll(all_theta, X);
fprintf('\nTraining Set Accuracy: %f\n', mean(double(pred == y)) * 100); %% ============== 计算test准确度(test_y 是基于KNN的 只作为参考)
[~,test_y] = max(test_y, [], 2); pred = predictOneVsAll(all_theta, test_x);
fprintf('\nTest Set Accuracy: %f\n', mean(double(pred == test_y)) * 100); %% write csv file
pred(pred==10) = 0;
M = [(1:length(pred))' pred(:)];
csvwrite('LiFeiteng0824.csv',M)

===============方法二、 784-200-200-10的Sparse AutoEncoder ===================

%% STEP 0: Here we provide the relevant parameters values that will
tic inputDim = 28;
inputSize = 28 * 28;
numClasses = 10;
hiddenSizeL1 = 200; % Layer 1 Hidden Size
hiddenSizeL2 = 200; % Layer 2 Hidden Size
sparsityParam = 0.1; % desired average activation of the hidden units.
% (This was denoted by the Greek alphabet rho, which looks like a lower-case "p",
% in the lecture notes).
lambda = 3e-3; % weight decay parameter
beta = 3; % weight of sparsity penalty term
maxIter = 100; %% STEP 1: Load data
load digitData
trainData = train_x';
[~, trainLabels] = max(train_y, [], 2);
%%% 增加数据 %%% ZCA白化 像素值范围变化 []
% trainData = ZCAWhite(trainData); %% STEP 2: Train the first sparse autoencoder
sae1Theta = initializeParameters(hiddenSizeL1, inputSize); options.Method = 'lbfgs';
options.maxIter = 200; % Maximum number of iterations of L-BFGS to run
options.display = 'on';
[sae1OptTheta, cost] = minFunc( @(p) sparseAutoencoderCost(p, ...
inputSize, hiddenSizeL1, ...
lambda, sparsityParam, ...
beta, trainData), ...
sae1Theta, options); % -------------------------------------------------------------------------
W1 = reshape(sae1OptTheta(1:hiddenSizeL1*inputSize), hiddenSizeL1, inputSize);
display_network(W1', 12); %% STEP 2: Train the second sparse autoencoder
[sae1Features] = feedForwardAutoencoder(sae1OptTheta, hiddenSizeL1, ...
inputSize, trainData); % Randomly initialize the parameters
sae2Theta = initializeParameters(hiddenSizeL2, hiddenSizeL1); options.Method = 'lbfgs';
options.maxIter = 100; % Maximum number of iterations of L-BFGS to run
options.display = 'on'; [sae2OptTheta, cost] = minFunc( @(p) sparseAutoencoderCost(p, ...
size(sae1Features,1), hiddenSizeL2, ...
lambda, sparsityParam, ...
beta, sae1Features), ...
sae2Theta, options); %% STEP 3: Train the softmax classifier [sae2Features] = feedForwardAutoencoder(sae2OptTheta, hiddenSizeL2, ...
hiddenSizeL1, sae1Features); % Randomly initialize the parameters
saeSoftmaxTheta = 0.005 * randn(hiddenSizeL2 * numClasses, 1); lambda = 1e-4;
options.maxIter = 200;
softmaxModel = softmaxTrain(hiddenSizeL2, numClasses, lambda, ...
sae2Features, trainLabels, options);
% -------------------------------------------------------------------------
saeSoftmaxOptTheta = softmaxModel.optTheta(:); %% STEP 5: Finetune softmax model % Implement the stackedAECost to give the combined cost of the whole model
% then run this cell. % Initialize the stack using the parameters learned
stack = cell(2,1);
stack{1}.w = reshape(sae1OptTheta(1:hiddenSizeL1*inputSize), ...
hiddenSizeL1, inputSize);
stack{1}.b = sae1OptTheta(2*hiddenSizeL1*inputSize+1:2*hiddenSizeL1*inputSize+hiddenSizeL1);
stack{2}.w = reshape(sae2OptTheta(1:hiddenSizeL2*hiddenSizeL1), ...
hiddenSizeL2, hiddenSizeL1);
stack{2}.b = sae2OptTheta(2*hiddenSizeL2*hiddenSizeL1+1:2*hiddenSizeL2*hiddenSizeL1+hiddenSizeL2); % Initialize the parameters for the deep model
[stackparams, netconfig] = stack2params(stack);
stackedAETheta = [ saeSoftmaxOptTheta ; stackparams ]; options.Method = 'lbfgs';
options.maxIter = 400; % Maximum number of iterations of L-BFGS to run
options.display = 'on'; [stackedAEOptTheta, cost] = minFunc( @(p) stackedAECost(p, ...
hiddenSizeL2 , hiddenSizeL2, ...
numClasses, netconfig, ...
lambda, trainData, trainLabels), ...
stackedAETheta, options); % ------------------------------------------------------------------------- %% STEP 6: Test
% Instructions: You will need to complete the code in stackedAEPredict.m
% before running this part of the code
% testData = test_x';
[~, testLabels] = max(test_y, [], 2); [pred] = stackedAEPredict(stackedAETheta, inputSize, hiddenSizeL2, ...
numClasses, netconfig, testData); acc = mean(testLabels(:) == pred(:));
fprintf('Before Finetuning Test Accuracy: %0.3f%%\n', acc * 100); [pred] = stackedAEPredict(stackedAEOptTheta, inputSize, hiddenSizeL2, ...
numClasses, netconfig, testData); acc = mean(testLabels(:) == pred(:));
fprintf('After Finetuning Test Accuracy: %0.3f%%\n', acc * 100);
toc pred(pred==10) = 0;
tmp = [(1:length(pred))' pred(:)];
csvwrite('LiFeiteng0824.csv',tmp)

test准确率 基于Knn的pred-label

===============方法三、 784-200-200-10的Sparse AutoEncoder ===================

使用DeepLearnToolbox

%%
clear
close all
clc %% load data label
load digitData %%% pre-processing
%% ex2 train a X-X hidden unit SDAE and use it to initialize a FFNN
% Setup and train a stacked denoising autoencoder (SDAE)
rng(0);
nDim = [784 200 200];
sae = saesetup(nDim);
sae.ae{1}.activation_function = 'sigm';
sae.ae{1}.learningRate = 1;
sae.ae{1}.inputZeroMaskedFraction = 0.5; sae.ae{2}.activation_function = 'sigm';
sae.ae{2}.learningRate = 1;
sae.ae{2}.inputZeroMaskedFraction = 0.5; % sae.ae{3}.activation_function = 'sigm';
% sae.ae{3}.learningRate = 0.8;
% sae.ae{3}.inputZeroMaskedFraction = 0.5; opts.numepochs = 30;
opts.batchsize = 100;
% opts.sparsityTarget = 0.05;%$LiFeiteng
% opts.nonSparsityPenalty = 1;
opts.dropoutFraction = 0.5; sae = saetrain(sae, train_x, opts);
visualize(sae.ae{1}.W{1}(:,2:end)') %% Use the SDAE to initialize a FFNN
nn = nnsetup([nDim 10]);
nn.activation_function = 'sigm';%'sigm';
nn.learningRate = 1; %add pretrained weights
nn.W{1} = sae.ae{1}.W{1};
nn.W{2} = sae.ae{2}.W{1};
%nn.W{3} = sae.ae{3}.W{1}; % Train the FFNN
fprintf('\n')
opts.numepochs = 40;
opts.batchsize = 100;
nn = nntrain(nn, train_x, train_y, opts); %% test
[er, bad, pred] = nntest(nn, test_x, test_y); pred(pred==10) = 0;
tmp = [(1:length(pred))' pred(:)];
csvwrite('LiFeiteng0824.csv',tmp)

start of the art!

==================================================================

排名200多好伤感!!!

Leaderboard上好多100%的,其实我也可以做到——作弊——把错误的部分 逐一用肉眼扫下,更改test_label就可,不过这就没意思了。

Y. LeCun 维护的

THE MNIST DATABASE

最好成绩:

==============================

可以提高准确率的方法:

1.增加train的个数,对增加原始图像 平移 旋转等构造新图像;

2.对图像做预处理等;直接用PCA or ZCA白化 会改变像素值范围;

3.卷积-池化等加入Deep Networks中去;

4.New Model。。。

Kaggle—Digit Recognizer竞赛的更多相关文章

  1. kaggle实战记录 =>Digit Recognizer

    date:2016-09-13 今天开始注册了kaggle,从digit recognizer开始学习, 由于是第一个案例对于整个流程目前我还不够了解,首先了解大神是怎么运行怎么构思,然后模仿.这样的 ...

  2. Kaggle大数据竞赛平台入门

    Kaggle大数据竞赛平台入门 大数据竞赛平台,国内主要是天池大数据竞赛和DataCastle,国外主要就是Kaggle.Kaggle是一个数据挖掘的竞赛平台,网站为:https://www.kagg ...

  3. Kiggle:Digit Recognizer

    题目链接:Kiggle:Digit Recognizer Each image is 28 pixels in height and 28 pixels in width, for a total o ...

  4. DeepLearning to digit recognizer in kaggle

    DeepLearning to digit recongnizer in kaggle 近期在看deeplearning,于是就找了kaggle上字符识别进行练习.这里我主要用两种工具箱进行求解.并比 ...

  5. Kaggle入门(一)——Digit Recognizer

    目录 0 前言 1 简介 2 数据准备 2.1 导入数据 2.2 检查空值 2.3 正则化 Normalization 2.4 更改数据维度 Reshape 2.5 标签编码 2.6 分割交叉验证集 ...

  6. Kaggle 项目之 Digit Recognizer

    train.csv 和 test.csv 包含 1~9 的手写数字的灰度图片.每幅图片都是 28 个像素的高度和宽度,共 28*28=784 个像素点,每个像素值都在 0~255 之间. train. ...

  7. kaggle赛题Digit Recognizer:利用TensorFlow搭建神经网络(附上K邻近算法模型预测)

    一.前言 kaggle上有传统的手写数字识别mnist的赛题,通过分类算法,将图片数据进行识别.mnist数据集里面,包含了42000张手写数字0到9的图片,每张图片为28*28=784的像素,所以整 ...

  8. 适合初学者的使用CNN的数字图像识别项目:Digit Recognizer with CNN for beginner

    准备工作 数据集介绍 数据文件 train.csv 和 test.csv 包含从零到九的手绘数字的灰度图像. 每张图像高 28 像素,宽 28 像素,总共 784 像素.每个像素都有一个与之关联的像素 ...

  9. SMO序列最小最优化算法

    SMO例子: 1 from numpy import * 2 import matplotlib 3 import matplotlib.pyplot as plt 4 5 def loadDataS ...

随机推荐

  1. Android 应用开发推荐书单

    本文由 伯乐在线 - zerob13 翻译自 fromdev.欢迎加入Android小组.转载请参见文章末尾处的要求. Android 已经成为了世界上最受欢迎的操作系统之一.成千上万的智能手机和平板 ...

  2. Linux经常使用命令(十二) - less

    less 工具也是对文件或其他输出进行分页显示的工具.应该说是linux正统查看文件内容的工具.功能极其强大. less 的使用方法比起 more 更加的有弹性.使用了 less 时.更easy用来查 ...

  3. 安装windows7导致Ubuntu启动项消失的问题的解决

    系统原来是Ubuntu14,前两天安装win7后,启动直接是win7.也就是Ubuntu的启动项消失了. 在windows下尝试非常多方法,都以失败告终,最后选择Ubuntu下boot-repair软 ...

  4. Linux的grep命令详解

    简介 grep (global search regular expression(RE) and print out the line,全面搜索正则表达式并把行打印出来)是一种强大的文本搜索工具,它 ...

  5. mfc修改应用程序外观

    1.在窗口创建前修改窗体外观 在BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)函数中修改,其中CREATESTRUCT结构中有诸如窗口大小 ...

  6. Mac 修改Host 绑定host

    Mac 系统下 ,修改Host 文件: 打开命令行终端 输入 sudo vi /etc/hosts 之后回车确认,进入vi 编辑界面(进行vi编辑操作,之后保存就行了) 版权声明:本文为博主原创文章, ...

  7. 【ASP.NET Web API教程】2.3.2 创建域模型

    原文:[ASP.NET Web API教程]2.3.2 创建域模型 Part 2: Creating the Domain Models 第2部分:创建域模型 本文引自:http://www.asp. ...

  8. 浅析——SCTP协议(转)

    SCTP处于SCTP用户应用层与IP网络层之间,它运用“关联”(association)这个术语定义交换信息的两个对等SCTP用户间的协议状态 .SCTP也是面向连接的,但在概念上,SCTP“关联”比 ...

  9. Raspberry pi raspbain系统下使用vim

    一开始 apt-get install vim不好用. 在putty中执行这条命令就可以了. sudo apt-get update && sudo apt-get install v ...

  10. 百度贴吧客户端(Android)网络通信行为分析

    百度贴吧安卓客户端网络通信行为分析 本文由CSDN-蚍蜉撼青松[主页:http://blog.csdn.net/howeverpf]原创,转载请注明出处! 一.实验环境与结果概述 1.1 实验环境   ...