Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NNETAR don't work with business days time series #327

Closed
jcierocki opened this issue Mar 2, 2021 · 5 comments
Closed

NNETAR don't work with business days time series #327

jcierocki opened this issue Mar 2, 2021 · 5 comments

Comments

@jcierocki
Copy link

While I was trying to forecast financial time series (which are defined only for business days) I couldn't actually use NNETAR model from fable package.

  1. If I didn't fill the gaps I have always got:
    Warning: 1 error encountered for nnet
    [1] .data contains implicit gaps in time. You should check your data and convert implicit gaps into explicit missing values using tsibble::fill_gaps() if required.
  2. If I filled the gaps using fill_gaps() I have got:
    Warning: 1 error encountered for nnet
    [1] missing values in object
@mitchelloharawild
Copy link
Member

Please provide a minimal reproducible example that helps demonstrate the issues you're having.

@jcierocki
Copy link
Author

My tsibble:

head(my_df) %>% kable()

y date
18.423 2010-05-12
18.270 2010-05-13
18.168 2010-05-14
17.963 2010-05-17
18.064 2010-05-18
17.701 2010-05-19

my_df_fill <- fill_gaps(my_df)
head(my_df_fill) %>% kable()

y date
18.423 2010-05-12
18.270 2010-05-13
18.168 2010-05-14
NA 2010-05-15
NA 2010-05-16
17.963 2010-05-17

index(my_df)
date

Case 1:

nn_model <- my_df %>% model(nn = NNETAR(y ~ AR()))

Error:
Warning: 1 error encountered for nn
[1] .data contains implicit gaps in time. You should check your data and convert implicit gaps into explicit missing values using tsibble::fill_gaps() if required.

Case 2:

nn_model <- my_df_fill %>% model(nn = NNETAR(y ~ AR()))

Error:
Warning: 1 error encountered for nn
[1] missing values in object

@mitchelloharawild
Copy link
Member

Could you provide the data using dput(my_df), the first 6 rows isn't enough to reproduce this issue.

@jcierocki
Copy link
Author

Here is dput(my_df) result:
structure(list(y = c(18.423, 18.27, 18.168, 17.963, 18.064, 17.701, 16.939, 17.22, 17.527, 16.887, 18.117, 17.923, 17.912, 17.912, 17.84, 17.886, 17.502, 17.399, 17.349, 17.757, 17.912, 17.86, 17.998, 18.038, 18.034, 18.095, 18.295, 18.669, 18.423, 18.371, 18.168, 18.172, 18.013, 17.912, 17.912, 18.219, 18.117, 18.019, 18.351, 18.32, 18.368, 18.475, 19.037, 19.343, 18.935, 18.935, 18.833, 19.125, 18.94, 19.165, 19.549, 19.293, 19.866, 19.657, 19.402, 19.958, 20.162, 20.316, 20.418, 20.266, 20.343, 20.214, 19.549, 19.523, 19.293, 19.601, 19.851, 19.964, 19.702, 19.774, 19.699, 19.948, 20.558, 20.306, 19.98, 19.532, 19.67, 19.753, 19.879, 19.742, 19.721, 20.102, 20.348, 20.163, 20.795, 21.023, 20.848, 20.906, 21.091, 21.164, 20.954, 21.19, 21.368, 21.638, 21.638, 21.113, 20.795, 20.954, 21.011, 20.954, 21.586, 21.059, 21.348, 21.206, 21.201, 20.795, 20.665, 20.785, 20.638, 20.848, 20.296, 20.217, 20.323, 20.485, 20.296, 20.163, 20.058, 19.742, 19.48, 19.85, 20.111, 19.907, 20.033, 19.742, 19.796, 20.086, 20.159, 20.274, 19.985, 19.48, 19.075, 18.852, 19.427, 19.38, 19.233, 19.28, 18.818, 18.896, 18.889, 18.584, 18.48, 18.685, 19.085, 19.158, 19.105, 19.321, 19.374, 19.053, 18.954, 18.981, 19.137, 19.306, 19.269, 19.011, 18.9, 18.795, 18.795, 18.779, 18.785, 18.768, 18.716, 18.795, 18.733, 18.717, 19.059, 18.539, 18.48, 18.48, 18.037, 18.231, 18.111, 17.954, 17.954, 18.32, 18.688, 18.427, 18.421, 18.353, 18.32, 18.237, 18.342, 18.033, 18.216, 18.163, 18.163, 18.263, 18.8, 18.553, 18.584, 18.606, 18.427, 18.32, 18.374, 18.269, 18.19, 18.059, 17.768, 18.069, 18.163, 18.516, 18.427, 18.374, 18.316, 18.289, 18.074, 17.854, 18.311, 18.427, 18.4, 18.632, 18.231, 18.111, 18.006, 18.059, 18, 17.885, 18.48, 19.079, 18.874, 18.584, 18.754, 18.531, 18.559, 18.879, 18.742, 18.463, 18.742, 19.053, 19.165, 19.191, 19.321, 19.427, 19.191, 19.18, 19.148, 19.191, 19.137, 19.169, 18.927, 19.059, 19.116, 19.132, 19.259, 19.402, 19.69, 19.637, 19.796, 19.532, 19.543, 19.69, 19.349, 19.77, 20.217, 20.269, 20.527, 20.691, 20.163, 19.706, 20.169, 20.533, 20.512, 20.558, 20.891, 20.674, 20.533, 20.475, 20.479, 20.533, 20.585, 20.533, 20.611, 20.564, 20.323, 19.558, 19.584, 19.753, 20.163, 20.006, 20.285, 20.427, 20.323, 20.217, 19.853, 20.006, 19.954, 20.102, 20.163, 19.742, 20.033, 20.058, 20.102, 19.842, 19.991, 19.85, 19.696, 19.532, 19.653, 19.69, 19.584, 19.306, 19.48, 19.543, 19.574, 19.837, 19.902, 19.969, 19.748, 19.902, 19.954, 19.902, 19.895, 19.269, 18.847, 18.539, 18.421, 17.764, 16.963, 17.696, 18.163, 18.611, 18.374, 17.586, 17.637, 17.705, 17.358, 17.716, 17.586, 17.22, 18.216, 18.417, 18.688, 18.638, 18.347, 17.954, 17.637, 18.374, 18.611, 17.69, 17.954, 17.9, 18.18, 18.258, 18.216, 18.311, 18.138, 18.263, 17.606, 17.889, 17.79, 18.1, 18.107, 18.112, 17.941, 17.371, 16.755, 17.03, 17.246, 17.456, 18.221, 18.061, 18.146, 17.714, 17.885, 17.885, 17.877, 18.197, 17.969, 18.328, 18.767, 18.909, 18.413, 19.235, 19.239, 19.222, 19.08, 19.535, 19.245, 19.17, 19.075, 18.283, 17.969, 18.112, 17.997, 18.453, 18.283, 18.397, 18.3, 18.055, 17.701, 17.714, 17.706, 17.656, 17.673, 18.192, 18.272, 18.516, 18.795, 18.608, 18.55, 17.714, 18.008, 17.736, 17.935, 17.758, 17.77, 17.661, 17.646, 17.793, 17.714, 17.598, 17.741, 17.77, 17.656, 17.656, 17.598), date = structure(c(14741, 14742, 14743, 14746, 14747, 14748, 14749, 14750, 14753, 14754, 14755, 14756, 14757, 14760, 14761, 14762, 14764, 14767, 14768, 14769, 14770, 14771, 14774, 14775, 14776, 14777, 14778, 14781, 14782, 14783, 14784, 14785, 14788, 14789, 14790, 14791, 14792, 14795, 14796, 14797, 14798, 14799, 14802, 14803, 14804, 14805, 14806, 14809, 14810, 14811, 14812, 14813, 14816, 14817, 14818, 14819, 14820, 14823, 14824, 14825, 14826, 14827, 14830, 14831, 14832, 14833, 14834, 14837, 14838, 14839, 14840, 14841, 14844, 14845, 14846, 14847, 14848, 14851, 14852, 14853, 14854, 14855, 14858, 14859, 14860, 14861, 14862, 14865, 14866, 14867, 14868, 14869, 14872, 14873, 14874, 14875, 14876, 14879, 14880, 14881, 14882, 14883, 14886, 14887, 14888, 14889, 14890, 14893, 14894, 14895, 14896, 14897, 14900, 14901, 14902, 14903, 14904, 14907, 14908, 14909, 14910, 14911, 14915, 14916, 14917, 14918, 14921, 14922, 14923, 14925, 14928, 14929, 14930, 14931, 14932, 14935, 14936, 14937, 14938, 14939, 14942, 14943, 14944, 14945, 14946, 14949, 14950, 14951, 14952, 14953, 14956, 14957, 14958, 14959, 14960, 14963, 14964, 14965, 14966, 14970, 14971, 14972, 14973, 14974, 14977, 14978, 14979, 14981, 14984, 14985, 14986, 14987, 14988, 14991, 14992, 14993, 14994, 14995, 14998, 14999, 15000, 15001, 15002, 15005, 15006, 15007, 15008, 15009, 15012, 15013, 15014, 15015, 15016, 15019, 15020, 15021, 15022, 15023, 15026, 15027, 15028, 15029, 15030, 15033, 15034, 15035, 15036, 15037, 15040, 15041, 15042, 15043, 15044, 15047, 15048, 15049, 15050, 15051, 15054, 15055, 15056, 15057, 15058, 15061, 15062, 15063, 15064, 15065, 15068, 15069, 15070, 15071, 15072, 15075, 15076, 15077, 15078, 15079, 15082, 15083, 15084, 15085, 15090, 15091, 15092, 15093, 15096, 15098, 15099, 15100, 15103, 15104, 15105, 15106, 15107, 15110, 15111, 15112, 15113, 15114, 15117, 15118, 15119, 15120, 15121, 15124, 15125, 15126, 15127, 15128, 15131, 15132, 15133, 15134, 15135, 15138, 15139, 15140, 15141, 15142, 15145, 15146, 15147, 15149, 15152, 15153, 15154, 15155, 15156, 15159, 15160, 15161, 15162, 15163, 15166, 15167, 15168, 15169, 15170, 15173, 15174, 15175, 15176, 15177, 15180, 15181, 15182, 15183, 15184, 15187, 15188, 15189, 15190, 15191, 15194, 15195, 15196, 15197, 15198, 15202, 15203, 15204, 15205, 15208, 15209, 15210, 15211, 15212, 15215, 15216, 15217, 15218, 15219, 15222, 15223, 15224, 15225, 15226, 15229, 15230, 15231, 15232, 15233, 15236, 15237, 15238, 15239, 15240, 15243, 15244, 15245, 15246, 15247, 15250, 15251, 15252, 15253, 15254, 15257, 15258, 15259, 15260, 15261, 15264, 15265, 15266, 15267, 15268, 15271, 15272, 15273, 15274, 15275, 15278, 15280, 15281, 15282, 15285, 15286, 15287, 15288, 15292, 15293, 15294, 15295, 15296, 15299, 15300, 15301, 15302, 15303, 15306, 15307, 15308, 15309, 15310, 15313, 15314, 15315, 15316, 15317, 15320, 15321, 15322, 15323, 15324, 15327, 15328, 15329, 15330, 15331, 15335, 15336, 15337, 15338 ), class = "Date")), row.names = c(NA, -415L), key = structure(list( .rows = structure(list(1:415), ptype = integer(0), class = c("vctrs_list_of", "vctrs_vctr", "list"))), row.names = c(NA, -1L), class = c("tbl_df", "tbl", "data.frame")), index = structure("date", ordered = TRUE), index2 = "date", interval = structure(list( year = 0, quarter = 0, month = 0, week = 0, day = 1, hour = 0, minute = 0, second = 0, millisecond = 0, microsecond = 0, nanosecond = 0, unit = 0), .regular = TRUE, class = c("interval", "vctrs_rcrd", "vctrs_vctr")), class = c("tbl_ts", "tbl_df", "tbl", "data.frame"))

mitchelloharawild added a commit that referenced this issue May 6, 2021
@mitchelloharawild
Copy link
Member

Thanks for the data. I've made an improvement to the NNETAR() training method to make it more robust to missing values, however I believe there may be an issue with ar.yw() for this particular dataset - so it doesn't work in this example yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants