tidyverts / feasts

Feature Extraction And Statistics for Time Series
https://feasts.tidyverts.org/
295 stars 23 forks source link

Some features missing #71

Closed robjhyndman closed 5 years ago

robjhyndman commented 5 years ago
library(tidyverse)
library(feasts)
#> Loading required package: fabletools
set.seed("20190910")
yahoo <- tsfeatures::yahoo_data() %>%
  as_tsibble() %>%
  mutate(
    Time = hms::hms(day = trunc(index) - 1L, 
                    hour = as.integer((round(24*(index-1))) %% 24))
  ) %>% 
  as_tsibble(index = Time, key=key) %>%
  select(Time, key, value)
#> Registered S3 method overwritten by 'xts':
#>   method     from
#>   as.zoo.xts zoo
#> Registered S3 method overwritten by 'quantmod':
#>   method            from
#>   as.zoo.data.frame zoo
#> Registered S3 methods overwritten by 'forecast':
#>   method             from    
#>   fitted.fracdiff    fracdiff
#>   residuals.fracdiff fracdiff
yahoo %>%
  filter(key %in% sample(yahoo$key, 3)) %>%
  features(value, features = list(
    feat_acf, 
    feat_spectral,
    n_flat_spots, 
    n_crossing_points,
    mean = ~ mean(., na.rm = TRUE),
    var = ~ var(., na.rm=TRUE),
    lumpiness = ~ var_tiled_var(., .period=24, .size=24), 
    ~ shift_level_max(., .period=24, .size=24),
    ~ shift_var_max(., .period=24, .size=24),
    ~ shift_kl_max(., .period=24, .size=48),
    ~ feat_stl(., s.window='periodic', robust=TRUE)
)) 
#> # A tibble: 3 x 20
#>   key    acf1 acf10 diff1_acf1 diff1_acf10 diff2_acf1 diff2_acf10
#>   <chr> <dbl> <dbl>      <dbl>       <dbl>      <dbl>       <dbl>
#> 1 dat0… 0.895 4.02       0.122       0.439     -0.257       0.621
#> 2 dat1… 0.969 8.82      -0.365       0.148     -0.605       0.382
#> 3 dat2… 0.415 0.942     -0.474       0.249     -0.665       0.513
#> # … with 13 more variables: season_acf1 <dbl>, spectral_entropy <dbl>,
#> #   n_flat_spots <int>, n_crossing_points <int>, mean <dbl>, var <dbl>,
#> #   lumpiness_var_tiled_var <dbl>, shift_level_max <dbl>,
#> #   shift_level_index <dbl>, shift_var_max <dbl>, shift_var_index <dbl>,
#> #   shift_kl_max <dbl>, shift_kl_index <dbl>

Created on 2019-09-10 by the reprex package (v0.3.0)

Here, the results from feat_spectral and feat_stl are missing.

mitchelloharawild commented 5 years ago

feat_spectral seems to be a bug, but feat_stl is missing the .period argument. There should be descriptive warnings for this issue: https://github.com/tidyverts/fabletools/issues/115

robjhyndman commented 5 years ago

Changing the feat_stl call to ~ feat_stl(., .period = 24, s.window = "periodic", robust = TRUE) makes no difference.

mitchelloharawild commented 5 years ago

Thanks, bug with NA handling fixed.