class_docstr: Wrapper for calling the `R forecast package
  <http://pkg.robjhyndman.com/forecast/>`_.
  
  In order to use it you need to install R and rpy2. You also need the R `forecast` package which
  can be installed by running:
  
      R -e 'install.packages(c("forecast", "nnfor"), repos="https://cloud.r-project.org")' # noqa
  
  Parameters
  ----------
  freq
      The granularity of the time series (e.g. '1H')
  prediction_length
      Number of time points to be predicted.
  method_name
      The method from rforecast to be used one of
      "ets", "arima", "tbats", "croston", "mlp", "thetaf".
  period
      The period to be used (this is called `frequency` in the R forecast
      package), result to a tentative reasonable default if not specified
      (for instance 24 for hourly freq '1H')
  trunc_length
      Maximum history length to feed to the model (some models become slow
      with very long series).
  params
      Parameters to be used when calling the forecast method default.
      For `output_type`, 'mean' and `quantiles` are supported (depending
      on the underlying R method).
class_docstr_tok: ["Wrapper","for","calling","the","`","R","forecast","package","<","http",":","\/\/pkg.robjhyndman.com\/forecast\/",">","`","_",".","In","order","to","use","it","you","need","to","install","R","and","rpy2",".","You","also","need","the","R","`","forecast","`","package","which","can","be","installed","by","running",":","R","-e","'install.packages","(","c","(","``","forecast","''",",","``","nnfor","''",")",",","repos=","''","https",":","\/\/cloud.r-project.org","''",")","'","#","noqa","Parameters","--","--","--","--","--","freq","The","granularity","of","the","time","series","(","e.g",".","'1H","'",")","prediction_length","Number","of","time","points","to","be","predicted",".","method_name","The","method","from","rforecast","to","be","used","one","of","``","ets","''",",","``","arima","''",",","``","tbats","''",",","``","croston","''",",","``","mlp","''",",","``","thetaf","''",".","period","The","period","to","be","used","(","this","is","called","`","frequency","`","in","the","R","forecast","package",")",",","result","to","a","tentative","reasonable","default","if","not","specified","(","for","instance","24","for","hourly","freq","'1H","'",")","trunc_length","Maximum","history","length","to","feed","to","the","model","(","some","models","become","slow","with","very","long","series",")",".","params","Parameters","to","be","used","when","calling","the","forecast","method","default",".","For","`","output_type","`",",","'mean","'","and","`","quantiles","`","are","supported","(","depending","on","the","underlying","R","method",")","."]
code: def _get_r_forecast(self, data: Dict) -> Dict:
      make_ts = self._stats_pkg.ts
      r_params = self._robjects.vectors.ListVector(self.params)
      vec = self._robjects.FloatVector(data["target"])
      ts = make_ts(vec, frequency=self.period)
  
      if (
          "feat_dynamic_real" in data
          and self.method_name == "fourier.arima.xreg"
      ):
          import rpy2.robjects.numpy2ri
  
          rpy2.robjects.numpy2ri.activate()
  
          data["feat_dynamic_real"] = np.transpose(
              data["feat_dynamic_real"]
          )
          nrow, ncol = data["feat_dynamic_real"].shape
          xreg_in = self._robjects.r.matrix(
              data["feat_dynamic_real"][: -self.prediction_length],
              nrow=nrow - self.prediction_length,
              ncol=ncol,
          )
          xreg_out = self._robjects.r.matrix(
              data["feat_dynamic_real"][-self.prediction_length :],
              nrow=self.prediction_length,
              ncol=ncol,
          )
          forecast = self._r_method(ts, r_params, xreg_in, xreg_out)
      else:
          forecast = self._r_method(ts, r_params)
  
      forecast_dict = dict(
          zip(forecast.names, map(unlist, list(forecast)))
      )
  
      if "quantiles" in self.params["output_types"]:
          upper_quantiles = [
              str(interval_to_quantile_level(interval, side="upper"))
              for interval in self.params["intervals"]
          ]
  
          lower_quantiles = [
              str(interval_to_quantile_level(interval, side="lower"))
              for interval in self.params["intervals"]
          ]
  
          forecast_dict["quantiles"] = dict(
              zip(
                  lower_quantiles + upper_quantiles,
                  forecast_dict["lower_quantiles"]
                  + forecast_dict["upper_quantiles"],
              )
          )
  
      return forecast_dict
  
file_path: gluonts/src/gluonts/ext/r_forecast/_univariate_predictor.py
imports: from typing import Dict, Optional, Any
  import numpy
  import pandas
  from gluonts.core.component import validated
  from gluonts.model.forecast import QuantileForecast
  from .None import RBasePredictor
  from .util import unlist, quantile_to_interval_level, interval_to_quantile_level
label_desc: Use image node_id 2 for calling the RForecastPredictor obj's underlying member method code with example usage: obj._get_r_forecast(data) and returns: forecast_dict