Still struggling with simple regression tasks
I am still struggling to figure out how to specify using NDLNetworkBuilder a simple regression task, where I can output the predictions from one or more Y variables. The data are a simple linear regression problem with 9 predictors and 1 Y variable, with a multiple linear R-square of .8. There are 100 cases. This should be easily solvable, so somehow my specifications must be off. I am getting predictions but they are simply wrong (R-square in training data close to 0).
Where am i going wrong here:
Parameters can be overwritten on the command line
for example: cntk configFile=myConfigFile RootDir=../..
For running from Visual Studio add
currentDirectory=$(SolutionDir)/
RootDir = ".."
RootDir = "."
ConfigDir = "$RootDir$/Config" DataDir = "$RootDir$/Data" OutputDir = "$RootDir$/Output" ModelDir = "$OutputDir$/Models"
deviceId=-1 for CPU, >=0 for GPU devices, "auto" chooses the best GPU, or CPU if no usable GPU is available
deviceId = -1
command = Factor_Train:Factor_Test:Factor_Output:Factor_Dumpnodes
precision = "float" traceLevel = 1 modelPath = "$ModelDir$/Factor.dnn"
Factor_Train = [ action = "train"
# Notation xxx:yyy*n:zzz is equivalent to xxx, then yyy repeated n times, then zzz
# Example: 10:20*3:5 is equivalent to 10:20:20:20:5
NDLNetworkBuilder = [
run = ndlLR
ndlLR = [
# sample and label dimensions
SDim = 9
HDim = 4
LDim = 1
features = Input(SDim)
mean1=Mean(features)
invStdDev1=InvStdDev(features)
f=PerDimMeanVarNormalization(features, mean1, invStdDev1)
labels = Input(LDim)
mean2=Mean(labels)
invStdDev2=InvStdDev(labels)
l=PerDimMeanVarNormalization(labels, mean2, invStdDev2)
# parameters to learn, and operations, layer 1
B0 = Parameter(HDIM) # HDIM x 1
W0 = Parameter(HDim,SDim) # HDIM x SDIM
T1 = Times(W0, f) # HDIM x 1
P1 = Plus(T1, B0) # HDIM x 1
s1 = sigmoid(P1) # HDIM x 1
B1 = Parameter(LDim) # HDIM x 1
W1 = Parameter(LDim,HDim) # LDIM, HDIM
T2 = Times (W1,S1) # LDIM, 1
P2 = Plus (T2,B1) # LDIM, 1
l2=PerDimMeanVarDeNormalization(P2, mean2, invStdDev2)
LR = SquareError(l, P2)
EP = SquareError(l, P2)
# root nodes
FeatureNodes = (features)
LabelNodes = (labels)
CriteriaNodes = (LR)
EvalNodes = (EP)
OutputNodes = (l2)
]
]
SGD = [
# epochSize = 0 means epochSize is the size of the training set
epochSize = 0
minibatchSize = 100
learningRatesPerMB = 0.5:0.2*20:0.1
learningRatesPerMB = 0.5
momentumPerMB = 0.9
dropoutRate = 0.0
maxEpochs = 200
]
# Parameter values for the reader
reader = [
readerType = "UCIFastReader"
file = "$DataDir$/FactorTrain.txt"
miniBatchMode = "partial"
randomize = "none"
verbosity = 1
features = [
dim = 9 # two-dimensional input data
start = 0 # Start with first element on line
]
labels = [
start = 9 # Skip two elements
dim = 1 # One label dimensione
labelType = "regression"
]
]
]
]
PS: Turns out the Sigmoid function is not suitable here (for regression prediction; which makes sense...); using s1 = Tanh(P1) seems to fix it; also works for multiple outputs with heterogeneous scale...
Great! If this solved it, would you mind closing the issue?
(I am a little puzzled that Sigmoid() does not give you good results, since the Sigmoid can be transformed into something very similar to Tanh() by adding/scaling with constants. Its modelling power should be very similar. So the problem you were facing is one of convergence, not of modelling. Interesting.)
I read a bit more about this here: http://cs231n.github.io/neural-networks-1/ (the Stanford NN course); there is also a discussion here of activation functions for regression: http://stats.stackexchange.com/questions/101560/tanh-activation-function-vs-sigmoid-activation-function, although I am still digesting this paper: http://yann.lecun.com/exdb/publis/pdf/lecun-98b.pdf.
Either way, that made all the difference. It's possible that the other parameters driving the estimation computations (learning rate, penalties, etc.) also are critical, but frankly, this seems to be very application and data dependent to me, and still a matter of much research....
I'll close this as you suggested. THANKS!