Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

panic: interface conversion: ... missing method CatToNum #47

Open
jerogee opened this issue Mar 18, 2015 · 9 comments
Open

panic: interface conversion: ... missing method CatToNum #47

jerogee opened this issue Mar 18, 2015 · 9 comments

Comments

@jerogee
Copy link

jerogee commented Mar 18, 2015

I run into an error using libsvm's sparse format, given the following files:

  1. Training data, 5 instances: https://www.dropbox.com/s/nlzfgj9235ffhsd/cf_test2.train.libsvm?dl=1
1.00000001 2:4.682604e-01 3:6.842105e-01 ...
1.60000001 2:2.247624e+00 3:4.454545e-01 ...
...
  1. Testing data, 2 instances: https://www.dropbox.com/s/t44uc09rdyboiev/cf_test2.test.libsvm?dl=1
0.16666601 2:1.619004e+00 3:3.390276e-01 ...
0.88888801 2:6.182730e-01 3:1.569653e-01 ...

Training goes well, but testing throws an error. Any idea what is going on?

$ growforest -train cf_test2.train.libsvm -rfpred cf_test2.sf -target 0
...
$ applyforest -fm cf_test2.test.libsvm -rfpred cf_test2.sf -preds cf_test2.pred
Target is 0 in feature 0
panic: interface conversion: *CloudForest.DenseNumFeature is not CloudForest.CatFeature: missing method CatToNum

goroutine 1 [running]:
github.com/ryanbressler/CloudForest.(*CatBallotBox).TallyError(0x20832bfe0, 0x2208291c48, 0x2082b40f0, 0x2)
    /Users/jg/src/github.com/ryanbressler/CloudForest/catballotbox.go:91 +0x5c
main.main()
    /Users/jg/src/github.com/ryanbressler/CloudForest/applyforest/applyforest.go:69 +0xb5a
@ryanbressler
Copy link
Owner

It looks like applyforest thinks you're doing classification (it uses a stupid method to guess) and is trying to treat you're target feature as categorical.

You can give it the -mean flag to force it to vote numerically but I should probably make it better about guessing for libsvm files.

@jerogee
Copy link
Author

jerogee commented Mar 18, 2015

Ryan, thanks for suggesting the -mean flag. That works. I already converted any integers to floats for the target feature and assumed that would have been sufficient. This asides: your implementation works really well.

@mhfzsharmin
Copy link

mhfzsharmin commented Oct 7, 2017

Hi @ryanbressler I am trying to run the following code using your CloudForest. My input file format is in libsvm. And 1st column is the target. The labels are 0,1 and 2. I want the classification, not regression. Thanks for your help.

#------------code
growforest -ordinal -train train.binary.libsvm -test validate.binary.libsvm -target 0 -gbt=1 -l1=true -rfpred forest.binary.sf -nCores 20 -importance importance.binary.txt

#---------------error message
Error: 1
panic: runtime error: index out of range

goroutine 1 [running]:
panic(0x623ae0, 0xc820010070)
/usr/lib/go-1.6/src/runtime/panic.go:481 +0x3e6
main.main()
/users/annashch/go/src/github.com/ryanbressler/CloudForest/growforest/growforest.go:945 +0x92ec

@ryanbressler
Copy link
Owner

@mhfzsharmin. Your prams don't make sense...l1 and ordinal are regression methods and not compatible with gradient boosting. Also since it is erroring at test time you may just be able to test with applyforest.

@mhfzsharmin
Copy link

@ryanbressler I tried without "-ordinal" and "-l1=true" as well. Still, I get the same error.

@mhfzsharmin
Copy link

mhfzsharmin commented Oct 9, 2017

@ryanbressler
Is gbt=1 parameter also for regression? I removed this parameters and it ran successfully (thank you for your previous reply!).
However, now I have some strange issue: none of my input files have label=6. But the tree produced is giving a label 6! I wonder does the algorithm gives prediction 6 when it cannot decide or something like that. Thanks for your reply

msharmin@nandi:~/cloudforest$ grep 'PRED=6' forest..binary.sf | wc -l
400972

msharmin@nandi:~/cloudforest$ grep 'PRED=0' forest.binary.sf | wc -l
22065

msharmin@nandi:~/cloudforest$ grep 'PRED=1' msforest.binary.sf | wc -l
9753092

msharmin@nandi:~/cloudforest$ grep 'PRED=2' msforest.binary.sf | wc -l
11458347

msharmin@nandi:~/cloudforest$ cut -f1 test.binary.libsvm | sort |uniq
0
1
2

msharmin@nandi:~/cloudforest$ cut -f1 train.binary.libsvm | sort |uniq
0
1
2

@ryanbressler
Copy link
Owner

Gradient boosting can be used with (binary) classification but you have to use it with the sum and expit options in applyforest IIRC.

6 has no special meaning in the output.

There may be a bug/quirk in my libsvm parsing code causing it to see that value or learn from the wrong column, you could try one of the other formats or using applyforest instead of the -test option.

IF you post the whole command and the output it gives i may be able to tell if anything funky is going on, otherwise sorry I can't be more helpful.

@mhfzsharmin
Copy link

@ryanbressler using *.afm format worked. I had 3 labels in my target column. To confirm my understanding Multi-class classification works in cloudforest, right? If this is a parsing issue of libSVM, may be instead of using numeric category (0,1 and 2), direct A,B,C as categories would have worked in libSVM. If I get to that, I will post the result in case any future users find it helpful. Thanks for your response.

@ryanbressler
Copy link
Owner

Multi class classification works with the standard gini impurity random forest and the -entropy option.

Gradient Boosting boosting relies on the gradient of the logistic loss function which is intrinsically binary (IIRC the same is true with adaboost). You can however train one boosted forest for each class if you want to experiment with multiclass boosting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants