本文整理了Java中weka.core.Instances.stratify()
方法的一些代码示例,展示了Instances.stratify()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Instances.stratify()
方法的具体详情如下:
包路径:weka.core.Instances
类名称:Instances
方法名:stratify
[英]Stratifies a set of instances according to its class values if the class attribute is nominal (so that afterwards a stratified cross-validation can be performed).
[中]如果class属性为nominal,则根据其类值对一组实例进行分层(以便之后可以执行分层交叉验证)。
代码示例来源:origin: com.googlecode.obvious/obviousx-weka
@Override
public void stratify(int arg0) {
super.stratify(arg0);
}
代码示例来源:origin: stackoverflow.com
Instances dataSet = ...;
dataSet.stratify(numOfFolds); // use this
//before splitting the dataset into train and test set!
代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable
/**
* Generate a bunch of predictions ready for processing, by performing a
* cross-validation on the supplied dataset.
*
* @param classifier the Classifier to evaluate
* @param data the dataset
* @param numFolds the number of folds in the cross-validation.
* @exception Exception if an error occurs
*/
public ArrayList<Prediction> getCVPredictions(Classifier classifier,
Instances data, int numFolds) throws Exception {
ArrayList<Prediction> predictions = new ArrayList<Prediction>();
Instances runInstances = new Instances(data);
Random random = new Random(m_Seed);
runInstances.randomize(random);
if (runInstances.classAttribute().isNominal() && (numFolds > 1)) {
runInstances.stratify(numFolds);
}
for (int fold = 0; fold < numFolds; fold++) {
Instances train = runInstances.trainCV(numFolds, fold, random);
Instances test = runInstances.testCV(numFolds, fold);
ArrayList<Prediction> foldPred = getTrainTestPredictions(classifier,
train, test);
predictions.addAll(foldPred);
}
return predictions;
}
代码示例来源:origin: Waikato/weka-trunk
/**
* Generate a bunch of predictions ready for processing, by performing a
* cross-validation on the supplied dataset.
*
* @param classifier the Classifier to evaluate
* @param data the dataset
* @param numFolds the number of folds in the cross-validation.
* @exception Exception if an error occurs
*/
public ArrayList<Prediction> getCVPredictions(Classifier classifier,
Instances data, int numFolds) throws Exception {
ArrayList<Prediction> predictions = new ArrayList<Prediction>();
Instances runInstances = new Instances(data);
Random random = new Random(m_Seed);
runInstances.randomize(random);
if (runInstances.classAttribute().isNominal() && (numFolds > 1)) {
runInstances.stratify(numFolds);
}
for (int fold = 0; fold < numFolds; fold++) {
Instances train = runInstances.trainCV(numFolds, fold, random);
Instances test = runInstances.testCV(numFolds, fold);
ArrayList<Prediction> foldPred = getTrainTestPredictions(classifier,
train, test);
predictions.addAll(foldPred);
}
return predictions;
}
代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable
/**
* Perform a cross validation for attribute selection. With subset evaluators
* the number of times each attribute is selected over the cross validation is
* reported. For attribute evaluators, the average merit and average ranking +
* std deviation is reported for each attribute.
*
* @return the results of cross validation as a String
* @exception Exception if an error occurs during cross validation
*/
public String CrossValidateAttributes() throws Exception {
Instances cvData = new Instances(m_trainInstances);
Instances train;
Random random = new Random(m_seed);
cvData.randomize(random);
if (!(m_ASEvaluator instanceof UnsupervisedSubsetEvaluator)
&& !(m_ASEvaluator instanceof UnsupervisedAttributeEvaluator)) {
if (cvData.classAttribute().isNominal()) {
cvData.stratify(m_numFolds);
}
}
for (int i = 0; i < m_numFolds; i++) {
// Perform attribute selection
train = cvData.trainCV(m_numFolds, i, random);
selectAttributesCVSplit(train);
}
return CVResultsString();
}
代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable
/**
* Method for building a pruneable classifier tree.
*
* @param data the data to build the tree from
* @throws Exception if tree can't be built successfully
*/
public void buildClassifier(Instances data)
throws Exception {
// remove instances with missing class
data = new Instances(data);
data.deleteWithMissingClass();
Random random = new Random(m_seed);
data.stratify(numSets);
buildTree(data.trainCV(numSets, numSets - 1, random),
data.testCV(numSets, numSets - 1), !m_cleanup);
if (pruneTheTree) {
prune();
}
if (m_cleanup) {
cleanup(new Instances(data, 0));
}
}
代码示例来源:origin: Waikato/weka-trunk
/**
* Perform a cross validation for attribute selection. With subset evaluators
* the number of times each attribute is selected over the cross validation is
* reported. For attribute evaluators, the average merit and average ranking +
* std deviation is reported for each attribute.
*
* @return the results of cross validation as a String
* @exception Exception if an error occurs during cross validation
*/
public String CrossValidateAttributes() throws Exception {
Instances cvData = new Instances(m_trainInstances);
Instances train;
Random random = new Random(m_seed);
cvData.randomize(random);
if (!(m_ASEvaluator instanceof UnsupervisedSubsetEvaluator)
&& !(m_ASEvaluator instanceof UnsupervisedAttributeEvaluator)) {
if (cvData.classAttribute().isNominal()) {
cvData.stratify(m_numFolds);
}
}
for (int i = 0; i < m_numFolds; i++) {
// Perform attribute selection
train = cvData.trainCV(m_numFolds, i, random);
selectAttributesCVSplit(train);
}
return CVResultsString();
}
代码示例来源:origin: Waikato/weka-trunk
/**
* Method for building a pruneable classifier tree.
*
* @param data the data to build the tree from
* @throws Exception if tree can't be built successfully
*/
public void buildClassifier(Instances data)
throws Exception {
// remove instances with missing class
data = new Instances(data);
data.deleteWithMissingClass();
Random random = new Random(m_seed);
data.stratify(numSets);
buildTree(data.trainCV(numSets, numSets - 1, random),
data.testCV(numSets, numSets - 1), !m_cleanup);
if (pruneTheTree) {
prune();
}
if (m_cleanup) {
cleanup(new Instances(data, 0));
}
}
代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable
newData.randomize(random);
if (newData.classAttribute().isNominal()) {
newData.stratify(m_NumFolds);
代码示例来源:origin: Waikato/weka-trunk
newData.randomize(random);
if (newData.classAttribute().isNominal()) {
newData.stratify(m_NumFolds);
代码示例来源:origin: Waikato/weka-trunk
trainData.stratify(m_NumFolds);
代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable
trainData.stratify(m_NumFolds);
代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable
allData.stratify(m_numFoldsBoosting);
代码示例来源:origin: Waikato/weka-trunk
allData.stratify(m_numFoldsBoosting);
代码示例来源:origin: nz.ac.waikato.cms.weka/conjunctiveRule
data.stratify(m_Folds);
代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable
getInputFormat().stratify(m_NumFolds);
if (!m_Inverse) {
instances = getInputFormat().testCV(m_NumFolds, m_Fold - 1);
代码示例来源:origin: Waikato/weka-trunk
getInputFormat().stratify(m_NumFolds);
if (!m_Inverse) {
instances = getInputFormat().testCV(m_NumFolds, m_Fold - 1);
代码示例来源:origin: net.sf.meka.thirdparty/mulan
transformed.stratify(folds);
代码示例来源:origin: olehmberg/winter
data.randomize(random);
if (data.classAttribute().isNominal()) {
data.stratify(numFolds);
代码示例来源:origin: Waikato/weka-trunk
&& !getPreserveOrder()) {
getStepManager().logBasic("Stratifying data");
dataSet.stratify(m_numFolds);
内容来源于网络,如有侵权,请联系作者删除!