自我学习(Self-Taught Learning)

自我学习就是把稀疏自编码器与Softmax回归分类器串联起来。

稀疏编码器是用来无监督学习的,使用无标签数据
回归分类器是有监督学习,使用标签数据


实际生活中,我们能轻松获得大量无标签数据(如从网上随机下载海量图片)
难以获得大量有标签数据(有标签的数据库通常不会太大,而且很贵


如果我们手头上只有少量标签数据,但是有大量的无标签数据,这是就可以采用自我学习的方式,得到有用的特征,进而获得比单纯Softmax好得多的效果。
我们还是用MINST数据库,我们把0~4这些手写体数据作为无标签数据;把5~9这些手写体数据再次一分为二,一部分为测试数据,一部分为验证数据。


程序方面因为有了前面几节的基础,把相关函数调用一下就好:




minFunc
display_network
initializeParameters
loadMNISTImages
loadMNISTLabels
softmaxCost
softmaxPredict
softmaxTrain
sparseAutoencoderCost
train-images.idx3-ubyte
train-labels.idx1-ubyte


各个部分的核心代码如下


stlExercise

opttheta = theta; 
addpath minFunc/
options.Method = 'lbfgs';
options.maxIter = 400;
options.display = 'on';
[opttheta, cost] = minFunc( @(p) sparseAutoencoderCost(p, ...
                                   inputSize, hiddenSize, ...
                                   lambda, sparsityParam, ...
                                   beta, unlabeledData), ...
                              theta, options);

feedForwardAutoencoder

activation=sigmoid(bsxfun(@plus,W1*data,b1));


训练Softmax分类器

options.maxIter = 100;
softmaxModel = softmaxTrain(hiddenSize, numLabels, 1e-4, ...
                            trainFeatures,trainLabels, options);


给出推断

[pred] = softmaxPredict(softmaxModel,testFeatures);


需要注意区分的几个变量,有可能弄混

trainData
trainLabels
testData
testLabels
trainFeatures
testFeatures

本次试验消耗的计算时间是很长的,Andrew表示

For us, the training step took less than 25 minutes on a fast desktop.

在我Thinkpad i5上测试结果是半小时左右,我不小心手一滑,覆盖了原先数据,又消耗了半小时。。。

半小时过后,可以瞧瞧稀疏自编码器学习到的特征

图1

最后的运行效果很不错,相比Softmax有了很大提升:

Test Accuracy: 98.215453%


欢迎参与讨论并关注本博客微博以及知乎个人主页后续内容继续更新哦~

转载请您尊重作者的劳动,完整保留上述文字以及文章链接,谢谢您的支持!





发布了54 篇原创文章 · 获赞 86 · 访问量 47万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章