The scitype of X in Machine is incompatible with model

Viewed 170

I am trying to use MLJ to train some data using the random forest classifier. In order to do that, I have coerce my categorical variables to Multiclass(scitype) and continuous features to Continuous. (I have also changed the target variables scitype to Multiclass)

 MLJ.schema(X)

enter image description here

However when I construct the machine object I get the following warning,

 mach = machine(forest, X,y)

 ┌ Warning: The scitype of `X`, in `machine(model, X, ...)` is incompatible 
 with `model=RandomForestClassifier @695`:
 │ scitype(X) = Table{Union{AbstractArray{Continuous,1}, 
 AbstractArray{Multiclass{8},1}, AbstractArray{Multiclass{3},1}, 
 AbstractArray{Multiclass{14},1}, AbstractArray{Multiclass{7},1}, 
 AbstractArray{Multiclass{12},1}}}
 │ input_scitype(model) = Table{var"#s45"} where var"#s45" 
 <:Union{AbstractArray{var"#s13",1} where var"#s13"<:Count, 
 AbstractArray{var"#s13",1} where var"#s13"<:OrderedFactor, 
 AbstractArray{var"#s13",1} where var"#s13"<:Continuous}.

followed by this TaskFailedExceptionErrorwhen I fit the model

trainRows, testRows = partition(eachindex(y),0.7, shuffle = true)
MLJ.fit(mach, rows = trainRows)

I tested the model with just the Continuous features and it works fine. So it's something incorrect with categorical variables (with scitype Muticlass), but can't quite figure out what it is. Any ideas what I am doing incorrectly?

1 Answers

The MLJDecisionTreeInterface does not support the Multiclass scitype. GitHub:

Inputs are tables with ordinal columns. That is, the element scitype
of each column can be `Continuous`, `Count` or `OrderedFactor`.

One possible solution would be to expand out the categorical columns of the table as one-hot encoded columns like in this forum post.

Related