0

I am getting an error here for the makeClassifTask() from MLR package.

task = makeClassifTask(data = data[,2:20441], target='Disease')

Entering this I get this error.

Provided data is not a pure data.frame but from class data.table, hence it will be converted. Error in [.data.table(data, target) : When i is a data.table (or character vector), the columns to join by must be specified using 'on=' argument (see ?data.table), by keying x (i.e. sorted, and, marked as sorted, see ?setkey), or by sharing column names between x and i (i.e., a natural join). Keyed joins might have further speed benefits on very large data due to x being sorted in RAM.

If someone could help me out it'd be great.

pat-s
  • 5,992
  • 1
  • 32
  • 60
  • Should I revert the object back to data.frame? – Shreyash Gupta Dec 25 '20 at 09:25
  • Welcome to Stackoverflow. You can edit your question instead of adding another question in the comment section. Also take care to choose the right tags for your questions. Next it is common practice to post a [minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – pat-s Dec 25 '20 at 09:32

2 Answers2

0

Given that you did not provide the data I can only do some guessing and suggest to read the documentation at https://mlr3book.mlr-org.com/tasks.html.

It looks like you left out the first column in your dataset which might be your target. Hence makeClassifTask() cannot find your target column.

pat-s
  • 5,992
  • 1
  • 32
  • 60
  • 1
    Hey!! I resolved the issue with changing the data.table object to data.frame and it worked with as.data.frame(), but anyways thanks for checking it out. – Shreyash Gupta Dec 26 '20 at 16:43
  • Great. You can also post your reply as an answer and accept it. `data.table` should work as input though - mlr3 only uses `data.table` under hood. – pat-s Dec 26 '20 at 16:52
0

As @Shreyash Gputa pointed out correctly, changing the data.table object to a data.frame object solves the issue:

task = makeClassifTask(data = as.data.frame(data[,2:20441]), target='Disease')

Given of course that data[,2:20441] contains the target variable Disease...

MJimitater
  • 833
  • 3
  • 13
  • 26