0

I'm working on a student performance dataset and I get this message error

Error in trafo(data = data, numeric_trafo = numeric_trafo, factor_trafo = factor_trafo, : data class “character” is not supported In addition: Warning message: In storage.mode(RET@predict_trafo) <- "double" : NAs introduced by coercion

from this code, and I don't know why?

set.seed(1)
ind <- sample(2,nrow(d2),replace = TRUE ,prob = c(0.7,0.3))
trainData <- d2[ind==1,]
testData <- d2[ind==2,]
library(party)
myFormula <- higher~G1+G2+G3
d2_ctree <- ctree(myFormula, data=trainData)
table(predict(d2_ctree),trainData$higher)
Razan
  • 11
  • 4
  • 2
    unfortunately you did not supply data of d2. From the error it should be clear, that you have some variable as character when it should be factor (most probable) or maybe numeric (integer/double).... many algorithms/functions do not work with character but they work when converitng these columns to factors... hope this helps – DPH Nov 04 '20 at 14:09
  • You didn't supply d2 object . However , i think this example may help you : https://rpubs.com/njvijay/14899 – Tou Mou Nov 04 '20 at 14:14

2 Answers2

0

An example with iris data ( as you didn't give d2 data ) :

library(party)
set.seed(1234) #To get reproducible result
ind <- sample(2,nrow(iris), replace=TRUE, prob=c(0.7,0.3))
trainData <- iris[ind==1,]
testData <- iris[ind==2,]
myFormula <- Species ~ Sepal.Length + Sepal.Width + Petal.Length + Petal.Width
d2_ctree <- ctree(myFormula, data=trainData)
table(predict(d2_ctree),trainData$Species)
plot(d2_ctree)

Source : source

Tou Mou
  • 1,270
  • 5
  • 16
0

You should convert all nonnumerical columns to numeric.

d2$higher = factor(d2$higher,levels = c("Label1","Label2","Label3"), 
                    labels = c(1, 2, 3))
Mahmoud Nasr
  • 564
  • 7
  • 11