因素有新的水平错误

时间:2017-03-31 19:24:47

标签: r linear-regression predict

R告诉我,我的字符串变量中有新的级别,但是当我打印出级别时,我不会看到它。 "电子"是测试和训练数据集中的一个级别。运行日志如下。我还为Predict阶段尝试了不同的数据子集,并将一组不同的级别列为新的。有什么想法吗?

> levels(trainingData$Genre)
 [1] "Alternative"        "Christian & Gospel" "Country"           
 [4] "Dance"              "Electronic"         "Hip Hop / Rap"     
 [7] "Hip-Hop"            "Pop"                "Pop in Spanish"    
[10] "R&B / Soul"         "Rap"                "Rock"              
[13] "Soul"               "Soundtrack"        
> levels(testData$Genre)
 [1] "Alternative"        "Christian & Gospel" "Country"           
 [4] "Dance"              "Electronic"         "Hip Hop / Rap"     
 [7] "Hip-Hop"            "Pop"                "Pop in Spanish"    
[10] "R&B / Soul"         "Rap"                "Rock"              
[13] "Soul"               "Soundtrack"        
> testData$Genre[id] <- NA
> # Predict
> rankPred <- predict(lmMod, testData)  
Error in model.frame.default(Terms, newdata, na.action = na.action, xlev = object$xlevels) : 
  factor Genre has new levels Electronic
Calls: predict -> predict.lm -> model.frame -> model.frame.default
Execution halted

0 个答案:

没有答案