How to get multiclass neural network equation for use in excel


I made an R code using caret to do a multi-class classification neural network.
I am able to achieve good classification results and able to predict new data with the neural network.

I want to get the weights of the neural network, in other words, I want to know how the neural network classifies the data in order to insert these weights on excel and make excel predict new data through the neural network weights.

I was able to get the weights from R using the neuralweights function. the output of the function is factors and I don't know how these predicts classes at the end. My classes are "on or below schedule" - "Late-major" - "late - minor" etc.

any help?
This is the Rcode:

#fit model

fit <- nnet(Status~.,data=data, size =6, decay= 0.0001, maxit = 500)
predictions <- predict(fit, data[,1:6], type = "class")
#predicting tests
predictiontest <-predict(fit, datatest[,1:6], type = "class")

confusionMatrix(as.factor(predictions), as.factor(data$Status))

These are the weights: 

[1] 6 6 4

$wts$`hidden 1 1`
[1] -2.6590091 -7.1824542  0.4958755  0.8433498  8.2095521  2.4000397 -3.1055782

$wts$`hidden 1 2`
[1] -0.4194698 -7.8059757 -3.1148086  0.2468263  8.1757322  1.9420070  0.3023690

$wts$`hidden 1 3`
[1]  0.2573233 -0.7496363  0.6353437 -1.0495383  0.2317010  1.9741867 -2.0314975

$wts$`hidden 1 4`
[1] 0.02282316 0.20079435 0.19397557 0.21898944 0.24693248 0.15382270 0.24684709

$wts$`hidden 1 5`
[1]  0.1942839 -0.9739676 -0.4665476  1.2561668  1.0399035  3.4011882 -5.0683255

$wts$`hidden 1 6`
[1] 17.661462 -2.104310  1.610985  3.904200 -7.992500 -3.871134  5.083067

$wts$`out 1`
[1]   3.254789767 -13.827205640   6.822064728   0.003571207   3.251182730  -6.703624868  10.175074072

$wts$`out 2`
[1]  -3.12855859  -1.07939139 -14.15440722  -0.01217096  -3.12799684  -0.13091726  35.75726368

$wts$`out 3`
[1]   2.713869  -0.118249   6.031388  11.196365   2.710654  -5.039395 -31.007136

$wts$`out 4`
[1]  -2.839328  15.020478   1.303031 -11.189032  -2.837091  11.877274 -14.926057

thanks in advance

The weights is only a part of the neural network. To be able to use the network you have to know what layers are there, how many of then, how many neurons is there in each layer. You need to know activation functions too. So you won't be able to reflect the neural network in excel just knowing the weights. You'd need to implement a neural network in Excel on your own, which is inefficient and you should forget this idea, in my opinion.

The most important equation in NN is x* = Wx + b, so knowing the weights (the W in the equation) you are able to calculate each neuron's sum - the input value. Theoretically, it is possible to do this in Excel as matrix multiplication is achieved by a dedicated function. Then you'll have to handle activations. Next step would be to transfer all x* as inputs to the next layer and again until you reach the outcome layer (class predictions). A lot of work to do and a lot of errors along the way. I'd consider it only as a theoretical solution or, if you really want to understand how NNs work step by step, this could be a (not so) good excerise.

But maybe the output from your network can be approximated by a simpler (linear) model - if so, you could try implement the simpler model in Excel, which is easy and effortless.

Also, we often want the predictors for this model to be in the same units. Do do so, we typically normalize by either centering/scaling or range normalization. You'll need to embed those statistics and transformations for each predictor in order to get the correct results.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.