Orchestra is a heterogeneous ensemble learning package for the Julia programming language. It is driven by a uniform machine learner API designed for learner composition.
We will cover how to predict on a dataset using Orchestra.
A tabular dataset will be used to obtain our instances and labels.
This will be split it into a training and test set using holdout method.
import RDatasets
using Orchestra.Util
using Orchestra.Transformers
# Obtain instances and labels
dataset = RDatasets.dataset("datasets", "iris")
instances = array(dataset[:, 1:(end-1)])
labels = array(dataset[:, end])
# Split into training and test sets
(train_ind, test_ind) = holdout(size(instances, 1), 0.3)
A transformer processes instances in some form. Coincidentally, a learner is a subtype of transformer.
A transformer can be created by instantiating it, taking an options dictionary as an optional argument.
All transformers, including learners are called in the same way.
# Learner with default settings
learner = PrunedTree()
# Learner with some of the default settings overriden
learner = PrunedTree({
:impl_options => {
:purity_threshold => 0.5
}
})
# All learners are called in the same way.
learner = StackEnsemble({
:learners => [
PrunedTree(),
RandomForest(),
DecisionStumpAdaboost()
],
:stacker => RandomForest()
})
Normally we may require the use of data pre-processing before the instances are passed to the learner.
We shall use a pipeline transformer to chain many transformers in sequence.
In this case we shall one hot encode categorical features, impute NA values and numerically standardize before we call the learner.
# Create pipeline
pipeline = Pipeline({
:transformers => [
OneHotEncoder(), # Encodes nominal features into numeric
Imputer(), # Imputes NA values
StandardScaler(), # Standardizes features
learner # Predicts labels on instances
]
})
Training is done via the fit!
function, predicton via transform!
.
All transformers, provide these two functions. They are always called the same way.
# Train
fit!(pipeline, instances[train_ind, :], labels[train_ind])
# Predict
predictions = transform!(pipeline, instances[test_ind, :])
Finally we assess how well our learner performed.
# Assess predictions
result = score(:accuracy, labels[test_ind], predictions)
Outlined are all the transformers currently available via Orchestra.
Baseline learner that by default assigns the most frequent label.
learner = Baseline({
# Output to train against
# (:class).
:output => :class,
# Label assignment strategy.
# Function that takes a label vector and returns the required output.
:strategy => mode
})
Identity transformer passes the instances as is.
transformer = Identity()
Set of machine learners that majority vote to decide prediction.
learner = VoteEnsemble({
# Output to train against
# (:class).
:output => :class,
# Learners in voting committee.
:learners => [PrunedTree(), DecisionStumpAdaboost(), RandomForest()]
})
Ensemble where a 'stack' learner learns on a set of learners' predictions.
learner = StackEnsemble({
# Output to train against
# (:class).
:output => :class,
# Set of learners that produce feature space for stacker.
:learners => [PrunedTree(), DecisionStumpAdaboost(), 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
})
Selects best learner out of set. Will perform a grid search on learners if options grid is provided.
learner = BestLearner({
# 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, 2))[2],
# Score type returned by score() using respective output.
:score_type => Real,
# Candidate learners.
:learners => [PrunedTree(), DecisionStumpAdaboost(), 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
})
Transforms instances with nominal features into one-hot form and coerces the instance matrix to be of element type Float64.
transformer = OneHotEncoder({
# Nominal columns
:nominal_columns => nothing,
# Nominal column values map. Key is column index, value is list of
# possible values for that column.
:nominal_column_values_map => nothing
})
Imputes NaN values from Float64 features.
transformer = Imputer({
# Imputation strategy.
# Statistic that takes a vector such as mean or median.
:strategy => mean
})
Chains multiple transformers in sequence.
transformer = Pipeline({
# Transformers as list to chain in sequence.
:transformers => [OneHotEncoder(), Imputer()],
# Transformer options as list applied to same index transformer.
:transformer_options => nothing
})
Wraps around an Orchestra transformer.
transformer = Wrapper({
# Transformer to call.
:transformer => OneHotEncoder(),
# Transformer options.
:transformer_options => nothing
})
Pruned ID3 decision tree.
learner = PrunedTree({
# Output to train against
# (:class).
:output => :class,
# Options specific to this implementation.
:impl_options => {
# Merge leaves having >= purity_threshold combined purity.
:purity_threshold => 1.0
}
})
Random forest (C4.5).
learner = RandomForest({
# Output to train against
# (:class).
:output => :class,
# Options specific to this implementation.
:impl_options => {
# Number of features to train on with trees.
:num_subfeatures => nothing,
# Number of trees in forest.
:num_trees => 10,
# Proportion of trainingset to be used for trees.
:partial_sampling => 0.7
}
})
Adaboosted C4.5 decision stumps.
learner = DecisionStumpAdaboost({
# Output to train against
# (:class).
:output => :class,
# Options specific to this implementation.
:impl_options => {
# Number of boosting iterations.
:num_iterations => 7
}
})
Principal Component Analysis rotation on features. Features ordered by maximal variance descending.
Fails if zero-variance feature exists.
transformer = PCA({
# Center features
:center => true,
# Scale features
:scale => true
})
Standardizes each feature using (X - mean) / stddev. Will produce NaN if standard deviation is zero.
transformer = StandardScaler({
# Center features
:center => true,
# Scale features
:scale => true
})
See the scikit-learn API for what options are available per learner.
Wrapper for scikit-learn that provides access to most learners.
Options for the specific scikit-learn learner is to be passed
in options[:impl_options]
dictionary.
Available learners:
- "AdaBoostClassifier"
- "BaggingClassifier"
- "ExtraTreesClassifier"
- "GradientBoostingClassifier"
- "RandomForestClassifier"
- "LDA"
- "LogisticRegression"
- "PassiveAggressiveClassifier"
- "RidgeClassifier"
- "RidgeClassifierCV"
- "SGDClassifier"
- "KNeighborsClassifier"
- "RadiusNeighborsClassifier"
- "NearestCentroid"
- "QDA"
- "SVC"
- "LinearSVC"
- "NuSVC"
- "DecisionTreeClassifier"
learner = SKLLearner({
# Output to train against
# (:class).
:output => :class,
:learner => "LinearSVC",
# Options specific to this implementation.
:impl_options => Dict()
})
Python library 'rpy2' is required to interface with R.
R library 'caret' offers more than 100 learners. See here for more details.
CARET wrapper that provides access to all learners.
Options for the specific CARET learner is to be passed
in options[:impl_options]
dictionary.
learner = CRTLearner({
# Output to train against
# (:class).
:output => :class,
:learner => "svmLinear",
:impl_options => Dict()
})
Learners have only been tested on instances with numeric features.
Inconsistencies may result in using nominal features directly without a numeric transformation (i.e. OneHotEncoder).
The links provided below will only work if you are viewing this in the GitHub repository.
See CHANGELOG.yml.
See FUTUREWORK.md.
See CONTRIBUTING.md.
MIT "Expat" License. See LICENSE.md.