[R] Inf in nnet final value for validation data

jude.ryan at ubs.com jude.ryan at ubs.com
Thu Jun 11 23:28:28 CEST 2009


Andrea,

 

You can calculate predictions for your validation data based on nnet objects using the predict function (the predict function can also be used for regressions, quantile regressions, etc.)

If you create a neural net with the following code: 

 

library(nnet)

# 3 hidden neurons, for classification (linout = F), and not a skip layer network (skip = F, or T if you want)

mynet.nn <- nnet(dependent_variable ~ ., data = train, size = 3, decay = 1e-3, linout = F, skip = F, maxit = 1000, Hess = T)  

# calculate predictions for your training data and append to data frame called train

train$predictions <- predict(mynet.nn)

# calculate predictions for your validation data and append to data frame called valid

valid$predictions  <- predict(mynet.nn, valid)  # you need to pass your neural net object and your validation dataset to the predict function

 

To just get the predictions for your validation dataset this is all you need. I do not know why you need to calculate the log likelihood.

 

Hope this helps.

 

Jude

 

 

Andrea wrote:

 

Hi,

 

I use nnet for my classification problem and have a problem concerning the calculation of the final value for my validation data.(nnet only calculates the final value for the training data). I made my own final value formula (for the training data I get the same value as nnet):

  

    # prob-matrix

    pmatrix <- cat*fittedValues

    tmp <- rowSums(pmatrix) 

    

    # -log likelihood

    finalValue <- sum(-log(tmp))

    

    # add penalty term

    finalValue + sum(decay * weights^2)

  

where cat is a matrix with cols for each possible category and a row for each data record. The values are 1 for the target categories of a data record and 0 otherwise.

 

My problem is, that I get Inf-values for some validation data records, because the rowsum of cat*fittedValues gets 0 and the log gets Inf.

 

Has anyone an idea how to deal with that problem properly? How does nnet?

 

I´m thinking of a penalty value for those values. That means if cat*fittedValues == 0 not to calculate the log but add e.g. 100 instead of "-log(tmp)" to the finalValue-sum??

But how to determine the penalty value???

 

I´m looking forwar for all suggestions,

 

Andrea.

 

 

___________________________________________
Jude Ryan
Director, Client Analytical Services
Strategy & Business Development
UBS Financial Services Inc.
1200 Harbor Boulevard, 4th Floor
Weehawken, NJ 07086-6791
Tel. 201-352-1935
Fax 201-272-2914
Email: jude.ryan at ubs.com



-------------- next part --------------
Please do not transmit orders or instructions regarding a UBS 
account electronically, including but not limited to e-mail, 
fax, text or instant messaging. The information provided in 
this e-mail or any attachments is not an official transaction 
confirmation or account statement. For your protection, do not 
include account numbers, Social Security numbers, credit card 
numbers, passwords or other non-public information in your e-mail. 
Because the information contained in this message may be privileged, 
confidential, proprietary or otherwise protected from disclosure, 
please notify us immediately by replying to this message and 
deleting it from your computer if you have received this 
communication in error. Thank you. 

UBS Financial Services Inc. 
UBS International Inc. 
UBS Financial Services Incorporated of Puerto Rico 
UBS AG

 
UBS reserves the right to retain all messages. Messages are protected
and accessed only in legally justified cases.


More information about the R-help mailing list