首页 > 解决方案 > 无法在 xy 坐标中绘制测试数据

问题描述

当我尝试绘制我的 mrl_model 时,我在 xy 坐标中收到一条错误消息。我对 R 的了解不足,无法解决此问题。有人可以帮我解决这个错误吗?

set.seed(1234)
ind <- sample(2, nrow(New_imports), replace = TRUE, prob = c(0.7, 0.3))
train.data <- New_imports[ind == 1, ]
test.data <- New_imports[ind == 2, ]
myFormula<-Price~.
mlr_model<-lm(myFormula, data=train.data)
print(mlr_model)

Call:
lm(formula = myFormula, data = train.data)

Coefficients:
        (Intercept)            symboling    normalized_losses      aspirationturbo         num_doorstwo  
         -44140.550             -206.852                8.956             1538.373              -83.248  
  body_stylehardtop  body_stylehatchback      body_stylesedan      body_stylewagon      drive_wheelsfwd  
         -12119.455           -11201.288           -10659.429           -10655.282            -1466.030  
    drive_wheelsrwd  engine_locationrear           wheel_base               length                width  
            702.577             2415.164               95.239              -89.271              792.837  
             height          curb_weight          engine_size    compression_ratio             peak_rpm  
            -13.931                3.403               45.880               91.632                1.333  
           city_mpg          highway_mpg  
           -221.142              155.776  

pred <-predict(mlr_model, New_imports=test.data)
plot(test.data$Price, pred, xlab = "Observed", ylab = "Prediction") 
Error in xy.coords(x, y, xlabel, ylabel, log) : 
  'x' and 'y' lengths differ

标签: r

解决方案


推荐阅读