为什么在R的deepnet包中使用nn.predict进行预测会返回常量值? [英] Why does prediction using nn.predict in deepnet package in R return constant value?

查看:298
本文介绍了为什么在R的deepnet包中使用nn.predict进行预测会返回常量值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 CIFAR-10数据集.这是我准备数据的方式:

I work with The CIFAR-10 dataset. Here is the way I prepare data:

library(R.matlab)
A1 <- readMat("data_batch_1.mat")
A2 <- readMat("data_batch_2.mat")
A3 <- readMat("data_batch_3.mat")
A4 <- readMat("data_batch_4.mat")
A5 <- readMat("data_batch_5.mat")
meta <- readMat("batches.meta.mat")
test <- readMat("test_batch.mat")
A <- rbind(A1$data, A2$data, A3$data, A4$data, A5$data)
Gtrain <- 0.21*A[,1:1024] + 0.71*A[,1025:2048] +0.07*A[,2049:3072]
ytrain <- c(A1$labels, A2$labels, A3$labels, A4$labels, A5$labels)
Gtest <- 0.21*test$data[,1:1024] + 0.71*test$data[,1025:2048]     +0.07*test$data[,2049:3072]
ytest <- test$labels
x_train <- Gtrain[ytrain %in% c(7,9),]
y_train <- ytrain[ytrain %in% c(7,9)]==7
x_test <- Gtest[ytest %in% c(7,9),]
y_test <- ytest[ytest %in% c(7,9)]==7

我训练深度神经网络:

library(deepnet)
dnn <- dbn.dnn.train(x_train, y_train, hidden = rep(10,2),numepochs = 3)

我做出预测

prednn <- nn.predict(dnn, x_test)

返回用一个值填充的向量(在这种情况下为0.4603409,但是对于不同的参数,它始终约为0.5).怎么了?

which returns vector filled with one value (0.4603409 in this case, but for different parameters it is always something around 0.5). What is wrong?

推荐答案

基于类似问题的答案,请考虑以下方法: 神经网络预测为所有预测返回相同的值

Based on this answer to similar question maybe consider this approach: neuralnet prediction returns the same values for all predictions

使用神经网络获得怪异结果时要考虑的第一个原因是归一化.您的数据必须进行标准化,否则,是的,训练将导致偏斜的NN始终产生相同的结果,这是常见症状.

The first reason to consider when you get weird results with neural networks is normalization. Your data must be normalized, otherwise, yes, the training will result in skewed NN which will produce the same outcome all the time, it is a common symptom.

看您的数据集,有>> 1值,这意味着它们被NN对待的方式基本上相同.其原因是,传统上使用的响应函数在(大约)0附近的某个范围内(几乎)是恒定的.

Looking at your data set, there are values >>1 which means they are all treated by NN essentially the same. The reason for it is that the traditionally used response functions are (almost) constant outside some range around 0.

在将数据输入神经网络之前,总是对其进行标准化.

Always normalize your data before feeding it into a neural network.

这篇关于为什么在R的deepnet包中使用nn.predict进行预测会返回常量值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆