本文整理汇总了Java中weka.core.Randomizable类的典型用法代码示例。如果您正苦于以下问题:Java Randomizable类的具体用法?Java Randomizable怎么用?Java Randomizable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Randomizable类属于weka.core包,在下文中一共展示了Randomizable类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: buildClassifier
import weka.core.Randomizable; //导入依赖的package包/类
@Override
public void buildClassifier(Instances train) throws Exception {
testCapabilities(train);
if (getDebug()) System.out.print("-: Models: ");
//m_Classifiers = (MultilabelClassifier[]) AbstractClassifier.makeCopies(m_Classifier, m_NumIterations);
m_Classifiers = MultilabelClassifier.makeCopies((MultilabelClassifier)m_Classifier, m_NumIterations);
for(int i = 0; i < m_NumIterations; i++) {
Random r = new Random(m_Seed+i);
Instances bag = new Instances(train,0);
if (m_Classifiers[i] instanceof Randomizable) ((Randomizable)m_Classifiers[i]).setSeed(m_Seed+i);
if(getDebug()) System.out.print(""+i+" ");
int bag_no = (m_BagSizePercent*train.numInstances()/100);
//System.out.println(" bag no: "+bag_no);
while(bag.numInstances() < bag_no) {
bag.add(train.instance(r.nextInt(train.numInstances())));
}
m_Classifiers[i].buildClassifier(bag);
}
if (getDebug()) System.out.println(":-");
}
开发者ID:IsaacHaze,项目名称:meka,代码行数:25,代码来源:BaggingMLdup.java
示例2: buildClassifier
import weka.core.Randomizable; //导入依赖的package包/类
@Override
public void buildClassifier(Instances train) throws Exception {
testCapabilities(train);
if (getDebug()) System.out.print("-: Models: ");
train = new Instances(train);
m_Classifiers = MultilabelClassifier.makeCopies((MultilabelClassifier)m_Classifier, m_NumIterations);
int sub_size = (train.numInstances()*m_BagSizePercent/100);
for(int i = 0; i < m_NumIterations; i++) {
if(getDebug()) System.out.print(""+i+" ");
if (m_Classifiers[i] instanceof Randomizable) ((Randomizable)m_Classifiers[i]).setSeed(i);
train.randomize(new Random(m_Seed+i));
Instances sub_train = new Instances(train,0,sub_size);
m_Classifiers[i].buildClassifier(sub_train);
}
if (getDebug()) System.out.println(":-");
}
开发者ID:IsaacHaze,项目名称:meka,代码行数:20,代码来源:EnsembleML.java
示例3: buildClassifier
import weka.core.Randomizable; //导入依赖的package包/类
/**
* Builds the committee of randomizable classifiers.
*
* @param data the training data to be used for generating the
* bagged classifier.
* @exception Exception if the classifier could not be built successfully
*/
public void buildClassifier(Instances data) throws Exception {
// can classifier handle the data?
getCapabilities().testWithFail(data);
// remove instances with missing class
data = new Instances(data);
data.deleteWithMissingClass();
if (!(m_Classifier instanceof Randomizable)) {
throw new IllegalArgumentException("Base learner must implement Randomizable!");
}
m_Classifiers = Classifier.makeCopies(m_Classifier, m_NumIterations);
Random random = data.getRandomNumberGenerator(m_Seed);
for (int j = 0; j < m_Classifiers.length; j++) {
// Set the random number seed for the current classifier.
((Randomizable) m_Classifiers[j]).setSeed(random.nextInt());
// Build the classifier.
m_Classifiers[j].buildClassifier(data);
}
}
开发者ID:williamClanton,项目名称:jbossBA,代码行数:33,代码来源:RandomCommittee.java
示例4: buildClassifier
import weka.core.Randomizable; //导入依赖的package包/类
/**
* Builds the committee of randomizable classifiers.
*
* @param data the training data to be used for generating the
* bagged classifier.
* @exception Exception if the classifier could not be built successfully
*/
public void buildClassifier(Instances data) throws Exception {
// can classifier handle the data?
getCapabilities().testWithFail(data);
// get fresh instances
m_data = new Instances(data);
super.buildClassifier(m_data);
if (!(m_Classifier instanceof Randomizable)) {
throw new IllegalArgumentException("Base learner must implement Randomizable!");
}
m_Classifiers = AbstractClassifier.makeCopies(m_Classifier, m_NumIterations);
Random random = m_data.getRandomNumberGenerator(m_Seed);
// Resample data based on weights if base learner can't handle weights
if (!(m_Classifier instanceof WeightedInstancesHandler)) {
m_data = m_data.resampleWithWeights(random);
}
for (int j = 0; j < m_Classifiers.length; j++) {
// Set the random number seed for the current classifier.
((Randomizable) m_Classifiers[j]).setSeed(random.nextInt());
// Build the classifier.
// m_Classifiers[j].buildClassifier(m_data);
}
buildClassifiers();
// save memory
m_data = null;
}
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:44,代码来源:RandomCommittee.java
示例5: buildClassifier
import weka.core.Randomizable; //导入依赖的package包/类
/**
* Builds the committee of randomizable classifiers.
*
* @param data the training data to be used for generating the
* bagged classifier.
* @exception Exception if the classifier could not be built successfully
*/
public void buildClassifier(Instances data) throws Exception {
// can classifier handle the data?
getCapabilities().testWithFail(data);
// remove instances with missing class
m_data = new Instances(data);
m_data.deleteWithMissingClass();
super.buildClassifier(m_data);
if (!(m_Classifier instanceof Randomizable)) {
throw new IllegalArgumentException("Base learner must implement Randomizable!");
}
m_Classifiers = FilteredClassifier.makeCopies(this, m_NumIterations);
Random random = m_data.getRandomNumberGenerator(m_Seed);
for (int j = 0; j < m_Classifiers.length; j++) {
// Set the random number seed for the current classifier.
((Randomizable) m_Classifiers[j]).setSeed(random.nextInt());
// Build the classifier.
// m_Classifiers[j].buildClassifier(m_data);
}
buildClassifiers();
// save memory
m_data = null;
}
开发者ID:dsibournemouth,项目名称:autoweka,代码行数:39,代码来源:RandomCommittee.java
示例6: buildClassifier
import weka.core.Randomizable; //导入依赖的package包/类
/**
* Builds the committee of randomizable classifiers.
*
* @param data the training data to be used for generating the
* bagged classifier.
* @exception Exception if the classifier could not be built successfully
*/
public void buildClassifier(Instances data) throws Exception {
// can classifier handle the data?
getCapabilities().testWithFail(data);
// remove instances with missing class
m_data = new Instances(data);
m_data.deleteWithMissingClass();
super.buildClassifier(m_data);
if (!(m_Classifier instanceof Randomizable)) {
throw new IllegalArgumentException("Base learner must implement Randomizable!");
}
m_Classifiers = AbstractClassifier.makeCopies(m_Classifier, m_NumIterations);
Random random = m_data.getRandomNumberGenerator(m_Seed);
// Resample data based on weights if base learner can't handle weights
if (!(m_Classifier instanceof WeightedInstancesHandler)) {
m_data = m_data.resampleWithWeights(random);
}
for (int j = 0; j < m_Classifiers.length; j++) {
// Set the random number seed for the current classifier.
((Randomizable) m_Classifiers[j]).setSeed(random.nextInt());
// Build the classifier.
// m_Classifiers[j].buildClassifier(m_data);
}
buildClassifiers();
// save memory
m_data = null;
}
开发者ID:umple,项目名称:umple,代码行数:45,代码来源:RandomCommittee.java
示例7: buildClassifier
import weka.core.Randomizable; //导入依赖的package包/类
@Override
public void buildClassifier(Instances train) throws Exception {
testCapabilities(train);
if (getDebug()) System.out.print("-: Models: ");
train = new Instances(train);
m_Classifiers = MultilabelClassifier.makeCopies((MultilabelClassifier)m_Classifier, m_NumIterations);
for(int i = 0; i < m_NumIterations; i++) {
Random r = new Random(m_Seed+i);
Instances bag = new Instances(train,0);
if (m_Classifiers[i] instanceof Randomizable) ((Randomizable)m_Classifiers[i]).setSeed(m_Seed+i);
if(getDebug()) System.out.print(""+i+" ");
int ixs[] = new int[train.numInstances()];
for(int j = 0; j < ixs.length; j++) {
ixs[r.nextInt(ixs.length)]++;
}
for(int j = 0; j < ixs.length; j++) {
if (ixs[j] > 0) {
Instance instance = train.instance(j);
instance.setWeight(ixs[j]);
bag.add(instance);
}
}
m_Classifiers[i].buildClassifier(bag);
}
if (getDebug()) System.out.println(":-");
}
开发者ID:IsaacHaze,项目名称:meka,代码行数:32,代码来源:BaggingML.java
示例8: buildClassifier
import weka.core.Randomizable; //导入依赖的package包/类
/**
* Builds the committee of randomizable classifiers.
*
* @param data the training data to be used for generating the
* bagged classifier.
* @throws Exception if the classifier could not be built successfully
*/
public void buildClassifier(Instances data) throws Exception {
// can classifier handle the data?
getCapabilities().testWithFail(data);
// remove instances with missing class
data = new Instances(data);
data.deleteWithMissingClass();
if (!(m_Classifier instanceof weka.classifiers.meta.nestedDichotomies.ND) &&
!(m_Classifier instanceof weka.classifiers.meta.nestedDichotomies.ClassBalancedND) &&
!(m_Classifier instanceof weka.classifiers.meta.nestedDichotomies.DataNearBalancedND)) {
throw new IllegalArgumentException("END only works with ND, ClassBalancedND " +
"or DataNearBalancedND classifier");
}
m_hashtable = new Hashtable();
m_Classifiers = Classifier.makeCopies(m_Classifier, m_NumIterations);
Random random = data.getRandomNumberGenerator(m_Seed);
for (int j = 0; j < m_Classifiers.length; j++) {
// Set the random number seed for the current classifier.
((Randomizable) m_Classifiers[j]).setSeed(random.nextInt());
// Set the hashtable
if (m_Classifier instanceof weka.classifiers.meta.nestedDichotomies.ND)
((weka.classifiers.meta.nestedDichotomies.ND)m_Classifiers[j]).setHashtable(m_hashtable);
else if (m_Classifier instanceof weka.classifiers.meta.nestedDichotomies.ClassBalancedND)
((weka.classifiers.meta.nestedDichotomies.ClassBalancedND)m_Classifiers[j]).setHashtable(m_hashtable);
else if (m_Classifier instanceof weka.classifiers.meta.nestedDichotomies.DataNearBalancedND)
((weka.classifiers.meta.nestedDichotomies.DataNearBalancedND)m_Classifiers[j]).
setHashtable(m_hashtable);
// Build the classifier.
m_Classifiers[j].buildClassifier(data);
}
}
开发者ID:williamClanton,项目名称:jbossBA,代码行数:47,代码来源:END.java
示例9: buildClassifier
import weka.core.Randomizable; //导入依赖的package包/类
/**
* builds the classifier.
*
* @param data the training data to be used for generating the
* classifier.
* @throws Exception if the classifier could not be built successfully
*/
public void buildClassifier(Instances data) throws Exception {
// can classifier handle the data?
getCapabilities().testWithFail(data);
// get fresh Instances object
m_data = new Instances(data);
// only class? -> build ZeroR model
if (m_data.numAttributes() == 1) {
System.err.println(
"Cannot build model (only class attribute present in data!), "
+ "using ZeroR model instead!");
m_ZeroR = new weka.classifiers.rules.ZeroR();
m_ZeroR.buildClassifier(m_data);
return;
}
else {
m_ZeroR = null;
}
super.buildClassifier(data);
Integer[] indices = new Integer[data.numAttributes()-1];
int classIndex = data.classIndex();
int offset = 0;
for(int i = 0; i < indices.length+1; i++) {
if (i != classIndex) {
indices[offset++] = i+1;
}
}
int subSpaceSize = numberOfAttributes(indices.length, getSubSpaceSize());
Random random = data.getRandomNumberGenerator(m_Seed);
for (int j = 0; j < m_Classifiers.length; j++) {
if (m_Classifier instanceof Randomizable) {
((Randomizable) m_Classifiers[j]).setSeed(random.nextInt());
}
FilteredClassifier fc = new FilteredClassifier();
fc.setClassifier(m_Classifiers[j]);
m_Classifiers[j] = fc;
Remove rm = new Remove();
rm.setOptions(new String[]{"-V", "-R", randomSubSpace(indices,subSpaceSize,classIndex+1,random)});
fc.setFilter(rm);
// build the classifier
//m_Classifiers[j].buildClassifier(m_data);
}
buildClassifiers();
// save memory
m_data = null;
}
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:62,代码来源:RandomSubSpace.java
示例10: buildClassifier
import weka.core.Randomizable; //导入依赖的package包/类
/**
* Build the classifier on the filtered data.
*
* @param data the training data
* @throws Exception if the classifier could not be built successfully
*/
public void buildClassifier(Instances data) throws Exception {
if (m_Classifier == null) {
throw new Exception("No base classifiers have been set!");
}
if (!(m_Classifier instanceof Randomizable) &&
!(m_Filter instanceof Randomizable)) {
throw new Exception("Either the classifier or the filter must implement " +
"the Randomizable interface.");
}
getCapabilities().testWithFail(data);
// get fresh instances object
data = new Instances(data);
if (data.numInstances() == 0) {
throw new Exception("No training instances.");
}
try {
// get a random number generator
Random r = data.getRandomNumberGenerator(m_Seed);
if (m_Filter instanceof Randomizable) {
((Randomizable)m_Filter).setSeed(r.nextInt());
}
m_Filter.setInputFormat(data); // filter capabilities are checked here
data = Filter.useFilter(data, m_Filter);
// can classifier handle the data?
getClassifier().getCapabilities().testWithFail(data);
m_FilteredInstances = data.stringFreeStructure();
if (m_Classifier instanceof Randomizable) {
((Randomizable)m_Classifier).setSeed(r.nextInt());
}
m_Classifier.buildClassifier(data);
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:55,代码来源:RandomizableFilteredClassifier.java
示例11: buildClassifier
import weka.core.Randomizable; //导入依赖的package包/类
/**
* builds the classifier.
*
* @param data the training data to be used for generating the
* classifier.
* @throws Exception if the classifier could not be built successfully
*/
public void buildClassifier(Instances data) throws Exception {
// can classifier handle the data?
getCapabilities().testWithFail(data);
// remove instances with missing class
m_data = new Instances(data);
m_data.deleteWithMissingClass();
// only class? -> build ZeroR model
if (m_data.numAttributes() == 1) {
System.err.println(
"Cannot build model (only class attribute present in data!), "
+ "using ZeroR model instead!");
m_ZeroR = new weka.classifiers.rules.ZeroR();
m_ZeroR.buildClassifier(m_data);
return;
}
else {
m_ZeroR = null;
}
super.buildClassifier(data);
Integer[] indices = new Integer[data.numAttributes()-1];
int classIndex = data.classIndex();
int offset = 0;
for(int i = 0; i < indices.length+1; i++) {
if (i != classIndex) {
indices[offset++] = i+1;
}
}
int subSpaceSize = numberOfAttributes(indices.length, getSubSpaceSize());
Random random = data.getRandomNumberGenerator(m_Seed);
for (int j = 0; j < m_Classifiers.length; j++) {
if (m_Classifier instanceof Randomizable) {
((Randomizable) m_Classifiers[j]).setSeed(random.nextInt());
}
FilteredClassifier fc = new FilteredClassifier();
fc.setClassifier(m_Classifiers[j]);
m_Classifiers[j] = fc;
Remove rm = new Remove();
rm.setOptions(new String[]{"-V", "-R", randomSubSpace(indices,subSpaceSize,classIndex+1,random)});
fc.setFilter(rm);
// build the classifier
//m_Classifiers[j].buildClassifier(m_data);
}
buildClassifiers();
// save memory
m_data = null;
}
开发者ID:dsibournemouth,项目名称:autoweka,代码行数:63,代码来源:RandomSubSpace.java
示例12: buildClassifier
import weka.core.Randomizable; //导入依赖的package包/类
/**
* Build the classifier on the filtered data.
*
* @param data the training data
* @throws Exception if the classifier could not be built successfully
*/
public void buildClassifier(Instances data) throws Exception {
if (m_Classifier == null) {
throw new Exception("No base classifiers have been set!");
}
if (!(m_Classifier instanceof Randomizable) &&
!(m_Filter instanceof Randomizable)) {
throw new Exception("Either the classifier or the filter must implement " +
"the Randomizable interface.");
}
getCapabilities().testWithFail(data);
// remove instances with missing class
data = new Instances(data);
data.deleteWithMissingClass();
if (data.numInstances() == 0) {
throw new Exception("Not enough training instances with class labels.");
}
try {
// get a random number generator
Random r = data.getRandomNumberGenerator(m_Seed);
if (m_Filter instanceof Randomizable) {
((Randomizable)m_Filter).setSeed(r.nextInt());
}
m_Filter.setInputFormat(data); // filter capabilities are checked here
data = Filter.useFilter(data, m_Filter);
// can classifier handle the data?
getClassifier().getCapabilities().testWithFail(data);
m_FilteredInstances = data.stringFreeStructure();
if (m_Classifier instanceof Randomizable) {
((Randomizable)m_Classifier).setSeed(r.nextInt());
}
m_Classifier.buildClassifier(data);
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
开发者ID:umple,项目名称:umple,代码行数:56,代码来源:RandomizableFilteredClassifier.java
示例13: buildClassifier
import weka.core.Randomizable; //导入依赖的package包/类
@Override
public void buildClassifier(Instances D) throws Exception {
testCapabilities(D);
m_InstancesTemplates = new Instances[m_NumIterations];
m_InstanceTemplates = new Instance[m_NumIterations];
if (getDebug()) System.out.println("-: Models: ");
m_Classifiers = MultilabelClassifier.makeCopies((MultilabelClassifier)m_Classifier, m_NumIterations);
Random r = new Random(m_Seed);
int N_sub = (D.numInstances()*m_BagSizePercent/100);
int L = D.classIndex();
int d = D.numAttributes() - L;
int d_new = d * m_AttSizePercent / 100;
m_IndicesCut = new int[m_NumIterations][];
for(int i = 0; i < m_NumIterations; i++) {
// Downsize the instance space (exactly like in EnsembleML.java)
if (getDebug())
System.out.print("\t"+(i+1)+": ");
D.randomize(r);
Instances D_cut = new Instances(D,0,N_sub);
if (getDebug())
System.out.print("N="+D.numInstances()+" -> N'="+D_cut.numInstances()+", ");
// Downsize attribute space
D_cut.setClassIndex(-1);
int indices_a[] = A.make_sequence(L,d+L);
A.shuffle(indices_a,r);
indices_a = Arrays.copyOfRange(indices_a,0,d-d_new);
Arrays.sort(indices_a);
m_IndicesCut[i] = A.invert(indices_a,D.numAttributes());
D_cut = F.remove(D_cut,indices_a,false);
D_cut.setClassIndex(L);
if (getDebug())
System.out.print(" A:="+(D.numAttributes() - L)+" -> A'="+(D_cut.numAttributes() - L)+" ("+m_IndicesCut[i][L]+",...,"+m_IndicesCut[i][m_IndicesCut[i].length-1]+")");
// Train multi-label classifier
if (m_Classifiers[i] instanceof Randomizable) ((Randomizable)m_Classifiers[i]).setSeed(m_Seed+i);
if(getDebug()) System.out.println(".");
m_Classifiers[i].buildClassifier(D_cut);
m_InstanceTemplates[i] = D_cut.instance(1);
m_InstancesTemplates[i] = new Instances(D_cut,0);
}
if (getDebug()) System.out.println(":-");
}
开发者ID:IsaacHaze,项目名称:meka,代码行数:56,代码来源:RandomSubspaceML.java
示例14: buildClassifier
import weka.core.Randomizable; //导入依赖的package包/类
/**
* builds the classifier.
*
* @param data the training data to be used for generating the
* classifier.
* @throws Exception if the classifier could not be built successfully
*/
public void buildClassifier(Instances data) throws Exception {
// can classifier handle the data?
getCapabilities().testWithFail(data);
// remove instances with missing class
data = new Instances(data);
data.deleteWithMissingClass();
// only class? -> build ZeroR model
if (data.numAttributes() == 1) {
System.err.println(
"Cannot build model (only class attribute present in data!), "
+ "using ZeroR model instead!");
m_ZeroR = new weka.classifiers.rules.ZeroR();
m_ZeroR.buildClassifier(data);
return;
}
else {
m_ZeroR = null;
}
super.buildClassifier(data);
Integer[] indices = new Integer[data.numAttributes()-1];
int classIndex = data.classIndex();
int offset = 0;
for(int i = 0; i < indices.length+1; i++) {
if (i != classIndex) {
indices[offset++] = i+1;
}
}
int subSpaceSize = numberOfAttributes(indices.length, getSubSpaceSize());
Random random = data.getRandomNumberGenerator(m_Seed);
for (int j = 0; j < m_Classifiers.length; j++) {
if (m_Classifier instanceof Randomizable) {
((Randomizable) m_Classifiers[j]).setSeed(random.nextInt());
}
FilteredClassifier fc = new FilteredClassifier();
fc.setClassifier(m_Classifiers[j]);
m_Classifiers[j] = fc;
Remove rm = new Remove();
rm.setOptions(new String[]{"-V", "-R", randomSubSpace(indices,subSpaceSize,classIndex+1,random)});
fc.setFilter(rm);
// build the classifier
m_Classifiers[j].buildClassifier(data);
}
}
开发者ID:williamClanton,项目名称:jbossBA,代码行数:59,代码来源:RandomSubSpace.java
注:本文中的weka.core.Randomizable类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论