List of usage examples for weka.core Instance setDataset
public void setDataset(Instances instances);
From source file:transformation.mimlTOml.ArithmeticTransformation.java
License:Open Source License
@Override public MultiLabelInstances transformDataset() throws Exception { Instances newData = new Instances(template); int labelIndices[] = dataset.getLabelIndices(); Instance newInst = new DenseInstance(newData.numAttributes()); newInst.setDataset(newData); // Sets the reference to the dataset // For all bags in the dataset double nBags = dataset.getNumBags(); for (int i = 0; i < nBags; i++) { // retrieves a bag Bag bag = dataset.getBag(i);/*w w w. ja v a 2 s . c om*/ // sets the bagLabel newInst.setValue(0, bag.value(0)); // retrieves instances (relational value) for each bag Instances instances = bag.getBagAsInstances(); // for all attributes in bag for (int j = 0, attIdx = 1; j < instances.numAttributes(); j++, attIdx++) { double value = instances.meanOrMode(j); newInst.setValue(attIdx, value); } // inserts label information into the instance for (int j = 0; j < labelIndices.length; j++) { newInst.setValue(updatedLabelIndices[j], dataset.getBag(i).value(labelIndices[j])); } newData.add(newInst); } return new MultiLabelInstances(newData, dataset.getLabelsMetaData()); }
From source file:transformation.mimlTOml.ArithmeticTransformation.java
License:Open Source License
@Override public Instance transformInstance(Bag bag) throws Exception { int labelIndices[] = dataset.getLabelIndices(); Instance newInst = new DenseInstance(template.numAttributes()); // sets the bagLabel newInst.setDataset(bag.dataset()); // Sets the reference to the dataset newInst.setValue(0, bag.value(0));/*w w w . j a v a2 s .c o m*/ // retrieves instances (relational value) Instances instances = bag.getBagAsInstances(); // For all attributes in bag for (int j = 0, attIdx = 1; j < instances.numAttributes(); j++, attIdx++) { double value = instances.meanOrMode(j); newInst.setValue(attIdx, value); } // Insert label information into the instance for (int j = 0; j < labelIndices.length; j++) { newInst.setValue(updatedLabelIndices[j], bag.value(labelIndices[j])); } return newInst; }
From source file:transformation.mimlTOml.GeometricTransformation.java
License:Open Source License
@Override public MultiLabelInstances transformDataset() throws Exception { Instances newData = new Instances(template); int labelIndices[] = dataset.getLabelIndices(); Instance newInst = new DenseInstance(newData.numAttributes()); newInst.setDataset(newData); // Sets the reference to the dataset // For all bags in the dataset double nBags = dataset.getNumBags(); for (int i = 0; i < nBags; i++) { // retrieves a bag Bag bag = dataset.getBag(i);//w ww .j av a 2 s .c om // sets the bagLabel newInst.setValue(0, bag.value(0)); // retrieves instances (relational value) for each bag Instances instances = bag.getBagAsInstances(); // for all attributes in bag for (int j = 0, attIdx = 1; j < instances.numAttributes(); j++, attIdx++) { double[] minimax = minimax(instances, j); double value = (minimax[0] + minimax[1]) / 2.0; newInst.setValue(attIdx, value); } // inserts label information into the instance for (int j = 0; j < labelIndices.length; j++) { newInst.setValue(updatedLabelIndices[j], dataset.getBag(i).value(labelIndices[j])); } newData.add(newInst); } return new MultiLabelInstances(newData, dataset.getLabelsMetaData()); }
From source file:transformation.mimlTOml.GeometricTransformation.java
License:Open Source License
@Override public Instance transformInstance(Bag bag) throws Exception { int labelIndices[] = dataset.getLabelIndices(); Instance newInst = new DenseInstance(template.numAttributes()); // sets the bagLabel newInst.setDataset(bag.dataset()); // Sets the reference to the dataset newInst.setValue(0, bag.value(0));/*from w w w . j a va 2s. co m*/ // retrieves instances (relational value) Instances instances = bag.getBagAsInstances(); // For all attributes in bag for (int j = 0, attIdx = 1; j < instances.numAttributes(); j++, attIdx++) { double[] minimax = minimax(instances, j); double value = (minimax[0] + minimax[1]) / 2.0; newInst.setValue(attIdx, value); } // Insert label information into the instance for (int j = 0; j < labelIndices.length; j++) { newInst.setValue(updatedLabelIndices[j], bag.value(labelIndices[j])); } return newInst; }
From source file:transformation.mimlTOml.MiniMaxTransformation.java
License:Open Source License
@Override public MultiLabelInstances transformDataset() throws Exception { Instances newData = new Instances(template); int labelIndices[] = dataset.getLabelIndices(); Instance newInst = new DenseInstance(newData.numAttributes()); newInst.setDataset(newData); // Sets the reference to the dataset // For all bags in the dataset double nBags = dataset.getNumBags(); for (int i = 0; i < nBags; i++) { // retrieves a bag Bag bag = dataset.getBag(i);//from w ww. j av a2 s . c o m // sets the bagLabel newInst.setValue(0, bag.value(0)); // retrieves instances (relational value) for each bag Instances instances = bag.getBagAsInstances(); // For all attributes in bag for (int j = 0, attIdx = 1; j < instances.numAttributes(); j++, attIdx++) { double[] minimax = minimax(instances, j); newInst.setValue(attIdx, minimax[0]);// minima value newInst.setValue(attIdx + instances.numAttributes(), minimax[1]);// maxima // value); } // Copy label information into the dataset for (int j = 0; j < labelIndices.length; j++) { newInst.setValue(updatedLabelIndices[j], bag.value(labelIndices[j])); } newData.add(newInst); } return new MultiLabelInstances(newData, dataset.getLabelsMetaData()); }
From source file:transformation.mimlTOml.MiniMaxTransformation.java
License:Open Source License
@Override public Instance transformInstance(Bag bag) throws Exception { int labelIndices[] = dataset.getLabelIndices(); Instance newInst = new DenseInstance(template.numAttributes()); // sets the bagLabel newInst.setDataset(bag.dataset()); // Sets the reference to the dataset newInst.setValue(0, bag.value(0));/*from w w w . j a v a 2 s . c o m*/ // retrieves instances (relational value) Instances instances = bag.getBagAsInstances(); // For all attributes in bag for (int j = 0, attIdx = 1; j < instances.numAttributes(); j++, attIdx++) { double[] minimax = minimax(instances, j); newInst.setValue(attIdx, minimax[0]);// minima value newInst.setValue(attIdx + instances.numAttributes(), minimax[1]);// maxima // value); } // Insert label information into the instance for (int j = 0; j < labelIndices.length; j++) { newInst.setValue(updatedLabelIndices[j], bag.value(labelIndices[j])); } return newInst; }
From source file:tubesduaai.TesFFNN.java
public static void tes() throws Exception { BufferedReader reader = new BufferedReader(new FileReader("C:\\Program Files\\Weka-3-8\\data\\iris.arff")); data = new Instances(reader); reader.close();//from www .ja v a2 s . c o m // setting class attribute data.setClassIndex(data.numAttributes() - 1); Instances dummy = null; FFNN nn = new FFNN("C:\\Program Files\\Weka-3-8\\data\\iris.arff", 0); boolean[] nom = nn.cek_nominal(); System.out.println("ingin load?: "); String load = sc.nextLine(); if (load.equalsIgnoreCase("y")) { nn.load_model(); eval = cross_validation(nn); nn.print_perceptron(); } else { nn.buildClassifier(data); nn.print_perceptron(); eval = cross_validation(nn); nn.print_perceptron(); } System.out.println(eval.toSummaryString("\nResults\n======\n", false)); double[] attValues1 = { 5.1, 3.5, 1.4, 0.2 }; Instance i1 = new DenseInstance(1.0, attValues1); double[] attValues2 = { 7.0, 3.2, 4.7, 1.4 }; Instance i2 = new DenseInstance(1.0, attValues2); double[] attValues3 = { 6.3, 3.3, 6.0, 2.5 }; Instance i3 = new DenseInstance(1.0, attValues3); i1.setDataset(data); i2.setDataset(data); i3.setDataset(data); //hasil harusnya 0 1 2 System.out.println(nn.classifyInstance(i1)); System.out.println(nn.classifyInstance(i2)); System.out.println(nn.classifyInstance(i3)); System.out.println("ingin save?: "); String save = sc.nextLine(); if (save.equalsIgnoreCase("y")) { nn.save_model(); } }
From source file:util.Weka.java
public Instance casoADecidir(double... atributos) { Instance casoAdecidir = new Instance(casosEntrenamiento.numAttributes()); casoAdecidir.setDataset(casosEntrenamiento); for (int i = 0; i < atributos.length; i++) { casoAdecidir.setValue(i, atributos[i]); }/*w w w .j ava 2s. com*/ return casoAdecidir; }
From source file:wedt.project.Common.java
public Instances getPrepapredSet(File file) { try {// w w w . java 2s. c o m CSVLoader csvLoader = new CSVLoader(); csvLoader.setSource(file); Instances loadedInstances = csvLoader.getDataSet(); Instances instances = getEmptyInstances("instances"); for (Instance currentInstance : loadedInstances) { Instance tmpInstance = extractFeature(currentInstance); tmpInstance.setDataset(instances); instances.add(tmpInstance); } return instances; } catch (IOException e) { System.out.println("Blad w przygotowywaniu zbioru"); System.out.println(e.toString()); } return null; }
From source file:wekimini.DataGenerator.java
private void addToTempInstances(double[] inputs, double[] outputs, boolean[] recordingMask, int recordingRound) { int thisId = nextID; nextID++;/*from w ww. j av a 2 s . c om*/ double myVals[] = new double[numMetaData + numInputs + numOutputs]; myVals[idIndex] = thisId; myVals[recordingRoundIndex] = recordingRound; Date now = new Date(); //myVals[timestampIndex] = Double.parseDouble(dateFormat.format(now)); //Error: This gives us scientific notation! String pretty = prettyDateFormat.format(now); try { myVals[timestampIndex] = trainingInputs.attribute(timestampIndex).parseDate(pretty); //myVals[timestampIndex] = } catch (ParseException ex) { myVals[timestampIndex] = 0; Logger.getLogger(DataManager.class.getName()).log(Level.SEVERE, null, ex); } /*for (int i = 0; i < numInputs; i++) { myVals[numMetaData + i] = featureVals[i]; } */ System.arraycopy(inputs, 0, myVals, numMetaData, inputs.length); //TODO DOUBLECHECK /*for (int i = 0; i < numParams; i++) { if (isParamDiscrete[i] && (paramVals[i] < 0 || paramVals[i] >= numParamValues[i])) { throw new IllegalArgumentException("Invalid value for this discrete parameter"); } myVals[numMetaData + numFeatures + i] = paramVals[i]; } */ System.arraycopy(outputs, 0, myVals, numMetaData + numInputs, outputs.length); Instance in = new Instance(1.0, myVals); for (int i = 0; i < recordingMask.length; i++) { if (!recordingMask[i]) { in.setMissing(numMetaData + numInputs + i); } else { w.getDataManager().setNumExamplesPerOutput(i, w.getDataManager().getNumExamplesPerOutput(i) + 1); // outputInstanceCounts[i]++; } } in.setDataset(tempInstances); tempInstances.add(in); //setHasInstances(true); //fireStateChanged(); //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. }