当前位置: 首页>>代码示例>>Java>>正文


Java Attribute类代码示例

本文整理汇总了Java中weka.core.Attribute的典型用法代码示例。如果您正苦于以下问题:Java Attribute类的具体用法?Java Attribute怎么用?Java Attribute使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Attribute类属于weka.core包,在下文中一共展示了Attribute类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: instanceToDenseDMatrix

import weka.core.Attribute; //导入依赖的package包/类
public static DMatrix instanceToDenseDMatrix(Instance instance) throws XGBoostError {
    Attribute classAttribute = instance.classAttribute();
    int classAttrIndex = classAttribute.index();

    int colNum = instance.numAttributes()-1;
    int rowNum = 1;

    float[] data = new float[colNum*rowNum];

    Enumeration<Attribute> attributeEnumeration = instance.enumerateAttributes();
    int dataIndex = 0;
    while (attributeEnumeration.hasMoreElements()) {
        Attribute attribute = attributeEnumeration.nextElement();
        int attrIndex = attribute.index();
        if(attrIndex == classAttrIndex){
            continue;
        }
        data[dataIndex]= (float) instance.value(attribute);
        dataIndex++;
    }

    return new DMatrix(data, rowNum, colNum);
}
 
开发者ID:SigDelta,项目名称:weka-xgboost,代码行数:24,代码来源:DMatrixLoader.java

示例2: isClassTheMajortiy

import weka.core.Attribute; //导入依赖的package包/类
private boolean isClassTheMajortiy(ArrayList<Instance> instances, double classification){
	
	List<Instance> instancesList = new ArrayList<>(instances);
	TreeMap<Double, Double> classificationProbability = new TreeMap<>();
	Attribute classAttribute = instances.get(0).classAttribute();
	
	for (double i = 0; i < classAttribute.numValues(); i++) {
		int matchedClassCount = 0;
		
		for (Instance instance : instancesList) {
			if(instance.classValue() == i){
				matchedClassCount++;
			}
		}
		
		classificationProbability.put(((double) matchedClassCount / (double) instancesList.size()), i);
	}
	
	return (classificationProbability.lastEntry().getValue() == classification);
}
 
开发者ID:thienle2401,项目名称:G-eRules,代码行数:21,代码来源:GeRules.java

示例3: main

import weka.core.Attribute; //导入依赖的package包/类
public static void main(String[] args){
	ArrayList<Attribute> atts = new ArrayList<Attribute>();
	
	/*Properties p1 = new Properties();
	p1.setProperty("range", "[0,1]");
	ProtectedProperties prop1 = new ProtectedProperties(p1);*/
	
	Properties p2 = new Properties();
	p2.setProperty("range", "[321,1E9]");
	ProtectedProperties prop2 = new ProtectedProperties(p2);
	
	ArrayList<String> attVals = new ArrayList<String>();
	for (int i = 0; i < 5; i++)
	      attVals.add("val" + (i+1));
	
	//atts.add(new Attribute("att1", prop1));
	atts.add(new Attribute("att2", prop2));
	//atts.add(new Attribute("att3", attVals));
	//Instances data = LHSInitializer.getMultiDimContinuous(atts, 10, false);
	//Instances data = LHSInitializer.getMultiDim(atts, 10, false);
	Instances data = LHSInitializer.getMultiDimContinuous(atts, 1, false);
	
	System.out.println(data);
}
 
开发者ID:zhuyuqing,项目名称:bestconf,代码行数:25,代码来源:LHSInitializer.java

示例4: createDataSet

import weka.core.Attribute; //导入依赖的package包/类
private Instances createDataSet(List<ConceptSimilarityMeasure> sims) {

		ArrayList<Attribute> atts = new ArrayList<Attribute>();
		for (ConceptSimilarityMeasure sim : sims)
			atts.add(new Attribute(sim.getName()));

		List<String> classes = new ArrayList<String>();
		classes.add("no merge");
		classes.add("merge");
		atts.add(new Attribute("class", classes));

		Instances data = new Instances("data", atts, 0);
		data.setClassIndex(data.numAttributes() - 1);

		return data;
	}
 
开发者ID:UKPLab,项目名称:ijcnlp2017-cmaps,代码行数:17,代码来源:ConceptGrouperSimLog.java

示例5: ModelClassifier

import weka.core.Attribute; //导入依赖的package包/类
public ModelClassifier() {
    name = new Attribute("name");
    type = new Attribute("type");
    attributes = new ArrayList();
    classVal = new ArrayList();
    classVal.add("Monday");
    classVal.add("Tuesday");
    classVal.add("Wednesday");
    classVal.add("Thursday");
    classVal.add("Friday");
    classVal.add("Saturday");
    classVal.add("Sunday");
    
    attributes.add(name);
    attributes.add(type);

    attributes.add(new Attribute("class", classVal));
    dataRaw = new Instances("TestInstances", attributes, 0);
    dataRaw.setClassIndex(dataRaw.numAttributes() - 1);
}
 
开发者ID:sfahadahmed,项目名称:hungrydragon,代码行数:21,代码来源:ModelClassifier.java

示例6: main

import weka.core.Attribute; //导入依赖的package包/类
public static void main(String[] args){
	ArrayList<Attribute> atts = new ArrayList<Attribute>();
	
	/*Properties p1 = new Properties();
	p1.setProperty("range", "[0,1]");
	ProtectedProperties prop1 = new ProtectedProperties(p1);*/
	
	Properties p2 = new Properties();
	p2.setProperty("range", "[321,1E9]");
	ProtectedProperties prop2 = new ProtectedProperties(p2);
	
	ArrayList<String> attVals = new ArrayList<String>();
	for (int i = 0; i < 5; i++)
	      attVals.add("val" + (i+1));
	
	//atts.add(new Attribute("att1", prop1));
	atts.add(new Attribute("att2", prop2));
	//atts.add(new Attribute("att3", attVals));
	//Instances data = LHSInitializer.getMultiDimContinuous(atts, 10, false);
	//Instances data = LHSInitializer.getMultiDim(atts, 10, false);
	LHSSampler sampler = new LHSSampler();
	Instances data = sampler.sampleMultiDimContinuous(atts, 1, false);
	
	System.out.println(data);
}
 
开发者ID:zhuyuqing,项目名称:bestconf,代码行数:26,代码来源:LHSSampler.java

示例7: relationToInstances

import weka.core.Attribute; //导入依赖的package包/类
/**
 * Create an Instances object from the tuples provided. The Instances has
 * name `name` and every value from every tuple. The TupleDesc is provided
 * separately just to validate that all of the provided Tuples share this
 * TupleDesc.
 * @param name the name of the resulting Instances object
 * @param ts list of Tuples
 * @param td TupleDesc
 * @param fields indices identifying which fields should be included in the new Instances object.
 * @return new Instances object containing the values from all the tuples.
 */
public static Instances relationToInstances(String name, List<Tuple> ts, TupleDesc td,
        List<Integer> fields){
    ArrayList<Attribute> attrs = tupleDescToAttributeList(td, fields);
    int relationSize = ts.size();
    Instances instances = new Instances(name, attrs, relationSize);
    
    for (int i=0; i<ts.size(); i++){
        Tuple t = ts.get(i);
        if (!t.getTupleDesc().equals(td)){
            throw new RuntimeException("All TupleDescs must match.");
        }
        instances.add(i, tupleToInstance(t, attrs, fields));
    }
    
    return instances;
}
 
开发者ID:mitdbg,项目名称:imputedb,代码行数:28,代码来源:WekaUtil.java

示例8: setOptimal

import weka.core.Attribute; //导入依赖的package包/类
/**
 * set the bestConf to cluster and get the running performance
 * @param attributeToVal
 * @return
 */
public double setOptimal(Map<Attribute,Double> attributeToVal){
	HashMap hm = new HashMap();
	for(Attribute key : attributeToVal.keySet()){
		Double value = attributeToVal.get(key);
		hm.put(key.name(), value);
	}
	this.startTest(hm, 0, false);
	double y = 0;
	y = performance;
	return y;
}
 
开发者ID:zhuyuqing,项目名称:BestConfig,代码行数:17,代码来源:AutoTestAdjust.java

示例9: prefix2attributes

import weka.core.Attribute; //导入依赖的package包/类
/**
 * Helper method to convet Feature keys to Attributes
 * @param data
 * @param prefixes
 * @return
 */
public static Set<Attribute> prefix2attributes(Instances data, String...prefixes) {
    Set<Attribute> attributes = new ListOrderedSet<Attribute>();
    for (String key : prefixes) {
        Attribute attribute = data.attribute(key);
        assert(attribute != null) : "Invalid Attribute key '" + key + "'";
        attributes.add(attribute);
    } // FOR
    return (attributes);
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:16,代码来源:FeatureClusterer.java

示例10: convertToArff

import weka.core.Attribute; //导入依赖的package包/类
public static Instances convertToArff(List<Document> dataSet, List<String> vocabulary, String fileName) {
    int dataSetSize = dataSet.size();
    /* Create features */
    ArrayList<Attribute> attributes = new ArrayList<>();
    for (int i = 0; i < vocabulary.size(); i++) {
        attributes.add(new Attribute("word_" + i));
    }
    Attribute classAttribute = new Attribute("Class");
    attributes.add(classAttribute);

    /* Add examples */
    System.out.println("Building instances...");
    Instances trainingDataSet = new Instances(fileName, attributes, 0);
    for (int k = 0; k < dataSetSize; k++) {
        Document document = dataSet.get(k);
        Instance example = new DenseInstance(attributes.size());
        for (int i = 0; i < vocabulary.size(); i++) {
            String word = vocabulary.get(i);
            example.setValue(i, Collections.frequency(document.getTerms(), word));
        }
        example.setValue(classAttribute, document.getDocumentClass());
        trainingDataSet.add(example);
        int progress = (int) ((k * 100.0) / dataSetSize);
        System.out.printf("\rPercent completed: %3d%%", progress);
    }
    trainingDataSet.setClass(classAttribute);
    System.out.println();

    System.out.println("Writing to file ...");
    try {
        ArffSaver saver = new ArffSaver();
        saver.setInstances(trainingDataSet);
        saver.setFile(new File(fileName));
        saver.writeBatch();
    } catch (IOException e) {
        e.printStackTrace();
    }

    return trainingDataSet;
}
 
开发者ID:MarkXLII,项目名称:CS-436_580L_Introduction-to-Machine-Learning,代码行数:41,代码来源:Utils.java

示例11: uniBoundsGeneration

import weka.core.Attribute; //导入依赖的package包/类
private static void uniBoundsGeneration(double[] bounds, Attribute crntAttr, int sampleSetSize){
	bounds[0] = crntAttr.getLowerNumericBound();
	bounds[sampleSetSize] = crntAttr.getUpperNumericBound();
	double pace = (bounds[sampleSetSize] - bounds[0])/sampleSetSize;
	for(int j=1;j<sampleSetSize;j++){
		bounds[j] = bounds[j-1] + pace;
	}
}
 
开发者ID:zhuyuqing,项目名称:BestConfig,代码行数:9,代码来源:LHSInitializer.java

示例12: Term

import weka.core.Attribute; //导入依赖的package包/类
/**
 * Constructor for numeric attribute, each numeric attribute is
 * represented by a term in form of x <= value < y
 * 
 * @param attributeIn
 * @param attributeIndexIn
 */
public Term(Attribute attributeIn, double attributeIndexIn){
    
    attribute = attributeIn;
    setAttributeIndex(attributeIndexIn);
    
    // set type of the attribute
    if(attributeIn.isNumeric()){
        attributeType = TypeNumeric;
    }else{
        attributeType = 0;
    }
}
 
开发者ID:thienle2401,项目名称:GeneralisedRulesAlgorithm,代码行数:20,代码来源:GRules.java

示例13: tupleDescToAttributeList

import weka.core.Attribute; //导入依赖的package包/类
/**
 * Create a list of Weka Attributes from a TupleDesc. The resulting list is
 * suitable to pass to an Instances object.
 * @param td the TupleDesc
 * @return the list of Attributes
 */
public static ArrayList<Attribute> tupleDescToAttributeList(TupleDesc td){
    List<Integer> fields = new ArrayList<>();
    for (int i=0; i<td.numFields(); i++){
        fields.add(i);
    }
    return tupleDescToAttributeList(td, fields);
}
 
开发者ID:mitdbg,项目名称:imputedb,代码行数:14,代码来源:WekaUtil.java

示例14: main

import weka.core.Attribute; //导入依赖的package包/类
public static void main(String[] args){
	ArrayList<Attribute> atts = new ArrayList<Attribute>();
	
	Properties p1 = new Properties();
	p1.setProperty("range", "[0,1]");
	ProtectedProperties prop1 = new ProtectedProperties(p1);
	
	Properties p2 = new Properties();
	p2.setProperty("range", "[321,1E9]");
	ProtectedProperties prop2 = new ProtectedProperties(p2);
	
	Properties p3 = new Properties();
	p3.setProperty("range", "[1,30]");
	ProtectedProperties prop3 = new ProtectedProperties(p3);
	
	ArrayList<String> attVals = new ArrayList<String>();
	for (int i = 0; i < 5; i++)
	      attVals.add("val" + (i+1));
	
	atts.add(new Attribute("att1", prop1));
	atts.add(new Attribute("att2", prop2));
	atts.add(new Attribute("att3", prop3));
	//atts.add(new Attribute("att4", attVals));
	//Instances data = LHSInitializer.getMultiDimContinuous(atts, 10, false);
	//Instances data = LHSInitializer.getMultiDim(atts, 10, false);
	DDSSampler sampler = new DDSSampler(3);
	
	sampler.setCurrentRound(0);
	Instances data = sampler.sampleMultiDimContinuous(atts, 2, false);
	System.out.println(data);
	
	sampler.setCurrentRound(01);
	data = sampler.sampleMultiDimContinuous(atts, 2, false);
	System.out.println(data);
	
	sampler.setCurrentRound(2);
	data = sampler.sampleMultiDimContinuous(atts, 2, false);
	System.out.println(data);
}
 
开发者ID:zhuyuqing,项目名称:BestConfig,代码行数:40,代码来源:DDSSampler.java

示例15: getNominalAttribute

import weka.core.Attribute; //导入依赖的package包/类
private Attribute getNominalAttribute(Fields field) {
    Set<String> values = new HashSet<>();
    for(Object obj: dataDomain.get(field.name()))
        values.add(Conversion.getValueAsStr(obj));

    return new Attribute(field.name(), new ArrayList<>(values));
}
 
开发者ID:GeorgiMateev,项目名称:twitter-user-gender-classification,代码行数:8,代码来源:BaseFeaturesFactory.java


注:本文中的weka.core.Attribute类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。