tsfeatures()无意义错误(需要至少两个非NA值进行插值,但所有值均为非NA)

时间:2019-07-10 22:35:12

标签: r time-series

tsfeatures()approx()失败,因为至少需要两个非NA值进行插值。在我的时间序列或时间序列索引中找不到任何NA,我可以构造一个没有NA值,有序且唯一的索引的玩具示例,并且仍然可以重现错误。

以前似乎有很多关于R的tsfeatures()函数的问题,但是我找不到一个能解释为什么收到错误的问题:

Error in approx(idx, x[idx], tt, rule = 2) : 
  need at least two non-NA values to interpolate
# datetimes has type POSIXct
Browse[3]> class(datetimes[1:3])
[1] "POSIXct" "POSIXt"

# the first three date times are unique and ordered
Browse[3]> datetimes[1:3]
[1] "2019-06-18 19:59:48 PDT" "2019-06-18 20:00:48 PDT" "2019-06-18 20:01:48 PDT"

# create our time series
Browse[3]> temp = xts(x = c(0, 0, 0), order.by = datetimes[1:3])
Browse[3]> temp
                    [,1]
2019-06-18 19:59:48    0
2019-06-18 20:00:48    0
2019-06-18 20:01:48    0

# try to get our features:
Browse[3]> tsfeatures(temp)
Error in approx(idx, x[idx], tt, rule = 2) : 
  need at least two non-NA values to interpolate

编辑:我和我的队友发现,如果时间序列完全相同,则显示错误消息:

Browse[3]> tsfeatures(xts(x = c(1, 1, 1), order.by = datetimes[1:3]))
Error in approx(idx, x[idx], tt, rule = 2) : 
  need at least two non-NA values to interpolate

Browse[3]> tsfeatures(xts(x = c(1, 2, 1), order.by = datetimes[1:3]))
# A tibble: 1 x 16
  frequency nperiods seasonal_period    trend spike linearity curvature e_acf1 e_acf10 entropy x_acf1 x_acf10 diff1_acf1 diff1_acf10 diff2_acf1 diff2_acf10
      <dbl>    <dbl>           <dbl>    <dbl> <dbl>     <dbl>     <dbl>  <dbl>   <dbl>   <dbl>  <dbl>   <dbl>      <dbl>       <dbl>      <dbl>       <dbl>
1    0.0167        0          0.0167 1.11e-16 0.333 -6.04e-32  3.49e-32 -0.667      NA      NA -0.667      NA       -0.5        0.25         NA           0

有人可以解释错误消息吗?

1 个答案:

答案 0 :(得分:0)

该错误是由于package main import ( "fmt" "net/url" ) func main() { base, err := url.Parse("http://www.example.com") if err != nil { return } // Path params base.Path += "this will get automatically encoded" // Query params params := url.Values{} params.Add("q", "this will get encoded as well") base.RawQuery = params.Encode() fmt.Printf("Encoded URL is %q\n", base.String()) } 默认情况下会自动缩放时间序列。当您传递常数序列时,缩放将序列减少为tsfeatures() s。现在,在当前的github版本中已阻止了该问题-已修复here