weka.core.converters.ConverterUtils Java Examples
The following examples show how to use
weka.core.converters.ConverterUtils.
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: LocalDatasetProvider.java From meka with GNU General Public License v3.0 | 6 votes |
/** * Returns the next dataset. * * @return the next dataset, null in case of an error */ @Override public Instances next() { Instances result; try { log("Loading: " + m_Datasets.get(m_Current)); result = ConverterUtils.DataSource.read(m_Datasets.get(m_Current).getAbsolutePath()); MLUtils.prepareData(result); } catch (Exception e) { result = null; handleException("Failed to load dataset: " + m_Datasets.get(m_Current), e); } m_Current++; return result; }
Example #2
Source File: Explorer.java From meka with GNU General Public License v3.0 | 6 votes |
/** * Saves the data to the specified file. * * @param file the file to save the data to * @param saver the saver to use, determines it automatically if null */ public void save(File file, AbstractFileSaver saver) { if (saver == null) saver = ConverterUtils.getSaverForFile(file); try { log(null, "Saving: " + file); saver.setInstances(m_Data); if ((saver.retrieveFile() == null) || !saver.retrieveFile().equals(file)) saver.setFile(file); saver.writeBatch(); m_CurrentFile = file; log(null, "Saved successfully: " + file); } catch (Exception e) { handleException(null, "Failed to save data to '" + file + "':", e); JOptionPane.showMessageDialog( this, "Failed to save dataset to '" + file + "':\n" + e, "Error saving", JOptionPane.ERROR_MESSAGE); } updateMenu(); }
Example #3
Source File: Dl4jStringToWord2VecTest.java From wekaDeeplearning4j with GNU General Public License v3.0 | 5 votes |
public void testReuters() throws Exception { final String arffPath = "datasets/text/ReutersCorn-train.arff"; ConverterUtils.DataSource ds = new ConverterUtils.DataSource(arffPath); final Instances data = ds.getDataSet(); Dl4jStringToWord2Vec dl4jw2v = new Dl4jStringToWord2Vec(); dl4jw2v.setInputFormat(data); Instances d = Filter.useFilter(data, dl4jw2v); }
Example #4
Source File: DataViewerMainPanel.java From meka with GNU General Public License v3.0 | 5 votes |
/** * loads the specified file * * @param filename the file to load * @param loaders optional varargs loader to use */ public void loadFile(String filename, AbstractFileLoader... loaders) { DataPanel panel; AbstractFileLoader loader; panel = new DataPanel(filename, loaders); panel.addChangeListener(this); m_TabbedPane.addTab(panel.getTitle(), panel); m_TabbedPane.setSelectedIndex(m_TabbedPane.getTabCount() - 1); if (loaders == null) loader = ConverterUtils.getLoaderForFile(filename); else loader = loaders[0]; m_RecentFilesHandler.addRecentItem(new RecentFilesHandlerWithCommandline.Setup(new File(filename), loader)); }
Example #5
Source File: DataViewerMainPanel.java From meka with GNU General Public License v3.0 | 5 votes |
/** * saves the current data into a file */ public void saveFile() { DataPanel panel; String filename; AbstractSaver saver; // no panel? -> exit panel = getCurrentPanel(); if (panel == null) { return; } filename = panel.getFilename(); if (filename.equals(DataPanel.TAB_INSTANCES)) { saveFileAs(); } else { saver = ConverterUtils.getSaverForFile(filename); try { saver.setFile(new File(filename)); saver.setInstances(panel.getInstances()); saver.writeBatch(); panel.setChanged(false); setCurrentFilename(filename); } catch (Exception e) { e.printStackTrace(); } } }
Example #6
Source File: DataTableModel.java From meka with GNU General Public License v3.0 | 5 votes |
/** * loads the specified ARFF file * * @param filename the file to load * @param loaders optional varargs for a loader to use */ protected void loadFile(String filename, AbstractFileLoader... loaders) { AbstractFileLoader loader; Instances data; if (loaders == null || loaders.length == 0) { loader = ConverterUtils.getLoaderForFile(filename); } else { loader = loaders[0]; } if (loader != null) { try { loader.setFile(new File(filename)); data = loader.getDataSet(); // fix class attributes definition in relation name if necessary MLUtils.fixRelationName(data); MLUtils.prepareData(data); setInstances(data); } catch (Exception e) { ComponentHelper .showMessageBox(null, "Error loading file...", e.toString(), JOptionPane.OK_CANCEL_OPTION, JOptionPane.ERROR_MESSAGE); System.out.println(e); setInstances(null); } } }
Example #7
Source File: AbstractMekaFilterTest.java From meka with GNU General Public License v3.0 | 5 votes |
/** * Called by JUnit before each test method. This implementation creates * the default filter to test and loads a test set of Instances. * * @throws Exception if an error occurs reading the example instances. */ protected void setUp() throws Exception { m_Filter = getFilter(); m_Instances = ConverterUtils.DataSource.read("FilterTest.arff"); m_OptionTester = getOptionTester(); m_GOETester = getGOETester(); m_FilteredClassifier = getFilteredClassifier(); m_FilteredClassifier.setDoNotCheckForModifiedClassAttribute(true); }
Example #8
Source File: Dl4jStringToWord2VecTest.java From wekaDeeplearning4j with GNU General Public License v3.0 | 5 votes |
public void testReuters() throws Exception { final String arffPath = "datasets/text/ReutersCorn-train.arff"; ConverterUtils.DataSource ds = new ConverterUtils.DataSource(arffPath); final Instances data = ds.getDataSet(); Dl4jStringToWord2Vec dl4jw2v = new Dl4jStringToWord2Vec(); dl4jw2v.setInputFormat(data); Instances d = Filter.useFilter(data, dl4jw2v); }
Example #9
Source File: WekaDataSetConverter.java From NeurophFramework with Apache License 2.0 | 4 votes |
/** * Creates neuroph dataset from arff weka file. * * @param filePath Path to the file. * @param numInputs Number of inputs. * @param numOutputs Number of outputs. * @return Neuroph dataset. */ public static DataSet createDataSetFromFile(String filePath, int numInputs, int numOutputs) { try { ConverterUtils.DataSource dataSource = new ConverterUtils.DataSource(filePath); Instances wekaDataset = dataSource.getDataSet(); wekaDataset.setClassIndex(numInputs); DataSet neurophDataset = WekaDataSetConverter.convertWekaToNeurophDataset(wekaDataset, numInputs, numOutputs); return neurophDataset; } catch (Exception e) { return new DataSet(0); } }
Example #10
Source File: Explorer.java From meka with GNU General Public License v3.0 | 2 votes |
/** * Processes the commandline arguments. * * @param args the arguments */ public void processCommandLineArgs(String[] args) { if (args.length > 0) open(new File(args[0]), ConverterUtils.getLoaderForFile(args[0])); }
Example #11
Source File: AbstractMekaClassifierTest.java From meka with GNU General Public License v3.0 | 2 votes |
/** * Loads the dataset from disk. * * @param file the dataset to load (e.g., "weka/classifiers/data/something.arff") * @throws Exception if loading fails, e.g., file does not exit */ public static Instances loadData(String file) throws Exception { return ConverterUtils.DataSource.read(file); }