【问题标题】:How to use Deep Neural Networks for regression?如何使用深度神经网络进行回归?
【发布时间】:2017-09-16 22:33:15
【问题描述】:

我编写了这个脚本 (Matlab) 用于使用 Softmax 进行分类。现在我想通过用 Sigmoid 或 ReLU 激活函数替换 Softmax 输出层来使用相同的脚本进行回归。但我做不到。

X=houseInputs ;
T=houseTargets;
%Train an autoencoder with a hidden layer of size 10 and a linear transfer function for the decoder. Set the L2 weight regularizer to 0.001, sparsity regularizer to 4 and sparsity proportion to 0.05.

hiddenSize = 10;
autoenc1 = trainAutoencoder(X,hiddenSize,...
    'L2WeightRegularization',0.001,...
    'SparsityRegularization',4,...
    'SparsityProportion',0.05,...
    'DecoderTransferFunction','purelin');
%% 
%Extract the features in the hidden layer.

features1 = encode(autoenc1,X);
%Train a second autoencoder using the features from the first autoencoder. Do not scale the data.

hiddenSize = 10;
autoenc2 = trainAutoencoder(features1,hiddenSize,...
    'L2WeightRegularization',0.001,...
    'SparsityRegularization',4,...
    'SparsityProportion',0.05,...
    'DecoderTransferFunction','purelin',...
    'ScaleData',false);

features2 = encode(autoenc2,features1);

%% 
softnet = trainSoftmaxLayer(features2,T,'LossFunction','crossentropy');
%Stack the encoders and the softmax layer to form a deep network.

deepnet = stack(autoenc1,autoenc2,softnet);
%Train the deep network on the wine data.

deepnet = train(deepnet,X,T);
%Estimate the deep network, deepnet.

y = deepnet(X);

【问题讨论】:

    标签: matlab machine-learning deep-learning regression


    【解决方案1】:

    回归是与分类不同的问题。您必须将损失函数更改为适合回归的东西,例如均方误差,当然也可以将神经元的数量改为一个(最后一层只会输出 1 个值)。

    【讨论】:

      【解决方案2】:

      可以使用神经网络来执行回归任务,但对于许多任务来说这可能是一种过度杀伤力。真正的回归意味着将一组连续输入映射到另一组连续输出:

      f: x -> ý
      

      更改神经网络的架构以使其执行回归任务通常相当简单。您不必像在您的情况下使用 Softmax 函数将连续输入数据映射到特定类,而是必须使网络仅使用单个输出节点。

      这个节点只会将前一层(最后一个隐藏层)的输出相加,并将相加的激活乘以 1。在训练过程中,此输出 ý 将与数据集随附的正确真实值 y 进行比较。作为损失函数,您可以使用Root-means-squared-error (RMSE)

      训练这样的网络将产生一个模型,该模型将任意数量的自变量 x 映射到因变量 ý,这基本上是一个回归任务。

      回到您的 Matlab 实现,将当前的 Softmax 输出层更改为激活函数(如 Sigmoid 或 ReLU)是不正确的。相反,您必须为您的网络实现一个自定义 RMSE 输出层,该输出层接收来自网络最后一个隐藏层的激活总和。

      【讨论】:

      • 很好的解释。那么在附加的脚本中,训练函数应该是什么而不是softmax? softnet = trainSoftmaxLayer(features2,T,'LossFunction','crossentropy');
      猜你喜欢
      • 2017-04-18
      • 2013-05-28
      • 2012-10-26
      • 2018-10-15
      • 2016-06-15
      • 1970-01-01
      • 2019-01-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多