2

I am trying to understand how to use reticulate for pyts. The package loads and runs fine but I can't seem to find how to insert the time-series into python chunk. I get the following result NameError: name 'x' is not defined. I also dont know how to extract X_gasf and X_gadf into R.

require(reticulate); require(tibble)
pyts<- reticulate::import("pyts", convert = TRUE)
pytsImage<-reticulate::import("pyts.image", convert = TRUE)
x <- tibble(values = sin(-10:6))

repl_python()
from pyts.image import GramianAngularField
from sklearn.pipeline import make_pipeline
gasf = GramianAngularField(image_size=17, method='summation')
X_gasf = gasf.fit_transform(x)
gadf = GramianAngularField(image_size=17, method='difference')
X_gadf = gadf.fit_transform(x)
exit

py$X_gasf
py$X_gadf
user3647872
  • 85
  • 1
  • 9

1 Answers1

0

I think I got it work by changing the variable to a simple time series and inserting "r.x" instead of "x" in the Python Chunk. Maybe the transpose is unnecessary at the end but I have to look into that.

require(reticulate); require(tibble)
pyts<- reticulate::import("pyts", convert = TRUE)
pytsImage<-reticulate::import("pyts.image", convert = TRUE)
x<-t(as.ts(sin(-10:6)))

repl_python()
from pyts.image import GramianAngularField
from sklearn.pipeline import make_pipeline
gasf = GramianAngularField(image_size=15, method='summation')
X_gasf = gasf.fit_transform(r.x)
gadf = GramianAngularField(image_size=15, method='difference')
X_gadf = gadf.fit_transform(r.x)
exit 

X_GASF<-t(matrix(py$X_gasf,ncol=length(py$X_gasf[,,1])))
X_GADF<-t(matrix(py$X_gadf,ncol=length(py$X_gadf[,,1])))
user3647872
  • 85
  • 1
  • 9