r - 无法在 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
解决方案
推荐阅读
- python - 按 Int32 字段对 mongodb 查询进行排序
- node.js - 使用 cli 1.7 运行 Angular6 应用程序,出现错误无法读取 null 的属性“配置”
- javascript - vue路由器动态别名
- c++ - 将二进制文件转换为十六进制表示法
- ruby - 使用 rspec 和 capybara 测试 Jekyll 站点,在 rspec 开始时得到一个奇怪的竞赛案例
- python - python smtpd.SMTPServer:如何在 process_message 中发送回复消息?
- angularjs - 角JS。内存泄漏。此类型的对象未附加到 DOM
- ruby-on-rails - 如何在 ruby 中实现从后端应用程序加载图像的方法
- angularjs - AngularJS 的 ngMessages 模块中 $error 的长度
- sql - ORACLE:在多插入时不使用序列创建唯一值