Home   >   User Resources   >   Online Help   >   apaNN.MLPClassifier.Estimate
 

 

Function index Version 3.0.0

apaNN.MLPClassifier.Estimate(X, Y, L2Penalty)

Excel=apaNN.MLPClassifier.Estimate(X, Y, L2Penalty)

Result

Estimates a multiclass neural network classifier with one hidden layer (multilayer perceptron, MLP) and returns diagnostics, parameters and in-sample predictions. The function is non-volatile.

Syntax

X: n x p matrix of predictors

Y: n x 1 vector of the dependent variable with integer classes 1..K

L2Penalty: optional; L2 penalty on the weights, >= 0. Default value: 0.01

Algorithm

The predictors are standardized with their means and sample standard deviations (denominator n − 1). For the standardized predictor vector z(i) of observation i, the network has 12 tanh hidden units and a softmax output over the K classes:

hi=tanh(W1⊤zi+b1),P(yi=k)=exp⁡(w2,k⊤hi+b2,k)∑l=1Kexp⁡(w2,l⊤hi+b2,l)h_{i} = tanh\left( W_{1}^{\top}z_{i} + b_{1} \right),\quad\quad P(y_{i} = k) = \frac{\exp\left( w_{2,k}^{\top}h_{i} + b_{2,k} \right)}{\sum_{l = 1}^{K}\exp\left( w_{2,l}^{\top}h_{i} + b_{2,l} \right)}

The weights minimize the L2-penalized mean log-loss

f=−1n∑i=1nlog⁡P(yi)+λ2(∥W1∥2+∥W2∥2)f = - \frac{1}{n}\sum_{i = 1}^{n}\log P(y_{i}) + \frac{\lambda}{2}\left( \left\| W_{1} \right\|^{2} + \left\| W_{2} \right\|^{2} \right)

where the penalty λ is L2Penalty and the biases b(1) and b(2) are not penalized. The objective is minimized with the limited-memory BFGS method (L-BFGS, memory 10) with exact gradients from backpropagation and a weak Wolfe line search. The starting weights are uniform random numbers with a fixed seed (123), scaled by 1/sqrt(p) and 1/sqrt(12), and the starting biases are 0, so the results are reproducible. The iteration stops when the largest absolute gradient component falls below 1E-6 (GradientTolerance), when the objective no longer decreases (FunctionTolerance), when the line search fails (LineSearchFailed) or after 10000 iterations (IterationLimit).

Remarks

The result starts with a diagnostics block. The first two columns contain the log-likelihood, the negative log-likelihood, AIC, BIC, the numbers of observations, predictors, classes and hidden units, the number of L-BFGS iterations and the termination reason. The next two columns contain the L2 penalty, the random seed, the number of parameters, the model type, the penalized objective f and the largest absolute gradient component at the solution. The diagnostics are followed by the blocks W1 (p x 12), b1, W2 (12 x K) and b2, where the weights W1 refer to the standardized predictors. The last block contains, for each observation, the actual class, the predicted class (highest probability) and the K class probabilities.

The objective is not convex, so the solution is a local minimum that depends on the starting weights. AIC and BIC use the full number of weights and biases; since the weights of a neural network are not identified, they are only rough indications. If the number of observations is small relative to the number of parameters, the network can fit the training data almost perfectly, and the in-sample accuracy overstates the accuracy on new data. A larger L2Penalty reduces this overfitting; with L2Penalty = 0 the fit can become arbitrarily close to perfect, with very large weights. The function returns an error message if a predictor is constant or if X contains non-finite values.