r random forest error - type of predictors in new data do not match

前端 未结 8 1421
挽巷
挽巷 2020-12-04 14:37

I am trying to use quantile regression forest function in R (quantregForest) which is built on Random Forest package. I am getting a type mismatch error that I can\'t quite

8条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-04 15:29

    Expanding on @user1849895's solution:

    common <- intersect(names(train), names(test)) 
    for (p in common) { 
      if (class(train[[p]]) == "factor") { 
        levels(test[[p]]) <- levels(train[[p]]) 
      } 
    }
    

提交回复
热议问题