The goal is to run Poisson regression for neural networks (multi-layer perceptron) in R.
I am currently using the neuralnet
package in R.
I have read Is there an R package which uses neural networks to explicitly model count data? and Nonlinear Poisson regression using neural networks: a simulation study. I have figured out that I should change the error function to err.fct = function(x, y) { -(-x+y*log(x))}
(for Poisson).
Code:
fit <- neuralnet(nclaims ~ age_ph + gender + tar_region + weight + age_car + ptw, data = df, hidden = 1, err.fct = function(x, y) { -(-x+y*log(x))}, act.fct = "logistic")
.
I know that act.fct = "logistic"
specifies the sigmoid function in the hidden layer, but how can I change to the exponential function in the output layer?