isofor icon indicating copy to clipboard operation
isofor copied to clipboard

Error in env$X[idx, ] : incorrect number of dimensions

Open mkoohafkan opened this issue 7 years ago • 5 comments

I'm getting an error with iForest that I don't understand:

# test dataset
test = data.frame(VALUE = rlnorm(200))
iForest(test, 100, 50)
## Error in env$X[idx, ] : incorrect number of dimensions
iForest(as.matrix(test), 100, 50)
## Error in env$X[idx, ] : incorrect number of dimensions
iForest(as_tibble(test), 100, 50)
## Isolation Forest with 100 Trees and Max Depth of 6

Why does iForest work with a tibble, but not with a regular data.frame or list?

mkoohafkan avatar Oct 10 '18 20:10 mkoohafkan

Try it with more than one column. It's probably dropping to a vector when it indices the data frame rows.

On Wed, Oct 10, 2018, 3:44 PM Michael [email protected] wrote:

I'm getting an error with iForest that I don't understand:

test dataset

test = data.frame(VALUE = rlnorm(200)) iForest(test, 100, 50)

Error in env$X[idx, ] : incorrect number of dimensions

iForest(as.matrix(test), 100, 50)

Error in env$X[idx, ] : incorrect number of dimensions

iForest(as_tibble(test), 100, 50)

Isolation Forest with 100 Trees and Max Depth of 6

Why does iForest work with a tibble, but not with a regular data.frame or list?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/Zelazny7/isofor/issues/19, or mute the thread https://github.com/notifications/unsubscribe-auth/ABmRXbpux2S6hitZ0rm_cTLtsqf3iWF4ks5ujlw-gaJpZM4XWSuj .

gravesee avatar Oct 10 '18 22:10 gravesee

Yes, the function works when there is more than one column, but my data is univariate. Do isolation forests not work on univariate data? I am new to this method.

mkoohafkan avatar Oct 11 '18 01:10 mkoohafkan

It's an issue of dropping dimensions when indexing a data.frame with one column. The second dimension gets dropped. I'll try to patch it tomorrow. It's an easy fix.

gravesee avatar Oct 11 '18 03:10 gravesee

I pushed a fix to this branch: https://github.com/Zelazny7/isofor/tree/fix-single-column-data-frame

Can you test it and let me know if it solves your problem? I was able to train an isolation forest on a data.frame with one column.

gravesee avatar Oct 11 '18 17:10 gravesee

@Zelazny7 it now works with vectors, data.frames, and matrices, but fails on tibbles:

Error in UseMethod("split_on_var") : no applicable method for 'split_on_var' applied to an object of class "c('tbl_df', 'tbl', 'data.frame')"

mkoohafkan avatar Oct 11 '18 17:10 mkoohafkan