使用插入符包阻止错误

时间:2018-03-04 13:14:49

标签: r

我想要功能重要性。所以我使用插入符号包作为我的数据集:

    > dput(head(data,100))
structure(list(Store = c(3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), Sales = c(8314, 
8977, 7610, 8864, 8107, 0, 3878, 5080, 5702, 5414, 5600, 5798, 
0, 4258, 6679, 7909, 8663, 8625, 9462, 0, 4011, 6316, 6613, 6347, 
6180, 6736, 0, 4482, 8149, 7450, 8311, 13261, 10243, 0, 5156, 
6222, 5763, 5448, 6757, 5840, 0, 3891, 8074, 7537, 8524, 9780, 
10818, 0, 4687, 6181, 5656, 6440, 7127, 6567, 0, 4622, 9685, 
0, 9590, 10455, 11594, 0, 4542, 7421, 6475, 5589, 6443, 0, 0, 
4613, 7349, 7682, 8226, 8728, 10040, 0, 4149, 7515, 0, 7003, 
6043, 5797, 0, 6024, 9083, 7705, 9046, 8719, 9488, 0, 6564, 0, 
9971, 9484, 8758, 9447, 0, 4373, 5376, 5570), DayOfWeek = c(5, 
4, 3, 2, 1, 7, 6, 5, 4, 3, 2, 1, 7, 6, 5, 4, 3, 2, 1, 7, 6, 5, 
4, 3, 2, 1, 7, 6, 5, 4, 3, 2, 1, 7, 6, 5, 4, 3, 2, 1, 7, 6, 5,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 3, 2, 1, 4, 3, 2, 1, 4, 3, 2, 1, 4, 3, 
2, 1, 4, 3, 2, 1, 4, 3, 2, 1, 4, 3, 2, 1), SchoolHoliday = structure(c(2L, 
2L, 2L, 2L, 2L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 2L, 2L, 2L, 
2L, 2L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L), .Label = c("0", "1"), class = "factor"), DateYear = c(2015, 
2015, 2015, 2015, 2015, 2015, 2015, 2015, 2015, 2015, 2015, 2015, 
2015, 2015, 2015, 2015, 2015, 2015, 2015, 2015, 2015, 2015, 2015, 
2015, 2015, 2015, 2015, 2015, 2015, 2015, 2015, 2015, 2015, 2015, 
2015, 2015, 2015, 2015, 2015, 2015, 2015, 2015, 2015, 2015, 2015, 
2015, 2015, 2015, 2015, 2015, 2015, 2015, 2015, 2015, 2015, 2015, 
2015, 2015, 2015, 2015, 2015, 2015, 2015, 2015, 2015, 2015, 2015, 
2015, 2015, 2015, 2015, 2015, 2015, 2015, 2015, 2015, 2015, 2015, 
2015, 2015, 2015, 2015, 2015, 2015, 2015, 2015, 2015, 2015, 2015, 
2015, 2015, 2015, 2015, 2015, 2015, 2015, 2015, 2015, 2015, 2015
), DateMonth = c(7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 6, 
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 
6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 
4), DateDay = c(31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 
19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 
2, 1, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 
16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 31, 30, 
29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 
13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 30, 29, 28, 27, 26, 
25, 24, 23), DateWeek = c(30, 30, 30, 30, 30, 29, 29, 29, 29, 
29, 29, 29, 28, 28, 28, 28, 28, 28, 28, 27, 27, 27, 27, 27, 27, 
27, 26, 26, 26, 26, 26, 26, 26, 25, 25, 25, 25, 25, 25, 25, 24, 
24, 24, 24, 24, 24, 24, 23, 23, 23, 23, 23, 23, 23, 22, 22, 22, 
22, 22, 22, 22, 21, 21, 21, 21, 21, 21, 21, 20, 20, 20, 20, 20, 
20, 20, 19, 19, 19, 19, 19, 19, 19, 18, 18, 18, 18, 18, 18, 18, 
17, 17, 17, 17, 17, 17, 17, 16, 16, 16, 16), StoreType = c(3, 
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3), CompetitionOpen = c(103, 
103, 103, 103, 103, 103, 103, 103, 103, 103, 103, 103, 103, 103, 
103, 103, 103, 103, 103, 103, 103, 103, 103, 103, 103, 103, 103, 
103, 103, 103, 103, 102, 102, 102, 102, 102, 102, 102, 102, 102, 
102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 
102, 102, 102, 102, 102, 102, 102, 102, 101, 101, 101, 101, 101, 
101, 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, 
101, 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, 
100, 100, 100, 100, 100, 100, 100, 100), PromoOpen = c(52, 52, 
52, 52, 52, 51.75, 51.75, 51.75, 51.75, 51.75, 51.75, 51.75, 
51.5, 51.5, 51.5, 51.5, 51.5, 51.5, 51.5, 51.25, 51.25, 51.25, 
51.25, 51.25, 51.25, 51.25, 51, 51, 51, 51, 51, 51, 51, 50.75, 
50.75, 50.75, 50.75, 50.75, 50.75, 50.75, 50.5, 50.5, 50.5, 50.5, 
50.5, 50.5, 50.5, 50.25, 50.25, 50.25, 50.25, 50.25, 50.25, 50.25, 
50, 50, 50, 50, 50, 50, 50, 49.75, 49.75, 49.75, 49.75, 49.75, 
49.75, 49.75, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.25, 
49.25, 49.25, 49.25, 49.25, 49.25, 49.25, 49, 49, 49, 49, 49, 
49, 49, 48.75, 48.75, 48.75, 48.75, 48.75, 48.75, 48.75, 48.5, 
48.5, 48.5, 48.5), IspromoinSales = c(1, 1, 1, 1, 1, 1, 1, 1, 
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
1, 1, 1, 1, 1, 1, 1, 1)), .Names = c("Store", "Sales", "DayOfWeek", 
"Open", "Promo", "StateHoliday", "SchoolHoliday", "DateYear", 
"DateMonth", "DateDay", "DateWeek", "StoreType", "CompetitionOpen", 
"PromoOpen", "IspromoinSales"), sorted = "Store", class = c("data.table", 
"data.frame"), row.names = c(NA, -100L), .internal.selfref = <pointer: 0x000000000c610788>)

然后我编写此代码来进行功能训练:

> library(caret)
> set.seed(42)
> model_rf <- caret::train(Sales ~ .,
+                          data = data[,-1],
+                          method = "rf",
+                          trControl = trainControl(method = "repeatedcv", 
+                                                   number = 10, 
+                                                   repeats = 5, 
+                                                   verboseIter = FALSE))

但看看我得到了什么:

  

出了点问题;缺少所有RMSE指标值:             RMSE Rsquared MAE
       闵。 :NA Min。 :NA Min。 :NA
       1 Qu。:NA 1st Qu。:NA 1st Qu。:NA
       中位数:NA中位数:NA中位数:NA
       平均值:NaN平均值:NaN平均值:NaN
       第三曲:NA第三曲:NA第三曲:NA
       最大。 :NA Max。 :NA Max。 :NA
       NA&#39; s:3 NA&#39; s:3 NA&#39; s:3
      错误:停止

     

另外:有50个或更多警告(使用警告()来查看   第一次50)

我该如何删除并获得正确的结果?

谢谢你!

0 个答案:

没有答案