當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。