Java Code Examples for weka.core.Instances#remove()
The following examples show how to use
weka.core.Instances#remove() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DataProcessing.java From tsml with GNU General Public License v3.0 | 5 votes |
public static void mergeEpilepsy(){ Instances x,y,z; Instances all; String sourcePath="C:\\Users\\ajb\\Dropbox\\TSC Problems\\EpilepsyX\\"; String destPath="C:\\Users\\ajb\\Dropbox\\Multivariate TSC Problems\\HAR\\Epilepsy\\"; x=DatasetLoading.loadDataNullable(sourcePath+"EpilepsyX_ALL"); y=DatasetLoading.loadDataNullable(sourcePath+"EpilepsyY_ALL"); z=DatasetLoading.loadDataNullable(sourcePath+"EpilepsyZ_ALL"); //Delete the use ID, will reinsert manually after x.deleteAttributeAt(0); y.deleteAttributeAt(0); z.deleteAttributeAt(0); all=utilities.multivariate_tools.MultivariateInstanceTools.mergeToMultivariateInstances(new Instances[]{x,y,z}); // OutFile out=new OutFile(destPath+"EpilepsyNew.arff"); // out.writeString(all.toString()); //Create train test splits so participant 1,2,3 in train and 4,5,6 in test int trainSize=149; int testSize=126; Instances train= new Instances(all,0); Instances test= new Instances(all); for(int i=0;i<trainSize;i++){ Instance t= test.remove(0); train.add(t); } OutFile tr=new OutFile(destPath+"Epilepsy_TRAIN.arff"); OutFile te=new OutFile(destPath+"Epilepsy_TEST.arff"); tr.writeString(train.toString()); te.writeString(test.toString()); }
Example 2
Source File: MultivariateProcessing.java From tsml with GNU General Public License v3.0 | 5 votes |
public static void mergeEpilepsy(){ Instances x,y,z; Instances all; String sourcePath="C:\\Users\\ajb\\Dropbox\\TSC Problems\\EpilepsyX\\"; String destPath="C:\\Users\\ajb\\Dropbox\\Multivariate TSC Problems\\HAR\\Epilepsy\\"; x=DatasetLoading.loadData(sourcePath+"EpilepsyX_ALL"); y=DatasetLoading.loadData(sourcePath+"EpilepsyY_ALL"); z=DatasetLoading.loadData(sourcePath+"EpilepsyZ_ALL"); //Delete the use ID, will reinsert manually after x.deleteAttributeAt(0); y.deleteAttributeAt(0); z.deleteAttributeAt(0); all=utilities.multivariate_tools.MultivariateInstanceTools.mergeToMultivariateInstances(new Instances[]{x,y,z}); // OutFile out=new OutFile(destPath+"EpilepsyNew.arff"); // out.writeString(all.toString()); //Create train test splits so participant 1,2,3 in train and 4,5,6 in test int trainSize=149; int testSize=126; Instances train= new Instances(all,0); Instances test= new Instances(all); for(int i=0;i<trainSize;i++){ Instance t= test.remove(0); train.add(t); } OutFile tr=new OutFile(destPath+"Epilepsy_TRAIN.arff"); OutFile te=new OutFile(destPath+"Epilepsy_TEST.arff"); tr.writeString(train.toString()); te.writeString(test.toString()); }
Example 3
Source File: LeaveOneOutCV.java From NLIWOD with GNU Affero General Public License v3.0 | 4 votes |
public static void main(String[] args) throws Exception { /* * For multilable classification: */ //load the data Path datapath= Paths.get("./src/main/resources/old/Qald6Logs.arff"); BufferedReader reader = new BufferedReader(new FileReader(datapath.toString())); ArffReader arff = new ArffReader(reader); /* * Test the trained system */ // JSONObject qald6test = loadTestQuestions(); // JSONArray questions = (JSONArray) qald6test.get("questions"); // ArrayList<String> testQuestions = Lists.newArrayList(); // for(int i = 0; i < questions.size(); i++){ // JSONObject questionData = (JSONObject) questions.get(i); // JSONArray questionStrings = (JSONArray) questionData.get("question"); // JSONObject questionEnglish = (JSONObject) questionStrings.get(0); // testQuestions.add((String) questionEnglish.get("string")); // } Instances data = arff.getData(); data.setClassIndex(6); System.out.println(); double cv_ave = 0; ArrayList<String> systems = Lists.newArrayList("KWGAnswer", "NbFramework", "PersianQA", "SemGraphQA", "UIQA_withoutManualEntries", "UTQA_English" ); for(int i = 0; i < 100; i++){ Instance testquestion = data.get(i); data.remove(i); PSt classifier = new PSt(); classifier.buildClassifier(data); double[] confidences = classifier.distributionForInstance(testquestion); int argmax = -1; double max = -1; for(int j = 0; j < 6; j++){ if(confidences[j]>max){ max = confidences[j]; argmax = j; } } String sys2ask = systems.get(systems.size() - argmax -1); float p = Float.parseFloat(loadSystemP(sys2ask).get(i)); float r = Float.parseFloat(loadSystemR(sys2ask).get(i)); double f = 0; if(p>0&&r>0){f = 2*p*r/(p + r);} cv_ave += f; data.add(i, testquestion); } System.out.println(cv_ave/100); }
Example 4
Source File: CNode.java From meka with GNU General Public License v3.0 | 4 votes |
/** * Main - run some tests. */ public static void main(String args[]) throws Exception { Instances D = new Instances(new FileReader(args[0])); Instance x = D.lastInstance(); D.remove(D.numInstances()-1); int L = Integer.parseInt(args[1]); D.setClassIndex(L); double y[] = new double[L]; Random r = new Random(); int s[] = new int[]{1,0,2}; int PA_J[][] = new int[][]{ {},{},{0,1}, }; //MLUtils.randomize(s,r); // MUST GO IN TREE ORDER !! for(int j : s) { int pa_j[] = PA_J[j]; System.out.println("PARENTS = "+Arrays.toString(pa_j)); //MLUtils.randomize(pa_j,r); System.out.println("**** TRAINING ***"); CNode n = new CNode(j,null,pa_j); n.build(D,new SMO()); /* */ //Instances D_ = n.transform(D); //n.T = D_; System.out.println("============== D_"+j+" / class = "+n.T.classIndex()+" ="); System.out.println(""+n.T); System.out.println("**** TESTING ****"); /* Instance x_ = MLUtils.setTemplate(x,(Instance)D_.firstInstance().copy(),D_); for(int pa : pa_j) { //System.out.println(""+map[pa]); x_.setValue(n.map[pa],y[pa]); } //x_.setDataset(T); x_.setClassMissing(); */ //n.T = D_; Instance x_ = n.transform(x,y); System.out.println(""+x_); y[j] = 1; } }