Types and Functions

Index

Descriptions

AMLPipelineBase.BaseFilters.ImputerType
Imputer(
   Dict(
      # Imputation strategy.
      # Statistic that takes a vector such as mean or median.
      :strategy => mean
   )
)

Imputes NaN values from Float64 features.

Implements fit! and transform.

source
AMLPipelineBase.BaseFilters.OneHotEncoderType
OneHotEncoder(Dict(
   # Nominal columns
   :nominal_columns => Int[],

   # Nominal column values map. Key is column index, value is list of
   # possible values for that column.
   :nominal_column_values_map => Dict{Int,Any}()
))

Transforms myinstances with nominal features into one-hot form and coerces the instance matrix to be of element type Float64.

Implements fit! and transform.

source
AMLPipelineBase.BaseFilters.WrapperType
Wrapper(
   default_args = Dict(
      :name => "ohe-wrapper",
      # Transformer to call.
      :transformer => OneHotEncoder(),
      # Transformer args.
      :transformer_args => Dict()
   )
)

Wraps around a transformer.

Implements fit! and transform.

source
AMLPipelineBase.BaseFilters.createtransformerFunction
createtransformer(prototype::Transformer, args=Dict())

Create transformer

  • prototype: prototype transformer to base new transformer on
  • options: additional options to override prototype's options

Returns: new transformer.

source
AMLPipelineBase.DecisionTreeLearners.PrunedTreeType
PrunedTree(
  Dict(
    :purity_threshold => 1.0,
    :max_depth => -1,
    :min_samples_leaf => 1,
    :min_samples_split => 2,
    :min_purity_increase => 0.0
  )
)

Decision tree classifier. See DecisionTree.jl's documentation

Hyperparmeters:

  • :purity_threshold => 1.0 (merge leaves having >=thresh combined purity)
  • :max_depth => -1 (maximum depth of the decision tree)
  • :min_samples_leaf => 1 (the minimum number of samples each leaf needs to have)
  • :min_samples_split => 2 (the minimum number of samples in needed for a split)
  • :min_purity_increase => 0.0 (minimum purity needed for a split)

Implements fit!, transform!

source
AMLPipelineBase.DecisionTreeLearners.RandomForestType
RandomForest(
  Dict(
    :output => :class,
    :num_subfeatures => 0,
    :num_trees => 10,
    :partial_sampling => 0.7,
    :max_depth => -1
  )
)

Random forest classification. See DecisionTree.jl's documentation

Hyperparmeters:

  • :num_subfeatures => 0 (number of features to consider at random per split)
  • :num_trees => 10 (number of trees to train)
  • :partial_sampling => 0.7 (fraction of samples to train each tree on)
  • :max_depth => -1 (maximum depth of the decision trees)
  • :min_samples_leaf => 1 (the minimum number of samples each leaf needs to have)
  • :min_samples_split => 2 (the minimum number of samples in needed for a split)
  • :min_purity_increase => 0.0 (minimum purity needed for a split)

Implements fit!, transform!

source
AMLPipelineBase.EnsembleMethods.BestLearnerType
BestLearner(
   Dict(
      # Output to train against
      # (:class).
      :output => :class,
      # Function to return partitions of instance indices.
      :partition_generator => (instances, labels) -> kfold(size(instances, 1), 5),
      # Function that selects the best learner by index.
      # Arg learner_partition_scores is a (learner, partition) score matrix.
      :selection_function => (learner_partition_scores) -> findmax(mean(learner_partition_scores, dims=2))[2],      
      # Score type returned by score() using respective output.
      :score_type => Real,
      # Candidate learners.
      :learners => [PrunedTree(), Adaboost(), RandomForest()],
      # Options grid for learners, to search through by BestLearner.
      # Format is [learner_1_options, learner_2_options, ...]
      # where learner_options is same as a learner's options but
      # with a list of values instead of scalar.
      :learner_options_grid => nothing
   )
)

Selects best learner from the set by performing a grid search on learners if grid option is indicated.

source
AMLPipelineBase.EnsembleMethods.StackEnsembleType
StackEnsemble(
   Dict(    
      # Output to train against
      # (:class).
      :output => :class,
      # Set of learners that produce feature space for stacker.
      :learners => [PrunedTree(), Adaboost(), RandomForest()],
      # Machine learner that trains on set of learners' outputs.
      :stacker => RandomForest(),
      # Proportion of training set left to train stacker itself.
      :stacker_training_proportion => 0.3,
      # Provide original features on top of learner outputs to stacker.
      :keep_original_features => false
   )
)

An ensemble where a 'stack' of learners is used for training and prediction.

source
AMLPipelineBase.EnsembleMethods.VoteEnsembleType
VoteEnsemble(
   Dict( 
      # Output to train against
      # (:class).
      :output => :class,
      # Learners in voting committee.
      :learners => [PrunedTree(), Adaboost(), RandomForest()]
   )
)

Set of machine learners employing majority vote to decide prediction.

Implements: fit!, transform!

source
AMLPipelineBase.AbsTypes.fit!Method
fit!(bls::BestLearner, instances::DataFrame, labels::Vector)

Training phase:

  • obtain learners as is if grid option is not present
  • generate learners if grid option is present
  • foreach prototype learner, generate learners with specific options found in grid
  • generate partitions
  • train each learner on each partition and obtain validation output
source
AMLPipelineBase.AbsTypes.fit!Method
fit!(se::StackEnsemble, instances::DataFrame, labels::Vector)

Training phase of the stack of learners.

  • perform holdout to obtain indices for
  • partition learner and stacker training sets
  • partition training set for learners and stacker
  • train all learners
  • train stacker on learners' outputs
  • build final model from the trained learners
source
TSML.MLBaseWrapper.StandardScalerType
StandardScaler(
   Dict( 
      :impl_args => Dict(
          :center => true,
          :scale => true
      )
   )
)

Standardizes each feature using (X - mean) / stddev. Will produce NaN if standard deviation is zero.

source
AMLPipelineBase.AbsTypes.fit!Function
fit!(st::StandardScaler, features::T, labels::Vector=[]) where {T<:Union{Vector,Matrix,DataFrame}}

Compute the parameters to center and scale.

source
TSML.Monotonicers.MonotonicerType
Monotonicer()

Monotonic filter to detect and normalize two types of dataset:

  • daily monotonic
  • entirely non-decreasing/non-increasing data

Example:

fname = joinpath(dirname(pathof(TSML)),"../data/testdata.csv")
csvfilter = CSVDateValReader(Dict(:filename=>fname,:dateformat=>"dd/mm/yyyy HH:MM"))
valgator = DateValgator(Dict(:dateinterval=>Dates.Hour(1)))
valnner = DateValNNer(Dict(:dateinterval=>Dates.Hour(1)))
stfier = Statifier(Dict(:processmissing=>true))
mono = Monotonicer(Dict())

mypipeline = @pipeline csvfilter |> valgator |> mono |> stfier
result = fit_transform!(mypipeline)

Implements: fit!, transform!

source
AMLPipelineBase.AbsTypes.transform!Method
transform!(st::Monotonicer, features::T) where {T<:Union{Vector,Matrix,DataFrame}}

Normalize monotonic or daily monotonic data by taking the diffs and counting the flips.

source
TSML.Normalizers.NormalizerType
Normalizer(Dict(
   :method => :zscore
))

Transforms continuous features into normalized form such as zscore, unitrange, square-root, log, pca, ppca with parameter:

  • :method => :zscore or :unitrange or :sqrt or :log or pca or ppca or fa
  • :zscore => standard z-score with centering and scaling
  • :unitrange => unit range normalization with centering and scaling
  • :sqrt => square-root transform
  • :pca => principal component analysis transform
  • :ppca => probabilistic pca
  • :fa => factor analysis
  • :log => log transform

Example:

function generatedf()
    Random.seed!(123)
    gdate = DateTime(2014,1,1):Dates.Minute(15):DateTime(2016,1,1)
    gval1 = rand(length(gdate))
    gval2 = rand(length(gdate))
    gval3 = rand(length(gdate))
    X = DataFrame(Date=gdate,Value1=gval1,Value2=gval2,Value3=gval3)
    X
end

X = generatedf()
norm = Normalizer(Dict(:method => :zscore))
fit!(norm,X)
res=transform!(norm,X)

Implements: fit!, transform!

source
TSML.Outliernicers.OutliernicerType
Outliernicer(Dict(
   :dateinterval => Dates.Hour(1),
   :nnsize => 1,
   :missdirection => :symmetric,
   :scale => 1.25
))

Detects outliers below or above (median-scaleiqr,median+scaleiqr) and calls DateValNNer to replace them with nearest neighbors.

Example:

fname = joinpath(dirname(pathof(TSML)),"../data/testdata.csv")
csvfilter = CSVDateValReader(Dict(:filename=>fname,:dateformat=>"dd/mm/yyyy HH:MM"))
valgator = DateValgator(Dict(:dateinterval=>Dates.Hour(1)))
valnner = DateValNNer(Dict(:dateinterval=>Dates.Hour(1)))
stfier = Statifier(Dict(:processmissing=>true))
mono = Monotonicer(Dict())
outliernicer = Outliernicer(Dict(:dateinterval=>Dates.Hour(1)))

mpipeline = @pipeline csvfilter |> valgator |> mono |> valnner |> outliernicer |> stfier
results = fit_transform!(mpipeline)

Implements: fit!, transform!

source
AMLPipelineBase.AbsTypes.transform!Method
transform!(st::Outliernicer, features::T) where {T<:Union{Vector,Matrix,DataFrame}}

Locate outliers based on IQR factor and calls DateValNNer to replace them with nearest neighbors.

source
AMLPipelineBase.Pipelines.ComboPipelineType
ComboPipeline(machs::Vector{T}) where {T<:Machine}

Feature union pipeline which iteratively calls fit_transform of each element and concatenate their output into one dataframe.

Implements fit! and transform!.

source
AMLPipelineBase.Pipelines.PipelineType
Pipeline(machs::Vector{<:Machine},args::Dict=Dict())

Linear pipeline which iteratively calls and passes the result of fit_transform to the succeeding elements in the pipeline.

Implements fit! and transform!.

source
TSML.Plotters.PlotterType

Plotter( Dict( :interactive => false, :pdfoutput => true ) )

Plots a TS by default but performs interactive plotting if specified during instance creation.

  • :interactive => boolean to indicate whether to use interactive plotting with false as default
  • :pdfoutput => boolean to indicate whether ouput will be saved as pdf with false as default

Example:

csvfilter = CSVDateValReader(Dict(:filename=>fname,:dateformat=>"dd/mm/yyyy HH:MM")) pltr = Plotter(Dict(:interactive => false))

mpipeline = @pipeline csvfilter |> pltr myplot = fit_transform!(mpipeline)

Implements: fit!, transform!

source
TSML.Statifiers.StatifierType
Statifier(Dict(
   :processmissing => true
))

Outputs summary statistics such as mean, median, quartile, entropy, kurtosis, skewness, etc. with parameter:

  • :processmissing => boolean to indicate whether to include missing data stats.

Example:

dt=[missing;rand(1:10,3);missing;missing;missing;rand(1:5,3)]
dat = DataFrame(Date= DateTime(2017,12,31,1):Dates.Hour(1):DateTime(2017,12,31,10) |> collect,
                Value = dt)

statfier = Statifier(Dict(:processmissing=>false))

fit!(statfier,dat)
results=transform!(statfier,dat)

Implements: fit!, transform!

source
TSML.TSClassifiers.TSClassifierType
TSClassifier(
   Dict(
      # training directory
      :trdirectory => "",
      :tstdirectory => "",
      :modeldirectory => "",
      :feature_range => 7:20,
      :juliarfmodelname => "juliarfmodel.serialized",
      # Output to train against
      # (:class).
      :output => :class,
      # Options specific to this implementation.
      :impl_args => Dict(
         # Merge leaves having >= purity_threshold CombineMLd purity.
         :purity_threshold => 1.0,
         # Maximum depth of the decision tree (default: no maximum).
         :max_depth => -1,
         # Minimum number of samples each leaf needs to have.
         :min_samples_leaf => 1,
         # Minimum number of samples in needed for a split.
         :min_samples_split => 2,
         # Minimum purity needed for a split.
         :min_purity_increase => 0.0
      )
   )
)

Given a bunch of time-series with specific types. Get the statistical features of each, use these as inputs to RF classifier with output as the TS type, train and test. Another option is to use these stat features for clustering and check cluster quality. If accuracy is poor, add more stat features and repeat same process as outlined for training and testing. Assume that each time-series is named based on their type which will be used as target output. For example, temperature time series will be named as temperature?.csv where ? is an integer. Loop over each file in a directory, get stat and record in a dictionary/dataframe, train/test. Default to using RandomForest for classification of data types.

source
TSML.ValDateFilters.CSVDateValReaderType
CSVDateValReader(
   Dict(
      :filename => "",
      :dateformat => ""
   )
)

Reads csv file and parse date using the given format.

  • :filename => complete path including filename of csv file
  • :dateformat => date format to parse

Example:

inputfile =joinpath(dirname(pathof(TSML)),"../data/testdata.csv")
csvreader = CSVDateValReader(Dict(:filename=>inputfile,:dateformat=>"d/m/y H:M"))
fit!(csvreader)
df = transform!(csvreader)

# using pipeline workflow
filter1 = DateValgator()
filter2 = DateValNNer(Dict(:nnsize=>1))
mypipeline = @pipeline csvreader |> filter1 |> filter2
fit!(mypipeline)
res=transform!(mypipeline)

Implements: fit!, transform!

source
TSML.ValDateFilters.CSVDateValWriterType
CSVDateValWriter(
   Dict(
      :filename => "",
      :dateformat => ""
   )
)

Writes the time series dataframe into a file with the given date format.

Example:

inputfile =joinpath(dirname(pathof(TSML)),"../data/testdata.csv")
outputfile = joinpath("/tmp/test.csv")
csvreader = CSVDateValReader(Dict(:filename=>inputfile,:dateformat=>"d/m/y H:M"))
csvwtr = CSVDateValWriter(Dict(:filename=>outputfile,:dateformat=>"d/m/y H:M"))
filter1 = DateValgator()
filter2 = DateValNNer(Dict(:nnsize=>1))
mypipeline = @pipeline csvreader |> filter1 |> filter2 |> csvwtr
res=fit_transform!(mypipeline)

# read back what was written to validate
csvreader = CSVDateValReader(Dict(:filename=>outputfile,:dateformat=>"y-m-d HH:MM:SS"))
fit!(csvreader)
transform!(csvreader)

Implements: fit!, transform!

source
TSML.ValDateFilters.DateValLinearImputerType
DateValLinearImputer(
   Dict(
      :dateinterval => Dates.Hour(1),
  )
)

Fills missings by linear interpolation.

  • :dateinterval => time period to use for grouping,

Example:

Random.seed!(123)
gdate = DateTime(2014,1,1):Dates.Minute(15):DateTime(2016,1,1)
gval = Array{Union{Missing,Float64}}(rand(length(gdate)))
gmissing = 50000
gndxmissing = Random.shuffle(1:length(gdate))[1:gmissing]
X = DataFrame(Date=gdate,Value=gval)
X.Value[gndxmissing] .= missing

dnnr = DateValLinearImputer()
fit!(dnnr,X)
transform!(dnnr,X)

Implements: fit!, transform!`

source
TSML.ValDateFilters.DateValMultiNNerType
DateValMultiNNer(
   Dict(
      :type => :knn # :linear
      :missdirection => :symmetric, #:reverse, # or :forward or :symmetric
      :dateinterval => Dates.Hour(1),
      :nnsize => 1,
      :strict => false,
      :aggregator => :median
  )
)

Fills missings with their nearest-neighbors. It assumes that first column is a Date class and the other columns are Union{Missings,Real}. It uses DateValNNer and DateValizer+Impute to process each numeric column concatendate with the Date column.

  • :type => type of imputation which can be a linear interpolation or nearest neighbor
  • :missdirection => direction to fill missing data (:symmetric, :reverse, :forward)
  • :dateinterval => time period to use for grouping,
  • :nnsize => neighborhood size,
  • :strict => boolean value to indicate whether to be strict about replacement or not,
  • `:aggregator => function to aggregate based on date interval

Example:

Random.seed!(123)
gdate = DateTime(2014,1,1):Dates.Minute(15):DateTime(2016,1,1)
gval1 = Array{Union{Missing,Float64}}(rand(length(gdate)))
gval2 = Array{Union{Missing,Float64}}(rand(length(gdate)))
gval3 = Array{Union{Missing,Float64}}(rand(length(gdate)))
gmissing = 50000
gndxmissing1 = Random.shuffle(1:length(gdate))[1:gmissing]
gndxmissing2 = Random.shuffle(1:length(gdate))[1:gmissing]
gndxmissing3 = Random.shuffle(1:length(gdate))[1:gmissing]
X = DataFrame(Date=gdate,Temperature=gval1,Humidity=gval2,Ozone=gval3)
X.Temperature[gndxmissing1] .= missing
X.Humidity[gndxmissing2] .= missing
X.Ozone[gndxmissing3] .= missing

dnnr = DateValMultiNNer(Dict(
      :type=>:linear,
      :dateinterval=>Dates.Hour(1),
      :nnsize=>10,
      :missdirection => :symmetric,
      :strict=>false,
      :aggregator => :mean))
fit!(dnnr,X)
transform!(dnnr,X)

Implements: fit!, transform!`

source
TSML.ValDateFilters.DateValNNerType
DateValNNer(
   Dict(
      :missdirection => :symmetric, #:reverse, # or :forward or :symmetric
      :dateinterval => Dates.Hour(1),
      :nnsize => 1,
      :strict => false,
      :aggregator => :median
  )
)

Fills missings with their nearest-neighbors.

  • :missdirection => direction to fill missing data (:symmetric, :reverse, :forward)
  • :dateinterval => time period to use for grouping,
  • :nnsize => neighborhood size,
  • :strict => boolean value to indicate whether to be strict about replacement or not,
  • `:aggregator => function to aggregate based on date interval

Example:

Random.seed!(123)
gdate = DateTime(2014,1,1):Dates.Minute(15):DateTime(2016,1,1)
gval = Array{Union{Missing,Float64}}(rand(length(gdate)))
gmissing = 50000
gndxmissing = Random.shuffle(1:length(gdate))[1:gmissing]
X = DataFrame(Date=gdate,Value=gval)
X.Value[gndxmissing] .= missing

dnnr = DateValNNer(Dict(
      :dateinterval=>Dates.Hour(1),
      :nnsize=>10,
      :missdirection => :symmetric,
      :strict=>true,
      :aggregator => :mean))
fit!(dnnr,X)
transform!(dnnr,X)

Implements: fit!, transform!`

source
TSML.ValDateFilters.DateValgatorType
DateValgator(args=Dict())
   Dict(
    :dateinterval => Dates.Hour(1),
    :aggregator => :median
  )
)

Aggregates values based on date period specified.

Example:

# generate random values with missing data
Random.seed!(123)
gdate = DateTime(2014,1,1):Dates.Minute(15):DateTime(2016,1,1)
gval = Array{Union{Missing,Float64}}(rand(length(gdate)))
gmissing = 50000
gndxmissing = Random.shuffle(1:length(gdate))[1:gmissing]
X = DataFrame(Date=gdate,Value=gval)
X.Value[gndxmissing] .= missing

dtvlmean = DateValgator(Dict(
      :dateinterval=>Dates.Hour(1),
      :aggregator => :mean))
fit!(dtvlmean,X)
res = transform!(dtvlmean,X)

Implements: fit!, transform!

source
TSML.ValDateFilters.DateValizerType
DateValizer(
   Dict(
    :medians => DataFrame(),
    :dateinterval => Dates.Hour(1)
  )
)

Normalizes and cleans time series by replacing missings with global medians computed based on time period groupings.

Example:

# generate random values with missing data
Random.seed!(123)
gdate = DateTime(2014,1,1):Dates.Minute(15):DateTime(2016,1,1)
gval = Array{Union{Missing,Float64}}(rand(length(gdate)))
gmissing = 50000
gndxmissing = Random.shuffle(1:length(gdate))[1:gmissing]
X = DataFrame(Date=gdate,Value=gval)
X.Value[gndxmissing] .= missing

dvzr = DateValizer(Dict(:dateinterval=>Dates.Hour(1)))
fit!(dvzr,X)
transform!(dvzr,X)

Implements: fit!, transform!

source
TSML.ValDateFilters.DateifierType
Dateifier(args=Dict())
   Dict(
    :ahead => 1,
    :size => 7,
    :stride => 1
   )
)

Converts a 1-D date series into sliding window matrix for ML training

Example:

dtr = Dateifier(Dict())
lower = DateTime(2017,1,1)
upper = DateTime(2018,1,31)
dat=lower:Dates.Day(1):upper |> collect
vals = rand(length(dat))
x=DataFrame(Date=dat,Value=vals)
fit!(dtr,x)
res = transform!(dtr,x)

Implements: 'fit!, transform!

source
TSML.ValDateFilters.MatrifierType
Matrifier(Dict(
   Dict(
    :ahead  => 1,
    :size   => 7,
    :stride => 1,
  )
)

Converts a 1-D timeseries into sliding window matrix for ML training:

  • :ahead => steps ahead to predict
  • :size => size of sliding window
  • :stride => amount of overlap in sliding window

Example:

mtr = Matrifier(Dict(:ahead=>24,:size=>24,:stride=>5))
lower = DateTime(2017,1,1)
upper = DateTime(2017,1,5)
dat=lower:Dates.Hour(1):upper |> collect
vals = 1:length(dat)
x = DataFrame(Date=dat,Value=vals)
fit!(mtr,x)
res = transform!(mtr,x)

Implements: fit!, transform

source
AMLPipelineBase.AbsTypes.transform!Method
transform!(dnnr::DateValMultiNNer,xx::T)

Replaces missings by nearest neighbor or linear interpolation by looping over the dataset for each column until all missing values are gone.

source
AMLPipelineBase.AbsTypes.transform!Method
transform!(dvmr::DateValgator,xx::T)

Aggregates values grouped by date-time period using aggregate function such as mean, median, maximum, minimum. Default is mean.

source