/** SAVE MODEL */ public void saveDataset(String arffilename, String dsfilename) { try { BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(arffilename), "UTF-8")); ArffReader arff = new ArffReader(reader); Instances dataset = arff.getData(); reader.close(); FileOutputStream dsOutFile = new FileOutputStream(dsfilename); ObjectOutputStream dsOutObjectFile = new ObjectOutputStream(dsOutFile); dsOutObjectFile.writeObject(dataset); dsOutObjectFile.flush(); dsOutObjectFile.close(); } catch (Exception e) {System.out.println("File not found: "+e.getMessage());} } // end save dataset
@Override public Instances getDataSet() throws IOException { if (m_sourceReader == null) { throw new IOException("No source has been specified"); } if (getRetrieval() == INCREMENTAL) { throw new IOException( "Cannot mix getting instances in both incremental and batch modes"); } setRetrieval(BATCH); if (m_structure == null) { getStructure(); } while (readData(true)) { ; } m_dataDumper.flush(); m_dataDumper.close(); // make final structure makeStructure(); Reader sr = new BufferedReader(new FileReader(m_tempFile)); ArffReader initialArff = new ArffReader(sr, m_structure, 0, m_fieldSeparatorAndEnclosures); Instances initialInsts = initialArff.getData(); sr.close(); initialArff = null; return initialInsts; }
@Override public Instances getDataSet() throws IOException { if (m_sourceReader == null) { throw new IOException("No source has been specified"); } if (getRetrieval() == INCREMENTAL) { throw new IOException( "Cannot mix getting instances in both incremental and batch modes"); } setRetrieval(BATCH); if (m_structure == null) { getStructure(); } while (readData(true)) { ; } m_dataDumper.flush(); m_dataDumper.close(); // make final structure makeStructure(); Reader sr = new BufferedReader(new FileReader(m_tempFile)); ArffReader initialArff = new ArffReader(sr, m_structure, 0, m_fieldSeparatorAndEnclosures); Instances initialInsts = initialArff.getData(); sr.close(); initialArff = null; return initialInsts; }
new ArffReader(new StringReader(m_Tokenizer.sval), m_Data .attribute(m_IndicesBuffer[numValues]).relation(), 0); Instances data = arff.getData(); m_ValueBuffer[numValues] = m_Data.attribute(m_IndicesBuffer[numValues]).addRelation(data);
new ArffReader(new StringReader(m_Tokenizer.sval), m_Data .attribute(m_IndicesBuffer[numValues]).relation(), 0); Instances data = arff.getData(); m_ValueBuffer[numValues] = m_Data.attribute(m_IndicesBuffer[numValues]).addRelation(data);
new ArffReader(new StringReader(m_Tokenizer.sval), m_Data .attribute(i).relation(), 0); Instances data = arff.getData(); instance[i] = m_Data.attribute(i).addRelation(data); } catch (Exception e) {
new ArffReader(new StringReader(m_Tokenizer.sval), m_Data .attribute(i).relation(), 0); Instances data = arff.getData(); instance[i] = m_Data.attribute(i).addRelation(data); } catch (Exception e) {
BufferedReader reader = new BufferedReader(new FileReader(datapath.toString())); ArffReader arff = new ArffReader(reader); Instances data = arff.getData(); data.setClassIndex(6);
BufferedReader reader = new BufferedReader(new FileReader(datapath.toString())); ArffReader arff = new ArffReader(reader); Instances data = arff.getData(); data.setClassIndex(6);
BufferedReader reader = new BufferedReader(new FileReader(datapath.toString())); ArffReader arff = new ArffReader(reader); Instances data = arff.getData(); data.setClassIndex(6);
BufferedReader reader = new BufferedReader(new FileReader(datapath.toString())); ArffReader arff = new ArffReader(reader); Instances data = arff.getData(); data.setClassIndex(6);
BufferedReader reader = new BufferedReader(new FileReader(datapath.toString())); ArffReader arff = new ArffReader(reader); Instances data = arff.getData(); data.setClassIndex(6);
Instances data = arff.getData(); data.setClassIndex(6);
/** * Reads a single instance from the reader and appends it to the dataset. * Automatically expands the dataset if it is not large enough to hold the * instance. This method does not check for carriage return at the end of the * line. * * @param reader the reader * @return false if end of file has been reached * @throws IOException if the information is not read successfully * @deprecated instead of using this method in conjunction with the * <code>readInstance(Reader)</code> method, one should use the * <code>ArffLoader</code> or <code>DataSource</code> class * instead. * @see weka.core.converters.ArffLoader * @see weka.core.converters.ConverterUtils.DataSource */ @Deprecated public boolean readInstance(Reader reader) throws IOException { ArffReader arff = new ArffReader(reader, this, m_Lines, 1); Instance inst = arff.readInstance(arff.getData(), false); m_Lines = arff.getLineNo(); if (inst != null) { add(inst); return true; } else { return false; } }
/** * Reads a single instance from the reader and appends it to the dataset. * Automatically expands the dataset if it is not large enough to hold the * instance. This method does not check for carriage return at the end of the * line. * * @param reader the reader * @return false if end of file has been reached * @throws IOException if the information is not read successfully * @deprecated instead of using this method in conjunction with the * <code>readInstance(Reader)</code> method, one should use the * <code>ArffLoader</code> or <code>DataSource</code> class * instead. * @see weka.core.converters.ArffLoader * @see weka.core.converters.ConverterUtils.DataSource */ @Deprecated public boolean readInstance(Reader reader) throws IOException { ArffReader arff = new ArffReader(reader, this, m_Lines, 1); Instance inst = arff.readInstance(arff.getData(), false); m_Lines = arff.getLineNo(); if (inst != null) { add(inst); return true; } else { return false; } }
/** * Reads an ARFF file from a reader, and assigns a weight of one to each * instance. Lets the index of the class attribute be undefined (negative). * * @param reader the reader * @throws IOException if the ARFF file is not read successfully */ public Instances(/* @non_null@ */Reader reader) throws IOException { ArffReader arff = new ArffReader(reader, 1000, false); initialize(arff.getData(), 1000); arff.setRetainStringValues(true); Instance inst; while ((inst = arff.readInstance(this)) != null) { m_Instances.add(inst); } compactify(); }
/** * Reads an ARFF file from a reader, and assigns a weight of one to each * instance. Lets the index of the class attribute be undefined (negative). * * @param reader the reader * @throws IOException if the ARFF file is not read successfully */ public Instances(/* @non_null@ */Reader reader) throws IOException { ArffReader arff = new ArffReader(reader, 1000, false); initialize(arff.getData(), 1000); arff.setRetainStringValues(true); Instance inst; while ((inst = arff.readInstance(this)) != null) { m_Instances.add(inst); } compactify(); }