jsat.classifiers.imbalance
Class SMOTE
- java.lang.Object
-
- jsat.classifiers.imbalance.SMOTE
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, Classifier, Parameterized
- Direct Known Subclasses:
- BorderlineSMOTE
public class SMOTE extends java.lang.Object implements Classifier, Parameterized
This class implements the Synthetic Minority Over-sampling TEchnique (SMOTE) for dealing with class imbalance. It does this by over-sampling the minority classes to bring their total count up to parity (or some target ratio) with the majority class. This is done by interpolating between minority points and their neighbors to create new synthetic points that are not present in the current dataset. For this reason SMOTE only works with numeric feature vectors.
See: Chawla, N., Bowyer, K., Hall, L., & Kegelmeyer, P. (2002). SMOTE: synthetic minority over-sampling technique. Artificial Intelligence Research, 16, 321–357. Retrieved from here- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description SMOTE(Classifier baseClassifier)Creates a new SMOTE model that will over-sample the minority classes so that there is a balanced number of data points in each class.
This implementation extends the original SMOTE algorithm to the multi-class case.SMOTE(Classifier baseClassifier, DistanceMetric dm)Creates a new SMOTE model that will over-sample the minority classes so that there is a balanced number of data points in each class.SMOTE(Classifier baseClassifier, DistanceMetric dm, double targetRatio)Creates a new SMOTE model.SMOTE(Classifier baseClassifier, DistanceMetric dm, int smoteNeighbors, double targetRatio)Creates a new SMOTE objectSMOTE(SMOTE toCopy)Copy constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description CategoricalResultsclassify(DataPoint data)Performs classification on the given data point.SMOTEclone()ClassifiergetBaseClassifier()DistanceMetricgetDistanceMetric()intgetSmoteNeighbors()doublegetTargetRatio()voidsetBaseClassifier(Classifier baseClassifier)Sets the classifier to use after the dataset has been modifiedvoidsetDistanceMetric(DistanceMetric dm)Sets the metric used to determine the nearest neighbors of each point.voidsetSmoteNeighbors(int smoteNeighbors)Sets the number of neighbors that will be used to be candidates for interpolation.voidsetTargetRatio(double targetRatio)Sets the desired ratio of samples for each class compared to the majority class.booleansupportsWeightedData()Indicates whether the model knows how to train using weighted data points.voidtrain(ClassificationDataSet dataSet)Trains the classifier and constructs a model for classification using the given data set.voidtrain(ClassificationDataSet dataSet, boolean parallel)Trains the classifier and constructs a model for classification using the given data set.-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface jsat.parameters.Parameterized
getParameter, getParameters
-
-
-
-
Constructor Detail
-
SMOTE
public SMOTE(Classifier baseClassifier)
Creates a new SMOTE model that will over-sample the minority classes so that there is a balanced number of data points in each class.
This implementation extends the original SMOTE algorithm to the multi-class case.- Parameters:
baseClassifier- the base classifier to use after the SMOTEing is done.
-
SMOTE
public SMOTE(Classifier baseClassifier, DistanceMetric dm)
Creates a new SMOTE model that will over-sample the minority classes so that there is a balanced number of data points in each class.- Parameters:
baseClassifier- the base classifier to use after the SMOTEing is done.dm- the distance metric to use for determining nearest neighbors
-
SMOTE
public SMOTE(Classifier baseClassifier, DistanceMetric dm, double targetRatio)
Creates a new SMOTE model.- Parameters:
baseClassifier- the base classifier to use after the SMOTEing is done.dm- the distance metric to use for determining nearest neighborstargetRatio- the desired ratio of samples for each class with respect to the majority class.
-
SMOTE
public SMOTE(Classifier baseClassifier, DistanceMetric dm, int smoteNeighbors, double targetRatio)
Creates a new SMOTE object- Parameters:
baseClassifier- the base classifier to use after the SMOTEing is done.dm- the distance metric to use for determining nearest neighborssmoteNeighbors- the number of neighbors to look at when interpolating pointstargetRatio- the desired ratio of samples for each class with respect to the majority class.
-
SMOTE
public SMOTE(SMOTE toCopy)
Copy constructor- Parameters:
toCopy- the object to copy
-
-
Method Detail
-
setDistanceMetric
public void setDistanceMetric(DistanceMetric dm)
Sets the metric used to determine the nearest neighbors of each point.- Parameters:
dm- the distance metric to use.
-
getDistanceMetric
public DistanceMetric getDistanceMetric()
- Returns:
- the distance metric to use
-
setSmoteNeighbors
public void setSmoteNeighbors(int smoteNeighbors)
Sets the number of neighbors that will be used to be candidates for interpolation. The default value recommended in the original paper is 5.- Parameters:
smoteNeighbors- the number of candidate neighbors to select from when creating synthetic data points.
-
getSmoteNeighbors
public int getSmoteNeighbors()
- Returns:
- the number of candidate neighbors to select from when creating synthetic data points.
-
setTargetRatio
public void setTargetRatio(double targetRatio)
Sets the desired ratio of samples for each class compared to the majority class. A ratio of 1.0 will oversample the minority classes until they have just as many data points as the majority class. If any minority class already exists at a ratio equal to or above this ratio, no over samples will be created for that class. If the target ratio is greater than one, all classes including the majority class will be over-sampled to the desired ratio.- Parameters:
targetRatio- the target ratio between each class and the majority class
-
getTargetRatio
public double getTargetRatio()
- Returns:
- the target ratio between each class and the majority class
-
setBaseClassifier
public void setBaseClassifier(Classifier baseClassifier)
Sets the classifier to use after the dataset has been modified- Parameters:
baseClassifier- the classifier to use for training and prediction
-
getBaseClassifier
public Classifier getBaseClassifier()
- Returns:
- the classifier used by the model
-
classify
public CategoricalResults classify(DataPoint data)
Description copied from interface:ClassifierPerforms classification on the given data point.- Specified by:
classifyin interfaceClassifier- Parameters:
data- the data point to classify- Returns:
- the results of the classification.
-
train
public void train(ClassificationDataSet dataSet, boolean parallel)
Description copied from interface:ClassifierTrains the classifier and constructs a model for classification using the given data set. If the training method knows how, it will used the threadPool to conduct training in parallel. This method will block until the training has completed.- Specified by:
trainin interfaceClassifier- Parameters:
dataSet- the data set to train onparallel-trueif multiple threads should be used to train the model.falseif it should be done in a single threaded manner.
-
train
public void train(ClassificationDataSet dataSet)
Description copied from interface:ClassifierTrains the classifier and constructs a model for classification using the given data set.- Specified by:
trainin interfaceClassifier- Parameters:
dataSet- the data set to train on
-
supportsWeightedData
public boolean supportsWeightedData()
Description copied from interface:ClassifierIndicates whether the model knows how to train using weighted data points. If it does, the model will train assuming the weights. The values returned by this method may change depending on the parameters set for the model.- Specified by:
supportsWeightedDatain interfaceClassifier- Returns:
- true if the model supports weighted data, false otherwise
-
clone
public SMOTE clone()
- Specified by:
clonein interfaceClassifier- Overrides:
clonein classjava.lang.Object
-
-
DataMelt 3.0 © DataMelt by jWork.ORG