當前位置: 首頁>>代碼示例>>Java>>正文


Java Instances.insertAttributeAt方法代碼示例

本文整理匯總了Java中weka.core.Instances.insertAttributeAt方法的典型用法代碼示例。如果您正苦於以下問題:Java Instances.insertAttributeAt方法的具體用法?Java Instances.insertAttributeAt怎麽用?Java Instances.insertAttributeAt使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在weka.core.Instances的用法示例。


在下文中一共展示了Instances.insertAttributeAt方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: generateMore

import weka.core.Instances; //導入方法依賴的package包/類
public Instances generateMore(int number, int existedNum,
		Instances header) {
	ArrayList<Attribute> localAtts = new ArrayList<Attribute>();
	Enumeration<Attribute> enu = header.enumerateAttributes();
	while (enu.hasMoreElements()) {
		localAtts.add(enu.nextElement());
	}
	Instances samplePoints = LHSInitializer.getMultiDimContinuous(
			localAtts, number + existedNum, false);
	samplePoints.insertAttributeAt(header.classAttribute(),
			samplePoints.numAttributes());
	samplePoints.setClassIndex(samplePoints.numAttributes() - 1);
	return samplePoints;
}
 
開發者ID:zhuyuqing,項目名稱:bestconf,代碼行數:15,代碼來源:BestConf.java

示例2: testCOMT2

import weka.core.Instances; //導入方法依賴的package包/類
public static void testCOMT2() throws Exception{
	BestConf bestconf = new BestConf();
	Instances trainingSet = DataIOFile.loadDataFromArffFile("data/trainingBestConf0.arff");
	trainingSet.setClassIndex(trainingSet.numAttributes()-1);
	
	Instances samplePoints = LHSInitializer.getMultiDimContinuous(bestconf.getAttributes(), InitialSampleSetSize, false);
	samplePoints.insertAttributeAt(trainingSet.classAttribute(), samplePoints.numAttributes());
	samplePoints.setClassIndex(samplePoints.numAttributes()-1);
	
	COMT2 comt = new COMT2(samplePoints, COMT2Iteration);
	
	comt.buildClassifier(trainingSet);
	
	Evaluation eval = new Evaluation(trainingSet);
	eval.evaluateModel(comt, trainingSet);
	System.err.println(eval.toSummaryString());
	
	Instance best = comt.getInstanceWithPossibleMaxY(samplePoints.firstInstance());
	Instances bestInstances = new Instances(trainingSet,2);
	bestInstances.add(best);
	DataIOFile.saveDataToXrffFile("data/trainingBestConf_COMT2.arff", bestInstances);
	
	//now we output the training set with the class value updated as the predicted value
	Instances output = new Instances(trainingSet, trainingSet.numInstances());
	Enumeration<Instance> enu = trainingSet.enumerateInstances();
	while(enu.hasMoreElements()){
		Instance ins = enu.nextElement();
		double[] values = ins.toDoubleArray();
		values[values.length-1] = comt.classifyInstance(ins);
		output.add(ins.copy(values));
	}
	DataIOFile.saveDataToXrffFile("data/trainingBestConf0_predict.xrff", output);
}
 
開發者ID:zhuyuqing,項目名稱:bestconf,代碼行數:34,代碼來源:BestConf.java

示例3: collectPerfs

import weka.core.Instances; //導入方法依賴的package包/類
@Override
public Instances collectPerfs(Instances samplePoints, String perfAttName) {
	Instances retVal = null;
	
	if(samplePoints.attribute(perfAttName) == null){
		Attribute performance = new Attribute(perfAttName);
		samplePoints.insertAttributeAt(performance, samplePoints.numAttributes());
	}
	
	File perfFolder = new File(perfsfilepath);
	int tot=0;
	if(perfFolder.exists()){
		//let's get all the name set for the sample points
		Iterator<Instance> itr = samplePoints.iterator();
		TreeSet<String> insNameSet = new TreeSet<String>();
		HashMap<String, Integer> mapping = new HashMap<String, Integer>();
		int pos=0;
		while(itr.hasNext()){
			String mdstr = getMD5(itr.next());
			insNameSet.add(mdstr);
			mapping.put(mdstr, new Integer(pos++));
		}
		
		//now we collect
		File[] perfFiles = perfFolder.listFiles(new PerfsFileFilter(insNameSet));
		tot = perfFiles.length;
		if(tot > 0) isInterrupt = true;
		for(int i=0;i<tot;i++){
			Instance ins = samplePoints.get(mapping.get(perfFiles[i].getName()));
			double[] results = getPerf(perfFiles[i].getAbsolutePath());
			if(results!=null){
				ins.setValue(samplePoints.numAttributes()-1, results[0]);
			}
		}
	}
	retVal = samplePoints;
	retVal.setClassIndex(retVal.numAttributes()-1);
	System.out.println("Total number of collected performances is : "+tot);
	return retVal;
}
 
開發者ID:zhuyuqing,項目名稱:bestconf,代碼行數:41,代碼來源:AutoTestAdjust.java

示例4: generateDecisionTree

import weka.core.Instances; //導入方法依賴的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);
}
 
開發者ID:s-store,項目名稱:sstore-soft,代碼行數:51,代碼來源:FeatureClusterer.java

示例5: runExp

import weka.core.Instances; //導入方法依賴的package包/類
public Instances runExp(Instances samplePoints, String perfAttName){
	Instances retVal = null;
	if(samplePoints.attribute(perfAttName) == null){
		Attribute performance = new Attribute(perfAttName);
		samplePoints.insertAttributeAt(performance, samplePoints.numAttributes());
	}
	int pos = samplePoints.numInstances();
	int count = 0;
	for (int i = 0; i < pos; i++) {
		Instance ins = samplePoints.get(i);
		HashMap hm = new HashMap();
		int tot = 0;
		for (int j = 0; j < ins.numAttributes(); j++) {
			hm.put(ins.attribute(j).name(), ins.value(ins.attribute(j)));
		}

		boolean testRet;
		if (Double.isNaN(ins.value(ins.attribute(ins.numAttributes() - 1)))) {
			testRet = this.startTest(hm, i, isInterrupt);
			double y = 0;
			if (!testRet) {// the setting does not work, we skip it
				y = -1;
				count++;
				if (count >= targetTestErrorNum) {
					System.out.println("There must be somthing wrong with the system. Please check and restart.....");
					System.exit(1);
				}
			} else {
				y = getPerformanceByType(performanceType);
				count = 0;
			}

			ins.setValue(samplePoints.numAttributes() - 1, y);
			writePerfstoFile(ins);
		} else {
			continue;
		}
	}
	retVal = samplePoints;
	retVal.setClassIndex(retVal.numAttributes()-1);
	
	return retVal;
}
 
開發者ID:zhuyuqing,項目名稱:bestconf,代碼行數:44,代碼來源:AutoTestAdjust.java

示例6: ConstructionInstances

import weka.core.Instances; //導入方法依賴的package包/類
public Instances ConstructionInstances(Instances data) throws Exception{
    String tweet, tweetS, tweetLem;
    Instances newData = new Instances(data);
    if (prop.getProperty("SyntacticFeatures.countElongatedWords").equalsIgnoreCase("yes")) newData.insertAttributeAt(new Attribute("_numberElongatedWords"), newData.numAttributes());
    if (prop.getProperty("SyntacticFeatures.presencePunctuation").equalsIgnoreCase("yes")) newData.insertAttributeAt(new Attribute("_punctuation"), newData.numAttributes());
    if (prop.getProperty("SyntacticFeatures.countCapitalizations").equalsIgnoreCase("yes")) newData.insertAttributeAt(new Attribute("_allCaps"), newData.numAttributes());
    if (prop.getProperty("SyntacticFeatures.presenceSmileys").equalsIgnoreCase("yes")) newData.insertAttributeAt(new Attribute("_emoticonePos"), newData.numAttributes());
    if (prop.getProperty("SyntacticFeatures.presenceSmileys").equalsIgnoreCase("yes")) newData.insertAttributeAt(new Attribute("_emoticoneNeg"), newData.numAttributes());
    if (prop.getProperty("SyntacticFeatures.countHashtags").equalsIgnoreCase("yes")) newData.insertAttributeAt(new Attribute("_hashtags"), newData.numAttributes());
    if (prop.getProperty("SyntacticFeatures.countNegators").equalsIgnoreCase("yes")) newData.insertAttributeAt(new Attribute("_countNegators"), newData.numAttributes());
    if (prop.getProperty("SyntacticFeatures.presencePartOfSpeechTags").equalsIgnoreCase("yes")) for (int j=0; j<POS.size(); j++) newData.insertAttributeAt(new Attribute("__"+POS.get(j)), newData.numAttributes());
    // Lexicons
    if (prop.getProperty("Lexicons.feelPol").equalsIgnoreCase("yes")) newData.insertAttributeAt(new Attribute("_countPosFEEL"), newData.numAttributes());
    if (prop.getProperty("Lexicons.feelPol").equalsIgnoreCase("yes")) newData.insertAttributeAt(new Attribute("_countNegFEEL"), newData.numAttributes());
    if (prop.getProperty("Lexicons.polarimotsPol").equalsIgnoreCase("yes")) newData.insertAttributeAt(new Attribute("_countPosPolarimots"), newData.numAttributes());
    if (prop.getProperty("Lexicons.polarimotsPol").equalsIgnoreCase("yes")) newData.insertAttributeAt(new Attribute("_countNegPolarimots"), newData.numAttributes());
    if (prop.getProperty("Lexicons.polarimotsPol").equalsIgnoreCase("yes")) newData.insertAttributeAt(new Attribute("_countNeuPolarimots"), newData.numAttributes());
    if (prop.getProperty("Lexicons.affectsPol").equalsIgnoreCase("yes")) newData.insertAttributeAt(new Attribute("_countPosAffects"), newData.numAttributes());
    if (prop.getProperty("Lexicons.affectsPol").equalsIgnoreCase("yes")) newData.insertAttributeAt(new Attribute("_countNegAffects"), newData.numAttributes());
    if (prop.getProperty("Lexicons.affectsPol").equalsIgnoreCase("yes")) newData.insertAttributeAt(new Attribute("_countNeuAffects"), newData.numAttributes());
    if (prop.getProperty("Lexicons.dikoPol").equalsIgnoreCase("yes")) newData.insertAttributeAt(new Attribute("_countPosDiko"), newData.numAttributes());
    if (prop.getProperty("Lexicons.dikoPol").equalsIgnoreCase("yes")) newData.insertAttributeAt(new Attribute("_countNegDiko"), newData.numAttributes());
    if (prop.getProperty("Lexicons.dikoPol").equalsIgnoreCase("yes")) newData.insertAttributeAt(new Attribute("_countNeuDiko"), newData.numAttributes());
    if (prop.getProperty("Lexicons.feelEmo").equalsIgnoreCase("yes")) for (int i=0; i<nbClassesFEEL; i++) newData.insertAttributeAt(new Attribute("_countEmotionFEEL"+(i+1)), newData.numAttributes());
    if (prop.getProperty("Lexicons.affectsEmo").equalsIgnoreCase("yes")) for (int i=0; i<nbClassesAffects; i++) newData.insertAttributeAt(new Attribute("_countEmotionAffects"+(i+1)), newData.numAttributes());
    if (prop.getProperty("Lexicons.dikoEmo").equalsIgnoreCase("yes")) for (int i=0; i<nbClassesDiko; i++) newData.insertAttributeAt(new Attribute("_countEmotionDiko"+(i+1)), newData.numAttributes());
    if (prop.getProperty("Lexicons.incongruity").equalsIgnoreCase("yes")) newData.insertAttributeAt(new Attribute("_countIncongruity"), newData.numAttributes());
    if (prop.getProperty("Lexicons.incongruityAll").equalsIgnoreCase("yes")) newData.insertAttributeAt(new Attribute("_countIncongruityAll"), newData.numAttributes());
    // Data
    for (int i=0; i<newData.numInstances(); i++){
        tweet = newData.instance(i).stringValue(data.attribute("_text"));
        tweetS = tweet;
        // Preprocessings1
        if (prop.getProperty("Preprocessings.normalizeHyperlinks").equalsIgnoreCase("yes")) tweet = Pretraitements.ReplaceLink(tweet);
        if (prop.getProperty("Preprocessings.normalizeEmails").equalsIgnoreCase("yes")) tweet = Pretraitements.ReplaceMail(tweet);
        if (prop.getProperty("Preprocessings.replacePseudonyms").equalsIgnoreCase("yes")) tweet = Pretraitements.ReplaceUserTag(tweet);
        if (prop.getProperty("Preprocessings.normalizeSlang").equalsIgnoreCase("yes")) tweet = Pretraitements.ReplaceArgots(tweet);
        // Syntactic features
        if (prop.getProperty("SyntacticFeatures.countElongatedWords").equalsIgnoreCase("yes")) newData.instance(i).setValue(newData.attribute("_numberElongatedWords"), ca.ElongatedWords(tweet));
        if (prop.getProperty("SyntacticFeatures.presencePunctuation").equalsIgnoreCase("yes")) newData.instance(i).setValue(newData.attribute("_punctuation"), (tweet.contains("!") || tweet.contains("?"))? 1 : 0);
        if (prop.getProperty("SyntacticFeatures.countCapitalizations").equalsIgnoreCase("yes")) newData.instance(i).setValue(newData.attribute("_allCaps"), ca.AllCaps(tweet));
        if (prop.getProperty("SyntacticFeatures.presenceSmileys").equalsIgnoreCase("yes")) newData.instance(i).setValue(newData.attribute("_emoticonePos"), ((ca.EmoticonesPos(tweet))? 1 : 0));
        if (prop.getProperty("SyntacticFeatures.presenceSmileys").equalsIgnoreCase("yes")) newData.instance(i).setValue(newData.attribute("_emoticoneNeg"), ((ca.EmoticonesNeg(tweet))? 1 : 0));
        if (prop.getProperty("SyntacticFeatures.countHashtags").equalsIgnoreCase("yes")) newData.instance(i).setValue(newData.attribute("_hashtags"), ca.CountHashtag(tweet));
        if (prop.getProperty("SyntacticFeatures.countNegators").equalsIgnoreCase("yes")) newData.instance(i).setValue(newData.attribute("_countNegators"), (ca.CountNegation(tweet)));
        if (prop.getProperty("SyntacticFeatures.presencePartOfSpeechTags").equalsIgnoreCase("yes")) for (int j=0; j<POS.size(); j++) newData.instance(i).setValue(newData.attribute("__"+POS.get(j)), ca.POS(tweet,POS.get(j)));
        // Preprocessings2
        if (prop.getProperty("Preprocessings.lowercase").equalsIgnoreCase("yes")) tweet = tweet.toLowerCase();
        if (prop.getProperty("Preprocessings.lemmatize").equalsIgnoreCase("yes")) tweet = ca.Lemmatiser(tweet);
        newData.instance(i).setValue(newData.attribute("_text"), tweet);
        // Lexicons
        tweetLem = tweetS.toLowerCase();
        tweetLem = ca.Lemmatiser(tweetLem);
        if (prop.getProperty("Lexicons.feelPol").equalsIgnoreCase("yes")) newData.instance(i).setValue(newData.attribute("_countPosFEEL"), ca.ComputePosFEEL(tweetLem));
        if (prop.getProperty("Lexicons.feelPol").equalsIgnoreCase("yes")) newData.instance(i).setValue(newData.attribute("_countNegFEEL"), ca.ComputeNegFEEL(tweetLem));
        if (prop.getProperty("Lexicons.polarimotsPol").equalsIgnoreCase("yes")) newData.instance(i).setValue(newData.attribute("_countPosPolarimots"), ca.ComputePosPolarimots(tweetLem));
        if (prop.getProperty("Lexicons.polarimotsPol").equalsIgnoreCase("yes")) newData.instance(i).setValue(newData.attribute("_countNegPolarimots"), ca.ComputeNegPolarimots(tweetLem));
        if (prop.getProperty("Lexicons.polarimotsPol").equalsIgnoreCase("yes")) newData.instance(i).setValue(newData.attribute("_countNeuPolarimots"), ca.ComputeNeuPolarimots(tweetLem));
        if (prop.getProperty("Lexicons.affectsPol").equalsIgnoreCase("yes")) newData.instance(i).setValue(newData.attribute("_countPosAffects"), ca.ComputePosAffects(tweetLem));
        if (prop.getProperty("Lexicons.affectsPol").equalsIgnoreCase("yes")) newData.instance(i).setValue(newData.attribute("_countNegAffects"), ca.ComputeNegAffects(tweetLem));
        if (prop.getProperty("Lexicons.affectsPol").equalsIgnoreCase("yes")) newData.instance(i).setValue(newData.attribute("_countNeuAffects"), ca.ComputeNeuAffects(tweetLem));
        if (prop.getProperty("Lexicons.dikoPol").equalsIgnoreCase("yes")) newData.instance(i).setValue(newData.attribute("_countPosDiko"), ca.ComputePosDiko(tweetLem));
        if (prop.getProperty("Lexicons.dikoPol").equalsIgnoreCase("yes")) newData.instance(i).setValue(newData.attribute("_countNegDiko"), ca.ComputeNegDiko(tweetLem));
        if (prop.getProperty("Lexicons.dikoPol").equalsIgnoreCase("yes")) newData.instance(i).setValue(newData.attribute("_countNeuDiko"), ca.ComputeNeuDiko(tweetLem));
        if (prop.getProperty("Lexicons.feelEmo").equalsIgnoreCase("yes")) for (int j=0; j<nbClassesFEEL; j++) newData.instance(i).setValue(newData.attribute("_countEmotionFEEL"+(j+1)), ca.ComputeEmotionFEEL(tweetLem, j));
        if (prop.getProperty("Lexicons.affectsEmo").equalsIgnoreCase("yes")) for (int j=0; j<nbClassesAffects; j++) newData.instance(i).setValue(newData.attribute("_countEmotionAffects"+(j+1)), ca.ComputeEmotionAffects(tweetLem, j));
        if (prop.getProperty("Lexicons.dikoEmo").equalsIgnoreCase("yes")) for (int j=0; j<nbClassesDiko; j++) newData.instance(i).setValue(newData.attribute("_countEmotionDiko"+(j+1)), ca.ComputeEmotionDiko(tweetLem, j));
        if (prop.getProperty("Lexicons.incongruity").equalsIgnoreCase("yes")) newData.instance(i).setValue(newData.attribute("_countIncongruity"), ca.ComputeIncongruity(tweetLem));
        if (prop.getProperty("Lexicons.incongruityAll").equalsIgnoreCase("yes")) newData.instance(i).setValue(newData.attribute("_countIncongruityAll"), ca.ComputeIncongruityAll(tweetLem));
    }        
    return newData;
}
 
開發者ID:amineabdaoui,項目名稱:french-sentiment-classification,代碼行數:73,代碼來源:ConstructionARFF.java


注:本文中的weka.core.Instances.insertAttributeAt方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。