全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 R语言论坛
888 0
2019-11-28
用了caret包的train函数训练模型,然后用predict函数做预测,方法是偏最小二乘(设定了成分数14)。
请问我的预测结果myresult 出来的为什么是向量带一个数组呢?
> plsFit <- plsr(Solubility ~ ., data = trainingData
+                ,ncomp=14
+                ,method="kernelpls"
+                , scale = TRUE, center = TRUE)
>
> myresult <- predict(plsFit, solTestXtrans,ncomp=14)
>
> str(myresult)
num [1:316, 1, 1] 0.551 0.142 -0.493 0.506 0.106 ...
- attr(*, "dimnames")=List of 3
  ..$ : chr [1:316] "20" "21" "23" "25" ...
  ..$ : chr "Solubility"
  ..$ : chr "14 comps"

如果尝试把myresult转换为数据框,数据框的列名甚至是【 Solubility.14 comps】

> temp<-as.data.frame(myresult)
> str(temp)
'data.frame':        316 obs. of  1 variable:
$ Solubility.14 comps: num  0.551 0.142 -0.493 0.506 0.106 ...
> head(temp)
   Solubility.14 comps
20           0.5506072
21           0.1418576
23          -0.4927215
25           0.5059239
28           0.1064888
31           1.6412768

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群