|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectweka.classifiers.timeseries.core.TSLagMaker
public class TSLagMaker
A class for creating lagged versions of target variable(s) for use in time series forecasting. Uses the TimeseriesTranslate filter. Has options for creating averages of consecutive lagged variables (which can be useful for long lagged variables). Some polynomials of time are also created (if there is a time stamp), such as time^2 and time^3. Also creates cross products between time and the lagged and averaged lagged variables. If there is no date time stamp in the data then the user has the option of having an artificial time stamp created. Time stamps, real or otherwise, are used for modeling trends rather than using a differencing-based approach. Also has routines for dealing with a date timestamp - i.e. it can detect a monthly time period (because months are different lengths) and maps date time stamps to equal spaced time intervals. For example, in general, a date time stamp is remapped by subtracting the first observed value and adding this value divided by the constant delta (difference between consecutive steps) to the result. In the case of a detected monthly time period, the remapping involves subtracting the base year and then adding to this the number of the month within the current year plus twelve times the number of intervening years since the base year. Also has routines for adding new attributes derived from a date time stamp to the data - e.g. AM indicator, day of the week, month, quarter etc. In the case where there is no real data time stamp, the user may specify a nominal periodic variable (if one exists in the data). For example, month might be coded as a nominal value. In this case it can be specified as the primary periodic variable. The point is, that in all these cases (nominal periodic and date-derived periodics), we are able to determine what the value of these variables will be in future instances (as computed from the last known historic instance).
Nested Class Summary | |
---|---|
static class |
TSLagMaker.Periodicity
Enum defining periodicity |
Constructor Summary | |
---|---|
TSLagMaker()
|
Method Summary | |
---|---|
void |
addCustomPeriodic(java.lang.String customPeriodic)
Add a custom date-derived periodic |
double |
advanceSuppliedTimeValue(double valueToAdvance)
Utility method to advance a supplied time value by one unit according to the periodicity set for this LagMaker. |
void |
clearCustomPeriodics()
Clear all custom date-derived periodic fields. |
void |
clearLagHistories()
Clears any history accumulated in the lag creating filters. |
Instances |
createTimeLagCrossProducts(Instances insts)
|
double |
decrementSuppliedTimeValue(double valueToDecrement)
|
static TSLagMaker.Periodicity |
determinePeriodicity(Instances insts,
java.lang.String timeName)
Utility method that uses heuristics to identify the periodicity of the data with respect to a time stamp. |
boolean |
getAddAMIndicator()
Return true if an AM indicator attribute is to be created. |
boolean |
getAddDayOfMonth()
Return true if a day of the month attribute is to be created. |
boolean |
getAddDayOfWeek()
Return true if a day of the week attribute is to be created. |
boolean |
getAddMonthOfYear()
Returns true if a month of the year attribute is to be created. |
boolean |
getAddNumDaysInMonth()
Return true if a num days in the month attribute is to be created. |
boolean |
getAddQuarterOfYear()
Returns true if a quarter attribute is to be created. |
boolean |
getAddWeekendIndicator()
Returns true if a weekend indicator attribute is to be created. |
boolean |
getAdjustForTrends()
Returns true if we are adjusting for trends via a real or artificial time stamp. |
boolean |
getAdjustForVariance()
Returns true if we are adjusting for variance by taking the log of the target(s). |
double |
getArtificialTimeStartValue()
Returns the current value of the artificial time stamp. |
boolean |
getAverageConsecutiveLongLags()
Returns true if consecutive long lagged variables are to be averaged. |
int |
getAverageLagsAfter()
Return the point after which long lagged variables will be averaged. |
double |
getCurrentTimeStampValue()
Returns the current (i.e. |
java.util.Map<java.lang.String,java.util.ArrayList<CustomPeriodicTest>> |
getCustomPeriodics()
Get the date-derived custom periodic attributes in use. |
double |
getDeltaTime()
Return the difference between time values. |
java.util.List<java.lang.String> |
getFieldsToLag()
Get the names of the fields to create lagged variables for. |
java.lang.String |
getFineTuneLags()
Get the ranges used to fine tune the creation of lagged attributes. |
java.lang.String |
getLagRange()
Get the ranges used to fine tune lag selection |
int |
getMaxLag()
Get the maximum lag to create. |
int |
getMinLag()
Get the minimum lag to create. |
int |
getNumConsecutiveLongLagsToAverage()
Get the number of consecutive long lagged variables to average. |
java.lang.String[] |
getOptions()
Gets the current settings of the LagMaker. |
java.util.List<java.lang.String> |
getOverlayFields()
Get overlay fields |
TSLagMaker.Periodicity |
getPeriodicity()
Gets the Periodicity representing the time stamp in use for this lag maker. |
java.lang.String |
getPrimaryPeriodicFieldName()
The name of the primary periodic attribute or null if one hasn't been specified. |
java.lang.String |
getTimeStampField()
Get the name of the time stamp field. |
Instances |
getTransformedData(Instances insts)
Creates a transformed data set based on the user's settings |
void |
incrementArtificialTimeValue(int increment)
Increment the artificial time value with the supplied incrememt value. |
boolean |
isUsingAnArtificialTimeIndex()
Returns true if an artificial time index is in use. |
java.util.Enumeration<Option> |
listOptions()
Returns an enumeration describing the available options. |
Instance |
processInstance(Instance source,
boolean incrementTime,
boolean setAnyPeriodic)
|
Instance |
processInstance(Instance source,
boolean incrementTime,
boolean setAnyPeriodic,
boolean temporary)
Process an instance in the original format and produce a transformed instance as output. |
Instance |
processInstancePreview(Instance source,
boolean incrementTime,
boolean setAnyPeriodic)
|
void |
reset()
Reset the lag maker. |
void |
setAddAMIndicator(boolean am)
Set whether to create an AM indicator attribute. |
void |
setAddDayOfMonth(boolean d)
Set whether to create a day of the month attribute. |
void |
setAddDayOfWeek(boolean d)
Set whether to create a day of the week attribute. |
void |
setAddMonthOfYear(boolean m)
Set whether to create a month of the year attribute. |
void |
setAddNumDaysInMonth(boolean d)
Set whether to create a numeric attribute that holds the number of days in the month. |
void |
setAddQuarterOfYear(boolean q)
Set whether to create a quarter attribute. |
void |
setAddWeekendIndicator(boolean w)
Set whether to create a weekend indicator attribute. |
void |
setAdjustForTrends(boolean a)
Set whether to adjust for trends or not. |
void |
setAdjustForVariance(boolean v)
Set whether to adjust for variance in the data by taking the log of the target(s). |
void |
setArtificialTimeStartValue(double value)
Set the starting value for the artificial time stamp. |
void |
setAverageConsecutiveLongLags(boolean avg)
Sets whether to average consecutive long lagged variables. |
void |
setAverageLagsAfter(int a)
Set at which point consecutive long lagged variables are to be averaged (default = 2, i.e. |
void |
setCustomPeriodics(java.util.Map<java.lang.String,java.util.ArrayList<CustomPeriodicTest>> custom)
Set the date-derived custom periodic fields to use/compute |
void |
setFieldsToLag(java.util.List<java.lang.String> names)
Set the names of the fields to create lagged variables for |
void |
setFineTuneLags(java.lang.String ranges)
Set ranges by which to fine-tune the creation of lagged attributes. |
void |
setLagRange(java.lang.String lagRange)
Set ranges to fine tune lag selection. |
void |
setMaxLag(int max)
Set the maximum lag to create (default = 12, i.e. |
void |
setMinLag(int min)
Set the minimum lag to create (default = 1, i.e. |
void |
setNumConsecutiveLongLagsToAverage(int c)
Set the number of long lagged variables to average for each averaged variable created (default = 2, e.g. |
void |
setOptions(java.lang.String[] options)
Parses a given list of options. |
void |
setOverlayFields(java.util.List<java.lang.String> overlayNames)
Set the names of fields in the data that are to be considered "overlay" fields - i.e. |
void |
setPrimaryPeriodicFieldName(java.lang.String p)
Set the name of a periodic attribute in the data. |
void |
setTimeStampField(java.lang.String name)
Set the name of the time stamp field in the data |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public TSLagMaker()
Method Detail |
---|
public void reset()
public java.util.Enumeration<Option> listOptions()
public void setOptions(java.lang.String[] options) throws java.lang.Exception
options
- the list of options as an array of strings
java.lang.Exception
- if an option is not supportedpublic java.lang.String[] getOptions()
public java.util.Map<java.lang.String,java.util.ArrayList<CustomPeriodicTest>> getCustomPeriodics()
public void addCustomPeriodic(java.lang.String customPeriodic)
customPeriodic
- the new custom date-derived periodic in textual
form.public void clearCustomPeriodics()
public void setCustomPeriodics(java.util.Map<java.lang.String,java.util.ArrayList<CustomPeriodicTest>> custom)
custom
- a Map, keyed by field name, of custom date-derived
periodic fields to use.public void setFieldsToLag(java.util.List<java.lang.String> names) throws java.lang.Exception
names
- a List of field names for which to create lagged
variables
java.lang.Exception
- if a problem occurspublic java.util.List<java.lang.String> getFieldsToLag()
public void setOverlayFields(java.util.List<java.lang.String> overlayNames)
overlayNames
- the names of the fields that are to be
considered "overlay" fieldspublic java.util.List<java.lang.String> getOverlayFields()
public void setTimeStampField(java.lang.String name)
name
- the name of the time stamp fieldpublic java.lang.String getTimeStampField()
public void setAdjustForTrends(boolean a)
a
- true if we are to adjust for trends via a real
or artificial time stamppublic boolean getAdjustForTrends()
public void setAdjustForVariance(boolean v)
v
- true to adjust for variance by taking the log of
the target(s).public boolean getAdjustForVariance()
public void setFineTuneLags(java.lang.String ranges)
ranges
- a list of ranges as a stringpublic java.lang.String getFineTuneLags()
public void setMinLag(int min)
min
- the minimum lag to createpublic int getMinLag()
public void setMaxLag(int max)
max
- the maximum lag to create.public int getMaxLag()
public void setLagRange(java.lang.String lagRange)
lagRange
- a set of ranges (e.g. 2,3,4,7-9).public java.lang.String getLagRange()
public void setAverageConsecutiveLongLags(boolean avg)
avg
- true if consecutive long lags are to be averaged.public boolean getAverageConsecutiveLongLags()
public void setAverageLagsAfter(int a)
a
- the point at which to start averaging consecutive long lagged
variables.public int getAverageLagsAfter()
public void setNumConsecutiveLongLagsToAverage(int c)
c
- the number of consecutive long lagged variables to
average.public int getNumConsecutiveLongLagsToAverage()
public void setPrimaryPeriodicFieldName(java.lang.String p)
p
- the name of the primary periodic attribute (if any) in
the data.public java.lang.String getPrimaryPeriodicFieldName()
public void setAddAMIndicator(boolean am)
am
- true if an AM indicator attribute is to be
created.public boolean getAddAMIndicator()
public void setAddDayOfWeek(boolean d)
d
- true if a day of the week attribute is to be
created.public boolean getAddDayOfWeek()
public void setAddDayOfMonth(boolean d)
d
- true if a day of the month attribute is to be created.public boolean getAddDayOfMonth()
public void setAddNumDaysInMonth(boolean d)
d
- true if a num days in month attribute is to be created.public boolean getAddNumDaysInMonth()
public void setAddWeekendIndicator(boolean w)
w
- true if a weekend indicator attribute is to
be created.public boolean getAddWeekendIndicator()
public void setAddMonthOfYear(boolean m)
m
- true if a month of the year attribute is to be
created.public boolean getAddMonthOfYear()
public void setAddQuarterOfYear(boolean q)
q
- true if a quarter attribute is to be added.public boolean getAddQuarterOfYear()
public boolean isUsingAnArtificialTimeIndex()
public void setArtificialTimeStartValue(double value) throws java.lang.Exception
value
- the value to initialize the artificial time stamp with.
java.lang.Exception
- if an artificial time stamp is not being used.public double getArtificialTimeStartValue() throws java.lang.Exception
java.lang.Exception
- if an artificial time stamp is not being used.public double getCurrentTimeStampValue() throws java.lang.Exception
java.lang.Exception
- if the lag maker is not adjusting for trends or
no time stamp attribute has been specified.public void incrementArtificialTimeValue(int increment)
increment
- the value to increment by.public double getDeltaTime()
public TSLagMaker.Periodicity getPeriodicity()
public Instances createTimeLagCrossProducts(Instances insts) throws java.lang.Exception
java.lang.Exception
public static TSLagMaker.Periodicity determinePeriodicity(Instances insts, java.lang.String timeName)
insts
- the instances to determine the periodicity fromtimeName
- the name of the time stamp attribute
public Instances getTransformedData(Instances insts) throws java.lang.Exception
insts
- the instances to transform
java.lang.Exception
- if a problem occurs during the creation of lagged
and auxiliary attributes.public Instance processInstance(Instance source, boolean incrementTime, boolean setAnyPeriodic) throws java.lang.Exception
java.lang.Exception
public Instance processInstancePreview(Instance source, boolean incrementTime, boolean setAnyPeriodic) throws java.lang.Exception
java.lang.Exception
public Instance processInstance(Instance source, boolean incrementTime, boolean setAnyPeriodic, boolean temporary) throws java.lang.Exception
source
- an instance in original formatincrementTime
- true if any time stamp value should be incremented based
on the time stamp value from the last instance seen and set in the outputted instancesetAnyPeriodic
- true if any user-specified periodic value should be set
in the transformed instance based on the value from the last instance seen.
java.lang.Exception
- if something goes wrong.public void clearLagHistories() throws java.lang.Exception
java.lang.Exception
- if something goes wrong.public double advanceSuppliedTimeValue(double valueToAdvance)
valueToAdvance
- the time value to advance
public double decrementSuppliedTimeValue(double valueToDecrement)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |