本文整理汇总了Java中weka.filters.unsupervised.attribute.NumericToNominal.setInputFormat方法的典型用法代码示例。如果您正苦于以下问题:Java NumericToNominal.setInputFormat方法的具体用法?Java NumericToNominal.setInputFormat怎么用?Java NumericToNominal.setInputFormat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类weka.filters.unsupervised.attribute.NumericToNominal
的用法示例。
在下文中一共展示了NumericToNominal.setInputFormat方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildAssociate
import weka.filters.unsupervised.attribute.NumericToNominal; //导入方法依赖的package包/类
public static String buildAssociate() throws Exception {
InstanceQuery query = new InstanceQuery();
query.setUsername("root");
query.setPassword("cs6310");
query.setDatabaseURL("jdbc:mysql://localhost/system?#characterEncoding=UTF-8");
query.setQuery("select * from courses_sessions;");
// You can declare that your data set is sparse
// query.setSparseData(true);
Instances data = query.retrieveInstances();
data.setClassIndex(data.numAttributes() - 1);
final NumericToNominal filter = new NumericToNominal();
filter.setInputFormat(data);
data = Filter.useFilter(data, filter);
if (data.size() > 0) {
// build associator
Apriori apriori = new Apriori();
apriori.setClassIndex(data.classIndex());
apriori.buildAssociations(data);
return String.valueOf(apriori);
} else {
return "Not enough data provided";
}
}
示例2: splitWorkload
import weka.filters.unsupervised.attribute.NumericToNominal; //导入方法依赖的package包/类
/**
*
* @param data
* @return
*/
protected Instances[] splitWorkload(Instances data) {
int offset = 0;
int all_cnt = data.numInstances();
for (SplitType stype : SplitType.values()) {
int idx = stype.ordinal();
this.split_counts[idx] = (int)Math.round(all_cnt * stype.percentage);
try {
this.splits[idx] = new Instances(data, offset, this.split_counts[idx]);
// Apply NumericToNominal filter!
NumericToNominal filter = new NumericToNominal();
filter.setInputFormat(this.splits[idx]);
this.splits[idx] = Filter.useFilter(this.splits[idx], filter);
} catch (Exception ex) {
throw new RuntimeException("Failed to split " + stype + " workload", ex);
}
offset += this.split_counts[idx];
if (debug.val) LOG.debug(String.format("%-12s%d", stype.toString()+":", this.split_counts[idx]));
} // FOR
return (this.splits);
}
示例3: generateDecisionTree
import weka.filters.unsupervised.attribute.NumericToNominal; //导入方法依赖的package包/类
protected Classifier generateDecisionTree(AbstractClusterer clusterer, MarkovAttributeSet aset, Instances data) throws Exception {
// We need to create a new Attribute that has the ClusterId
Instances newData = data; // new Instances(data);
newData.insertAttributeAt(new Attribute("ClusterId"), newData.numAttributes());
Attribute cluster_attr = newData.attribute(newData.numAttributes()-1);
assert(cluster_attr != null);
assert(cluster_attr.index() > 0);
newData.setClass(cluster_attr);
// We will then tell the Classifier to predict that ClusterId based on the MarkovAttributeSet
ObjectHistogram<Integer> cluster_h = new ObjectHistogram<Integer>();
for (int i = 0, cnt = newData.numInstances(); i < cnt; i++) {
// Grab the Instance and throw it at the the clusterer to get the target cluster
Instance inst = newData.instance(i);
int c = (int)clusterer.clusterInstance(inst);
inst.setClassValue(c);
cluster_h.put(c);
} // FOR
System.err.println("Number of Elements: " + cluster_h.getValueCount());
System.err.println(cluster_h);
NumericToNominal filter = new NumericToNominal();
filter.setInputFormat(newData);
newData = Filter.useFilter(newData, filter);
String output = this.catalog_proc.getName() + "-labeled.arff";
FileUtil.writeStringToFile(output, newData.toString());
LOG.info("Wrote labeled data set to " + output);
// Decision Tree
J48 j48 = new J48();
String options[] = {
"-S", Integer.toString(this.rand.nextInt()),
};
j48.setOptions(options);
// Make sure we add the ClusterId attribute to a new MarkovAttributeSet so that
// we can tell the Classifier to classify that!
FilteredClassifier fc = new FilteredClassifier();
MarkovAttributeSet classifier_aset = new MarkovAttributeSet(aset);
classifier_aset.add(cluster_attr);
fc.setFilter(classifier_aset.createFilter(newData));
fc.setClassifier(j48);
// Bombs away!
fc.buildClassifier(newData);
return (fc);
}
示例4: setUp
import weka.filters.unsupervised.attribute.NumericToNominal; //导入方法依赖的package包/类
@Override
protected void setUp() throws Exception {
super.setUp(ProjectType.TPCC);
this.addPartitions(NUM_PARTITIONS);
HStoreConf.singleton().site.markov_path_caching = false;
if (workload == null) {
catalog_proc = this.getProcedure(TARGET_PROCEDURE);
File file = this.getWorkloadFile(ProjectType.TPCC);
workload = new Workload(catalog);
// Check out this beauty:
// (1) Filter by procedure name
// (2) Filter on partitions that start on our BASE_PARTITION
// (3) Filter to only include multi-partition txns
// (4) Another limit to stop after allowing ### txns
// Where is your god now???
edu.brown.workload.filters.Filter filter = new ProcedureNameFilter(false)
.include(TARGET_PROCEDURE.getSimpleName())
// .attach(new ProcParameterValueFilter().include(1, new Long(5))) // D_ID
// .attach(new ProcParameterArraySizeFilter(CatalogUtil.getArrayProcParameters(catalog_proc).get(0), 10, ExpressionType.COMPARE_EQUAL))
// .attach(new BasePartitionTxnFilter(p_estimator, BASE_PARTITION))
// .attach(new MultiPartitionTxnFilter(p_estimator))
.attach(new ProcedureLimitFilter(WORKLOAD_XACT_LIMIT));
workload.load(file, catalog_db, filter);
assert(workload.getTransactionCount() > 0);
// Now extract the FeatureSet that we will use in our tests
Map<Procedure, FeatureSet> fsets = new FeatureExtractor(catalogContext, p_estimator).calculate(workload);
FeatureSet fset = fsets.get(catalog_proc);
assertNotNull(fset);
data = fset.export(catalog_proc.getName(), false);
NumericToNominal weka_filter = new NumericToNominal();
weka_filter.setInputFormat(data);
data = Filter.useFilter(data, weka_filter);
}
assertNotNull(data);
fclusterer = new FeatureClusterer(catalogContext, catalog_proc, workload, catalogContext.getAllPartitionIds());
}