Exercise:Self-Taught Learning 代码示例

本文介绍了一种结合稀疏自编码器和Softmax分类器的方法,用于无监督学习手写数字5到9的特征,并利用这些特征对0到4的手写数字进行有监督分类。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

练习参考Self-Taught Learning


结合使用稀疏自编码器和Softmax分类器对0到4的手写数字进行分类。首先利用稀疏自编码器无监督学习手写数字5到9的特征。利用学到的权重和偏置计算手写数字0到4的激活值,并将激活值作为Softmax分类器的输入进行分类(有监督学习)。


Train the sparse autoencoder

opttheta = theta;
addpath minFunc/
options.Method = 'lbfgs'; 
options.maxIter = maxIter;
options.display = 'on';

[opttheta, cost] = minFunc( @(p) sparseAutoencoderCost(p, ...
                                   inputSize, hiddenSize, ...
                                   lambda, sparsityParam, ...
                                   beta, unlabeledData), ...
                              theta, options);


Extracting features

feedForwardAutoencoder.m
activation = sigmoid(W1*data+repmat(b1,1,size(data,2)));


Train the softmax classifier

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

Testing

[pred] = softmaxPredict(softmaxModel, testFeatures);





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值