Class ShotgunEnsembleClassifier
- java.lang.Object
-
- ai.libs.jaicore.ml.tsc.classifier.ASimplifiedTSClassifier<java.lang.Integer>
-
- ai.libs.jaicore.ml.tsc.classifier.neighbors.ShotgunEnsembleClassifier
-
public class ShotgunEnsembleClassifier extends ASimplifiedTSClassifier<java.lang.Integer>
Implementation of Shotgun Ensemble Classifier as published in "Towards Time Series Classfication without Human Preprocessing" by Patrick Schäfer (2014). The Shotgun Classifier is based 1-NN and the Shotgun Distance. The Shotgun Ensemble AlgorithmShotgunEnsembleAlgoritmdetermines for specific window lengths the number of correct predicitions on the training data using the leave-one-out technique. ThebestScoreis the highest number of correct predicitions over all window lengths. Given afactorin(0,1], the window lengths wherecorrect * factor > bestScoreare used in an ensemble of Shotgun Classifiers to create an overall predicition.
-
-
Field Summary
Fields Modifier and Type Field Description protected intbestScoreThe best score.protected doublefactorFactor used to determine whether or not to include a window length into the overall predicition.protected NearestNeighborClassifiernearestNeighborClassifierThe nearest neighbor classifier used for prediction.protected ShotgunDistanceshotgunDistanceThe Shotgun Distance used by thenearestNeighborClassifier.protected int[]targetsTarget values for the instances.protected double[][]valuesValue matrix containing the time series instances.protected java.util.ArrayList<ai.libs.jaicore.basic.sets.Pair<java.lang.Integer,java.lang.Integer>>windowsHolds pairs of (number of correct predictions, window length) obtained in training phase.-
Fields inherited from class ai.libs.jaicore.ml.tsc.classifier.ASimplifiedTSClassifier
classMapper, trained
-
-
Constructor Summary
Constructors Constructor Description ShotgunEnsembleClassifier(int minWindowLength, int maxWindowLength, boolean meanNormalization, double factor)Creates a Shotgun Ensemble classifier.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.util.Map<java.lang.Integer,java.lang.Integer>calculateWindowLengthPredictions(double[] testInstance)Calculates predicitions for a test instance using 1NN with Shotgun Distance and different window lengths.protected java.util.Map<java.lang.Integer,java.util.List<java.lang.Integer>>calculateWindowLengthPredictions(TimeSeriesDataset dataset)Calculates predicitions for a test dataset using 1NN with Shotgun Distance and different window lengths.ShotgunEnsembleLearnerAlgorithmgetLearningAlgorithm(TimeSeriesDataset dataset)protected java.lang.IntegermostFrequentLabelFromWindowLengthPredicitions(java.util.Map<java.lang.Integer,java.lang.Integer> windowLengthPredicitions)Returns the most frequent predicition given a Map of (window length, prediciton) pairs.protected java.util.List<java.lang.Integer>mostFrequentLabelsFromWindowLengthPredicitions(java.util.Map<java.lang.Integer,java.util.List<java.lang.Integer>> windowLengthPredicitions)Returns for each instance the most frequent predicitions as contained in a Map of (window length, list of prediciton for each instance) pairs.java.lang.Integerpredict(double[] univInstance)Predicts on univariate instance.java.util.List<java.lang.Integer>predict(TimeSeriesDataset dataset)Predicts on a dataset.protected voidsetNearestNeighborClassifier(NearestNeighborClassifier nearestNeighborClassifier)Sets the nearest neighbor classifier,nearestNeighborClassifier.protected voidsetTargets(int[] targets)Sets the targets.protected voidsetValues(double[][] values)Sets the value matrix.protected voidsetWindows(java.util.ArrayList<ai.libs.jaicore.basic.sets.Pair<java.lang.Integer,java.lang.Integer>> windows)Sets the windows and also retreives and sets the @see #bestScore from these windows.-
Methods inherited from class ai.libs.jaicore.ml.tsc.classifier.ASimplifiedTSClassifier
checkWhetherPredictionIsPossible, getClassMapper, isTrained, predict, setClassMapper, train
-
-
-
-
Field Detail
-
factor
protected double factor
Factor used to determine whether or not to include a window length into the overall predicition.
-
values
protected double[][] values
Value matrix containing the time series instances. Set by algorithm.
-
targets
protected int[] targets
Target values for the instances. Set by the algorithm.
-
nearestNeighborClassifier
protected NearestNeighborClassifier nearestNeighborClassifier
The nearest neighbor classifier used for prediction. Set by the algorithm.
-
shotgunDistance
protected ShotgunDistance shotgunDistance
The Shotgun Distance used by thenearestNeighborClassifier. Set by the algorithm.
-
windows
protected java.util.ArrayList<ai.libs.jaicore.basic.sets.Pair<java.lang.Integer,java.lang.Integer>> windows
Holds pairs of (number of correct predictions, window length) obtained in training phase.
-
bestScore
protected int bestScore
The best score. States the highest number of correct predicitions for every window length used in training phase (leave-one-out).
-
-
Constructor Detail
-
ShotgunEnsembleClassifier
public ShotgunEnsembleClassifier(int minWindowLength, int maxWindowLength, boolean meanNormalization, double factor)Creates a Shotgun Ensemble classifier.- Parameters:
algorithm- The training algorithm.factor- Factor used to determine whether or not to include a window length into the overall predicition.
-
-
Method Detail
-
calculateWindowLengthPredictions
protected java.util.Map<java.lang.Integer,java.lang.Integer> calculateWindowLengthPredictions(double[] testInstance) throws PredictionExceptionCalculates predicitions for a test instance using 1NN with Shotgun Distance and different window lengths.- Parameters:
testInstance- The test instance.- Returns:
- Map of (window length, prediciton) pairs.
- Throws:
PredictionException
-
mostFrequentLabelFromWindowLengthPredicitions
protected java.lang.Integer mostFrequentLabelFromWindowLengthPredicitions(java.util.Map<java.lang.Integer,java.lang.Integer> windowLengthPredicitions)
Returns the most frequent predicition given a Map of (window length, prediciton) pairs.- Parameters:
windowLengthPredicitions- Map of (window length, prediciton) pairs.- Returns:
- The most frequent predicition.
-
calculateWindowLengthPredictions
protected java.util.Map<java.lang.Integer,java.util.List<java.lang.Integer>> calculateWindowLengthPredictions(TimeSeriesDataset dataset) throws PredictionException
Calculates predicitions for a test dataset using 1NN with Shotgun Distance and different window lengths.- Parameters:
dataset- The dataset to predict for.- Returns:
- Map of (window length, predicitions) pairs.
- Throws:
PredictionException
-
mostFrequentLabelsFromWindowLengthPredicitions
protected java.util.List<java.lang.Integer> mostFrequentLabelsFromWindowLengthPredicitions(java.util.Map<java.lang.Integer,java.util.List<java.lang.Integer>> windowLengthPredicitions)
Returns for each instance the most frequent predicitions as contained in a Map of (window length, list of prediciton for each instance) pairs.- Parameters:
windowLengthPredicitions- Map of (window length, list of prediciton for each instance) pairs.- Returns:
- The most frequent predicition for each instace.
-
predict
public java.lang.Integer predict(double[] univInstance) throws PredictionExceptionPredicts on univariate instance.- Specified by:
predictin classASimplifiedTSClassifier<java.lang.Integer>- Parameters:
univInstance- The univariate instance.- Returns:
- Class prediction for the instance.
- Throws:
PredictionException- If something fails during the prediction process.
-
predict
public java.util.List<java.lang.Integer> predict(TimeSeriesDataset dataset) throws PredictionException
Predicts on a dataset.- Specified by:
predictin classASimplifiedTSClassifier<java.lang.Integer>- Parameters:
dataset- The dataset.- Returns:
- List of class predicitons for each instance of the dataset.
- Throws:
PredictionException- If something fails during the prediction process
-
setValues
protected void setValues(double[][] values)
Sets the value matrix.- Parameters:
values-
-
setTargets
protected void setTargets(int[] targets)
Sets the targets.- Parameters:
targets-
-
setWindows
protected void setWindows(java.util.ArrayList<ai.libs.jaicore.basic.sets.Pair<java.lang.Integer,java.lang.Integer>> windows)
Sets the windows and also retreives and sets the @see #bestScore from these windows.- Parameters:
windows-- See Also:
windows
-
setNearestNeighborClassifier
protected void setNearestNeighborClassifier(NearestNeighborClassifier nearestNeighborClassifier)
Sets the nearest neighbor classifier,nearestNeighborClassifier.- Parameters:
nearestNeighborClassifier-
-
getLearningAlgorithm
public ShotgunEnsembleLearnerAlgorithm getLearningAlgorithm(TimeSeriesDataset dataset)
- Specified by:
getLearningAlgorithmin classASimplifiedTSClassifier<java.lang.Integer>
-
-