fawda123 / NeuralNetTools

R package of generic neural network tools
https://fawda123.github.io/NeuralNetTools/
Creative Commons Zero v1.0 Universal
71 stars 20 forks source link

Error when plotting #17

Closed basaldella closed 7 years ago

basaldella commented 7 years ago

Hello,

I have a strange error when trying to use plotnet. Let's assume I have two models, called m1 and m2, which are trained using the exact same formula on two different datasets.

If I do

> plotnet(m1,alpha=0.6)

Everything works fine.

But if run

> plotnet(m2,alpha=0.6)

What i get is

Error in as.character(forms) : 
  cannot coerce type 'closure' to vector of type 'character'

Do you have any idea of what could cause this problem?

fawda123 commented 7 years ago

Can you explain the models and input data a bit more? I can't diagnose anything from the example.

basaldella commented 7 years ago

Yeah, I'm sorry, you're right. I created a gist with the example code and data, I hope this helps.

In the code, as you can see, the formulae are the equal, the datasets (generated with the same tool) are very similar, but somehow plotnet(akecModel) fails, while plotnet(semevalModel) works. The same happens when I try to run garson and lekprofile as well.

fawda123 commented 7 years ago

You need to rename the formula object to something else. formula is already a function in R and that's causing problems in the NeuralNetTools functions. This should work:

library(nnet)
library(NeuralNetTools)

formulaA = AKEC ~ 
  tf +
  Freq_Sentence + 
  Height + 
  LifeSpan + 
  Depth +
  tf.idf + 
  Maximality

formulaS = SEMEVAL2010 ~ 
  tf +
  Freq_Sentence + 
  Height + 
  LifeSpan + 
  Depth +
  tf.idf + 
  Maximality

AKEC_train <- read.csv("https://gist.githubusercontent.com/basaldella/ebb672efbb12c565dec585a6ed0916b4/raw/b9dc49dffa6e8caa758cacd0a5acf8148b73c89e/akec.top.csv",stringsAsFactors = TRUE)
SEMEVAL_train <- read.csv("https://gist.githubusercontent.com/basaldella/ebb672efbb12c565dec585a6ed0916b4/raw/b9dc49dffa6e8caa758cacd0a5acf8148b73c89e/semeval.top.csv",stringsAsFactors = TRUE)

set.seed(1203) 
akecModel = nnet(formulaA,
                 size = length(attr(terms(formulaA),"variables")) * 2,
                 entropy=T,data = AKEC_train)

set.seed(1203) 
semevalModel = nnet(formulaS,
                    size = length(attr(terms(formulaS),"variables")) * 2,
                    entropy=T,data = SEMEVAL_train)

plotnet(akecModel)
plotnet(semevalModel)
basaldella commented 7 years ago

Now it works like a charm. Sorry for my mistake, but I'm far from being an R expert... Thanks a lot for your help!

fawda123 commented 7 years ago

No problem, I'm happy to help.