Home > database >  Demand Classification using idclass() function in R not working
Demand Classification using idclass() function in R not working

Time:09-28

I am trying to run an idclass() on this data frame and there is an error, I am trying to classify the demand into 4 parts as Lumpy, Intermittent, Smooth, Erratic. I am not sure as to why there is an error. Can someone help me out and tell me what the error is about. The code is

library(tidyverse, magrittr) # data wrangling packages
library(foreach, future) # parallel functions
library(viridis, plotly) # visualizations packages
library(lubridate)
library(fpp3)
library(tsintermittent)
library(timetk)
library(modeltime)
library(modeltime.gluonts)
library(tidymodels)
library(modeltime.ensemble)
library(modeltime.resample)
library(readxl)
wide_dt <- readxl::read_xlsx("C:/X/X/FooD_Data.xlsx",sheet = 'Main')

str(wide_dt)
ts_cate_obj <- idclass(wide_dt, type = "SBC", outplot = "none")

The error which I encounter is: enter image description here

Attached is the dataframe on which I am performing idclass() function:

structure(list(week_date = structure(c(1451692800, 1452297600, 
1452902400, 1453507200, 1454112000, 1454716800, 1455321600, 1455926400, 
1456531200, 1457136000, 1457740800, 1458345600, 1458950400, 1459555200, 
1460160000, 1460764800, 1461369600, 1461974400, 1462579200, 1463184000, 
1463788800, 1464393600, 1464998400, 1465603200, 1466208000, 1466812800, 
1467417600, 1468022400, 1468627200, 1469232000, 1469836800, 1470441600, 
1471046400, 1471651200, 1472256000, 1472860800, 1473465600, 1474070400, 
1474675200, 1475280000, 1475884800, 1476489600, 1477094400, 1477699200, 
1478304000, 1478908800, 1479513600, 1480118400, 1480723200, 1481328000, 
1481932800, 1482537600, 1483142400, 1483747200, 1484352000, 1484956800, 
1485561600, 1486166400, 1486771200, 1487376000, 1487980800, 1488585600, 
1489190400, 1489795200, 1490400000, 1491004800, 1491609600, 1492214400, 
1492819200, 1493424000, 1494028800, 1494633600, 1495238400, 1495843200, 
1496448000, 1497052800, 1497657600, 1498262400, 1498867200, 1499472000, 
1500076800, 1500681600, 1501286400, 1501891200, 1502496000, 1503100800, 
1503705600, 1504310400, 1504915200, 1505520000, 1506124800, 1506729600, 
1507334400, 1507939200, 1508544000, 1509148800, 1509753600, 1510358400, 
1510963200, 1511568000, 1512172800, 1512777600, 1513382400, 1513987200, 
1514592000, 1515196800, 1515801600, 1516406400, 1517011200, 1517616000, 
1518220800, 1518825600, 1519430400, 1520035200, 1520640000, 1521244800, 
1521849600, 1522454400, 1523059200, 1523664000, 1524268800, 1524873600, 
1525478400, 1526083200, 1526688000, 1527292800, 1527897600, 1528502400, 
1529107200, 1529712000, 1530316800, 1530921600, 1531526400, 1532131200, 
1532736000, 1533340800, 1533945600, 1534550400, 1535155200, 1535760000, 
1536364800, 1536969600, 1537574400, 1538179200, 1538784000), class = c("POSIXct", 
"POSIXt"), tzone = "UTC"), `10_1062` = c(865, 782, 851, 1202, 
958, 1094, 1513, 1149, 1282, 1473, 1363, 1295, 1054, 648, 770, 
663, 1404, 757, 1310, 1241, 1417, 1310, 1553, 998, 971, 933, 
918, 783, 932, 1418, 944, 1269, 1203, 1242, 1081, 1081, 729, 
933, 743, 864, 825, 905, 809, 998, 1243, 1025, 918, 688, 838, 
404, 161, 701, 863, 339, 973, 783, 960, 1054, 1229, 1201, 1270, 
339, 824, 782, 944, 1067, 1039, 1067, 609, 663, 607, 906, 810, 
1053, 919, 715, 838, 634, 1012, 757, 824, 865, 987, 1080, 985, 
1068, 743, 1052, 892, 919, 919, 851, 1000, 634, 728, 1079, 365, 
863, 648, 1000, 917, 811, 500, 1053, 1256, 906, 825, 852, 1148, 
946, 864, 1012, 1810, 1634, 1094, 1283, 1093, 1067, 1160, 755, 
919, 879, 1148, 716, 661, 931, 919, 932, 674, 825, 1176, 1538, 
622, 782, 960, 918, 703, 513, 824, 1014, 890, 919, 1120, 945, 
958), `10_1109` = c(2672, 1864, 1161, 1376, 1511, 2105, 1916, 
1756, 1850, 1473, 1620, 1634, 1822, 1687, 1701, 1458, 1323, 1364, 
3496, 1808, 1687, 1770, 1473, 1323, 1054, 1189, 1511, 1311, 1405, 
2767, 1417, 1674, 1689, 1270, 431, 1270, 1309, 1216, 1431, 1473, 
2740, 1230, 1149, 1418, 2093, 2958, 2133, 1376, 1068, 1336, 905, 
1243, 1189, 311, 2456, 1527, 1473, 1607, 1216, 1094, 1431, 405, 
1243, 1257, 1392, 1419, 1336, 1094, 1297, 1715, 1417, 1295, 1121, 
1527, 1337, 1255, 837, 1122, 1215, 1364, 1066, 1255, 1446, 1120, 
906, 850, 1067, 1013, 1202, 1392, 1431, 1012, 1202, 892, 3565, 
1365, 512, 3996, 2672, 1040, 674, 837, 527, 1039, 1472, 3185, 
2470, 1148, 1499, 1795, 985, 1012, 1242, 1405, 1268, 850, 1417, 
1295, 3159, 2065, 1228, 1608, 1554, 1376, 1430, 1499, 1403, 1149, 
1877, 3781, 3752, 1688, 1444, 1594, 1554, 1621, 1390, 1850, 1513, 
1783, 1446, 1689, 1810, 1905, 1525), `10_1198` = c(269, 136, 
418, 243, 150, 176, 405, 526, 365, 175, 458, 350, 311, 323, 150, 
297, 298, 229, 458, 377, 337, 229, 271, 350, 204, 202, 393, 188, 
231, 269, 161, 176, 310, 229, 189, 134, 136, 256, 365, 231, 204, 
217, 149, 216, 351, 134, 202, 447, 283, 324, 242, 256, 190, 122, 
217, 379, 230, 269, 244, 244, 107, 243, 202, 298, 188, 217, 217, 
339, 270, 161, 378, 229, 366, 244, 352, 365, 501, 474, 338, 485, 
324, 230, 526, 474, 555, 499, 420, 446, 298, 325, 404, 608, 472, 
366, 121, 243, 352, 271, 419, 526, 512, 594, 215, 393, 338, 595, 
312, 190, 555, 406, 298, 339, 487, 486, 486, 366, 351, 784, 526, 
621, 458, 554, 595, 554, 648, 567, 553, 527, 472, 568, 419, 540, 
379, 379, 188, 432, 298, 431, 406, 688, 594, 325, 270, 540, 406
), `10_1207` = c(769, 458, 418, 459, 312, 296, 150, 203, 163, 
175, 217, 162, 121, 473, 202, 256, 325, 379, 177, 175, 269, 215, 
123, 189, 81, 80, 95, 176, 121, 121, 175, 271, 190, 217, 123, 
163, 41, 26, 13, 26, 53, 136, 96, 203, 94, 28, 41, 161, 566, 
716, 459, 959, 1122, 823, 95, 135, 190, 122, 96, 123, 94, 0, 
27, 26, 244, 54, 230, 123, 163, 134, 175, 81, 95, 107, 122, 136, 
42, 122, 107, 122, 203, 216, 175, 161, 161, 109, 108, 96, 107, 
161, 190, 202, 202, 216, 134, 256, 337, 258, 150, 352, 298, 339, 
351, 136, 473, 54, 54, 108, 69, 527, 458, 460, 204, 215, 148, 
135, 204, 177, 28, 269, 203, 94, 82, 136, 96, 230, 257, 215, 
580, 379, 433, 366, 81, 230, 257, 216, 351, 94, 82, 337, 175, 
135, 136, 284, 54), `10_1216` = c(54, 94, 96, 230, 189, 148, 
149, 285, 0, 107, 257, 107, 202, 176, 149, 13, 67, 0, 69, 53, 
109, 189, 136, 217, 107, 109, 94, 135, 68, 204, 150, 216, 149, 
148, 136, 162, 136, 107, 230, 177, 123, 107, 150, 163, 243, 95, 
161, 96, 161, 123, 82, 148, 121, 68, 96, 109, 80, 42, 188, 123, 
80, 41, 163, 121, 135, 149, 230, 148, 67, 230, 95, 161, 134, 
68, 123, 123, 149, 69, 13, 163, 162, 162, 107, 188, 162, 175, 
41, 229, 121, 82, 109, 204, 203, 242, 41, 123, 109, 176, 176, 
202, 204, 216, 26, 40, 82, 96, 108, 190, 96, 162, 203, 162, 188, 
149, 202, 162, 203, 229, 135, 162, 134, 148, 163, 190, 161, 190, 
203, 242, 148, 188, 189, 121, 177, 107, 215, 107, 216, 148, 230, 
162, 107, 189, 366, 230, 215)), class = c("tbl_df", "tbl", "data.frame"
), row.names = c(NA, -145L))

CodePudding user response:

We may need to remove the first column as it is a Datetime column idclass documentation says the data input can be

data - Time series dataset. Each column is a series. Alternatively this can be a single series.

library(tsintermittent)
idclass(wide_dt[-1], type = "SBC", outplot = "none")

-output

$idx.croston
[1] 1 2 3 5

$idx.sba
[1] 4

$idx.ses
NULL

$cv2
[1] 0.07514503 0.17175565 0.16710532 0.67086294 0.16199317

$p
[1] 1.000000 1.000000 1.000000 1.006944 1.013986

$summary
        Series
Croston      4
SBA          1
  • Related