A calendar is an external file that lists events for a time series, such as holidays. For example, we might consider this calendar:
library(knitr)
<- read.csv(system.file("extdata", "calendar.csv", package = "datarobot"))
calendar kable(calendar)
Date | Name |
---|---|
2018-01-01 | New Year’s Day |
2018-02-14 | Valentine’s Day |
2018-04-01 | April Fools |
2018-05-05 | Cinco de Mayo |
2018-07-04 | July 4th |
To explore calendars, let’s first connect to DataRobot. First, you must load the DataRobot R package library.
If you have set up a credentials file, library(datarobot)
will initialize a connection to DataRobot automatically. Otherwise, you can specify your endpoint
and apiToken
as in this example to connect to DataRobot directly. For more information on connecting to DataRobot, see the “Introduction to DataRobot” vignette.
library(datarobot)
<- "https://<YOUR DATAROBOT URL GOES HERE>/api/v2"
endpoint <- "<YOUR API TOKEN GOES HERE>"
apiToken ConnectToDataRobot(endpoint = endpoint, token = apiToken)
To create a DataRobot calendar from the CSV file, use CreateCalendar
:
<- CreateCalendar("calendar.csv", name = "holidays")
calendar print(calendar)
$name [1] “holidays”
$created [1] “2019-10-25T08:38:43.286329Z”
$calendarStartDate [1] “2018-01-01”
$numEventTypes [1] 5
$source [1] “calendar.csv”
$calendarEndDate [1] “2018-07-04”
$projectIds list()
$id [1] “5db2b48a34ccce7a4df1425c”
attr(,“class”) [1] “dataRobotCalendar”
You can retrieve a calendar from the list of calendars. This will list all calendars across all projects.
<- ListCalendars()
calendars <- calendars[[1]]
calendar print(calendar)
$name [1] “holidays”
$created [1] “2019-10-25T08:38:43.286329Z”
$calendarStartDate [1] “2018-01-01”
$numEventTypes [1] 5
$source [1] “calendar.csv”
$calendarEndDate [1] “2018-07-04”
$projectIds list()
$id [1] “5db2b48a34ccce7a4df1425c”
attr(,“class”) [1] “dataRobotCalendar”
You can rename the calendar using UpdateCalendar
.
<- UpdateCalendar(calendar, name = "newName")
newCalendar print(newCalendar)
$name [1] “newName”
$created [1] “2019-10-25T08:38:43.286329Z”
$calendarStartDate [1] “2018-01-01”
$numEventTypes [1] 5
$source [1] “calendar.csv”
$calendarEndDate [1] “2018-07-04”
$projectIds list()
$id [1] “5db2b48a34ccce7a4df1425c”
attr(,“class”) [1] “dataRobotCalendar”
The main point of having calendars is not to admire them, but to use them for time series modeling! To do this, make a datetime partition like you usually would and pass the calendar using the calendar
parameter.
<- SetupProject(timeSeriesData, projectName = "time series with calendar")
project <- CreateCalendar("calendar.csv")
cal <- CreateDatetimePartitionSpecification("date",
partition autopilotDataSelectionMethod = "duration",
useTimeSeries = TRUE,
calendar = cal)
StartProject(project, partition = partition, target = "target")
You can get the calendar associated with a project using GetCalendarFromProject
<- "59dab74bbd2a54035786bfc0"
projectId <- GetCalendarFromProject(project)
calendar print(calendar)
$name [1] “holidays”
$created [1] “2019-10-25T08:38:43.286329Z”
$calendarStartDate [1] “2018-01-01”
$numEventTypes [1] 5
$source [1] “calendar.csv”
$calendarEndDate [1] “2018-07-04”
$projectIds list()
$id [1] “5db2b48a34ccce7a4df1425c”
attr(,“class”) [1] “dataRobotCalendar”
To see all the projects associated with a particular calendar, look at the projectIds
parameter of the calendar.
print(calendar$projectIds)
[[1]] [1] “59dab74bbd2a54035786bfc0”