public abstract class CrossValidation
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
CrossValidation.Data
Partition of input data
|
static class |
CrossValidation.TrainTestSubsets
Helper class to partition input data
|
Modifier and Type | Field and Description |
---|---|
protected java.util.Random |
random
RNG
|
protected double[][] |
X
Original samples
|
protected int[] |
y
Original sample labels
|
Constructor and Description |
---|
CrossValidation()
Creates a new empty cross-validator.
|
CrossValidation(CrossValidation.Data data)
Create a new cross validator
|
CrossValidation(double[][] samples,
int[] labels)
Create a new cross validator.
|
Modifier and Type | Method and Description |
---|---|
static CrossValidation.Data |
balanceUp(CrossValidation.Data orig)
Balances imbalanced data with the SMOTE (Synthetic Minority Over-sampling TEchnique) as per
https://www.cs.cmu.edu/afs/cs/project/jair/pub/volume16/chawla02a-html/node6.html .
|
static CrossValidation.Data |
balanceUp(CrossValidation.Data orig,
smile.math.distance.Distance<double[]> distanceMetric,
int nn)
Balances imbalanced data with the SMOTE (Synthetic Minority Over-sampling TEchnique) as per
https://www.cs.cmu.edu/afs/cs/project/jair/pub/volume16/chawla02a-html/node6.html .
|
static CrossValidation.Data |
balanceUp(CrossValidation.Data orig,
int nn)
Balances imbalanced data with the SMOTE (Synthetic Minority Over-sampling TEchnique) as per
https://www.cs.cmu.edu/afs/cs/project/jair/pub/volume16/chawla02a-html/node6.html .
|
java.util.Map<MLROIFinder,java.lang.Double> |
eval(int numRounds,
MLROIFinder[] models)
Evaluates the specified models for mean accuracy (ratio of true results / total results).
|
java.util.Map<MLROIFinder,java.lang.Double> |
eval(int numRounds,
MLROIFinder[] models,
boolean upSample)
Evaluates the specified models for mean accuracy (ratio of true results / total results).
|
java.util.Map<MLROIFinder,java.util.List<java.lang.Double>> |
evalModels(int numRounds,
MLROIFinder[] models)
Evaluates the specified models for accuracy i.e.
|
java.util.Map<MLROIFinder,java.util.List<java.lang.Double>> |
evalModels(int numRounds,
MLROIFinder[] models,
boolean upSample)
Evaluates the specified models for accuracy i.e.
|
java.util.Map.Entry<MLROIFinder,java.lang.Double> |
findBestModel(int numRounds,
MLROIFinder[] models)
Evaluates the specified models and returns the most accurate (ratio of true results / total results) model.
|
java.util.Map.Entry<MLROIFinder,java.lang.Double> |
findBestModel(int numRounds,
MLROIFinder[] models,
boolean upSample)
Evaluates the specified models and returns the most accurate (ratio of true results / total results) model.
|
static java.lang.Integer |
findMajorityLabel(CrossValidation.Data data)
Finds the majority label in a sample set, i.e.
|
static java.lang.Integer |
findMajorityLabel(java.util.Map<java.lang.Integer,java.lang.Integer> labelFreqs)
Finds the majority label in a sample set, i.e.
|
static java.lang.Integer |
findMinorityLabel(CrossValidation.Data data)
Finds the minority label in a sample set, i.e.
|
static java.lang.Integer |
findMinorityLabel(java.util.Map<java.lang.Integer,java.lang.Integer> labelFreqs)
Finds the minority label in a sample set, i.e.
|
abstract CrossValidation.TrainTestSubsets |
getTrainTestSubset()
Partition the input data into a training and a test set
|
static java.util.Map<java.lang.Integer,java.lang.Integer> |
labelFrequencies(CrossValidation.Data data)
Tallies the frequencies of each label in a dataset.
|
protected java.util.Random random
protected double[][] X
protected int[] y
public CrossValidation(double[][] samples, int[] labels)
samples
- N samples of M featureslabels
- N labelspublic CrossValidation(CrossValidation.Data data)
data
- samples and labels to usepublic CrossValidation()
public abstract CrossValidation.TrainTestSubsets getTrainTestSubset()
public static java.util.Map<java.lang.Integer,java.lang.Integer> labelFrequencies(CrossValidation.Data data)
data
- data to tallypublic static java.lang.Integer findMinorityLabel(java.util.Map<java.lang.Integer,java.lang.Integer> labelFreqs)
labelFreqs
- label frequencies mappublic static java.lang.Integer findMinorityLabel(CrossValidation.Data data)
data
- data to examinepublic static java.lang.Integer findMajorityLabel(java.util.Map<java.lang.Integer,java.lang.Integer> labelFreqs)
labelFreqs
- label frequencies mappublic static java.lang.Integer findMajorityLabel(CrossValidation.Data data)
data
- data to examinepublic static CrossValidation.Data balanceUp(CrossValidation.Data orig, smile.math.distance.Distance<double[]> distanceMetric, int nn)
orig
- Original (possibly) imbalanced datadistanceMetric
- distance metric to use for finding nearest neighborsnn
- number of nearest neighbors to findpublic static CrossValidation.Data balanceUp(CrossValidation.Data orig, int nn)
orig
- data to balancenn
- number of nearest neighbors to usepublic static CrossValidation.Data balanceUp(CrossValidation.Data orig)
orig
- data to balancepublic java.util.Map<MLROIFinder,java.util.List<java.lang.Double>> evalModels(int numRounds, MLROIFinder[] models, boolean upSample) throws java.lang.Exception
numRounds
- number of rounds of testingmodels
- models to testupSample
- if true, upsample training data to try to balance minority / majority classesjava.lang.Exception
- if an error occurs training the modelspublic java.util.Map<MLROIFinder,java.util.List<java.lang.Double>> evalModels(int numRounds, MLROIFinder[] models) throws java.lang.Exception
numRounds
- number of rounds of testingmodels
- models to testjava.lang.Exception
- if an error occurs training the modelspublic java.util.Map<MLROIFinder,java.lang.Double> eval(int numRounds, MLROIFinder[] models, boolean upSample) throws java.lang.Exception
numRounds
- number of rounds of testingmodels
- models to testupSample
- if true, upsample training data to try to balance minority / majority classesjava.lang.Exception
- if an error occurspublic java.util.Map<MLROIFinder,java.lang.Double> eval(int numRounds, MLROIFinder[] models) throws java.lang.Exception
numRounds
- number of rounds of testingmodels
- models to testjava.lang.Exception
- if an error occurspublic java.util.Map.Entry<MLROIFinder,java.lang.Double> findBestModel(int numRounds, MLROIFinder[] models, boolean upSample) throws java.lang.Exception
numRounds
- number of rounds of testingmodels
- models to testupSample
- if true, upsample training data to try to balance minority / majority classesjava.lang.Exception
- if an error occurspublic java.util.Map.Entry<MLROIFinder,java.lang.Double> findBestModel(int numRounds, MLROIFinder[] models) throws java.lang.Exception
numRounds
- number of rounds of testingmodels
- models to testjava.lang.Exception
- if an error occurs