Reduce the size of a full direct forecasting model by removing the training data from the model. You can use a compact model to improve memory efficiency.
Load the sample file TemperatureData.csv
, which contains average daily temperatures from January 2015 through July 2016. Read the file into a table. Observe the first eight observations in the table.
Year Month Day TemperatureF
____ ___________ ___ ____________
2015 {'January'} 1 23
2015 {'January'} 2 31
2015 {'January'} 3 25
2015 {'January'} 4 39
2015 {'January'} 5 29
2015 {'January'} 6 12
2015 {'January'} 7 10
2015 {'January'} 8 4
For this example, use a subset of the temperature data that omits the first 100 observations.
Create a datetime
variable t
that contains the year, month, and day information for each observation in Tbl
. Then, use t
to convert Tbl
into a timetable.
Plot the temperature values in Tbl
over time.
Create a full direct forecasting model by using the data in Tbl
. Train the model using a decision tree learner. All three of the predictors (Year
, Month
, and Day
) are leading predictors because their future values are known. To create new predictors by shifting the leading predictor and response variables backward in time, specify the leading predictor lags and the response variable lags.
Mdl =
DirectForecaster
Horizon: 1
ResponseLags: [1 2 3 4 5 6 7]
LeadingPredictors: [1 2 3]
LeadingPredictorLags: {[0 1] [0 1] [0 1 2 3 4 5 6 7]}
ResponseName: 'TemperatureF'
PredictorNames: {'Year' 'Month' 'Day'}
CategoricalPredictors: 2
Learners: {[1×1 classreg.learning.regr.CompactRegressionTree]}
MaxLag: 7
NumObservations: 465
Properties, Methods
Mdl
is a DirectForecaster
object. By default, the horizon is one step ahead. That is, Mdl
predicts a value that is one step into the future.
Reduce the size of the model by using the compact
object function.
compactMdl =
CompactDirectForecaster
Horizon: 1
ResponseLags: [1 2 3 4 5 6 7]
LeadingPredictors: [1 2 3]
LeadingPredictorLags: {[0 1] [0 1] [0 1 2 3 4 5 6 7]}
ResponseName: 'TemperatureF'
PredictorNames: {'Year' 'Month' 'Day'}
CategoricalPredictors: 2
Learners: {[1×1 classreg.learning.regr.CompactRegressionTree]}
MaxLag: 7
Properties, Methods
compactMdl
is a CompactDirectForecaster
model object. compactMdl
contains fewer properties than the full model Mdl
.
Display the amount of memory used by each direct forecasting model.
Name Size Bytes Class Attributes
Mdl 1x1 119523 timeseries.forecaster.DirectForecaster
compactMdl 1x1 43983 timeseries.forecaster.CompactDirectForecaster
The full model is larger than the compact model.