List of usage examples for weka.core Instances Instances
public Instances(Instances dataset)
From source file:data.generation.target.utils.PrincipalComponents.java
License:Open Source License
/** * Gets the transformed training data.// ww w .j a v a 2 s . c o m * @return the transformed training data * @throws Exception if transformed data can't be returned */ public Instances transformedData(Instances data) throws Exception { if (m_eigenvalues == null) { throw new Exception("Principal components hasn't been built yet"); } Instances output = null; if (m_transBackToOriginal) { output = new Instances(m_originalSpaceFormat); } else { output = new Instances(m_transformedFormat); } for (int i = 0; i < data.numInstances(); i++) { Instance converted = convertInstance(data.instance(i)); output.add(converted); } return output; }
From source file:data.Regression.java
public int regression(String fileName) { String arffName = FileTransfer.transfer(fileName); try {// w ww . jav a 2 s .c o m //load data Instances data = new Instances(new BufferedReader(new FileReader(arffName))); data.setClassIndex(data.numAttributes() - 1); //build model LinearRegression model = new LinearRegression(); model.buildClassifier(data); //the last instance with missing class is not used System.out.println(model); //classify the last instance Instance num = data.lastInstance(); int people = (int) model.classifyInstance(num); System.out.println("NumOfEnrolled (" + num + "): " + people); return people; } catch (Exception e) { e.printStackTrace(); System.out.println("Regression fail"); } return 0; }
From source file:data.RegressionDrop.java
public void regression() throws Exception { //public static void main(String[] args) throws Exception{ //load data//from ww w .j a v a2 s . c om Instances data = new Instances(new BufferedReader(new FileReader("NumOfDroppedByYear.arff"))); data.setClassIndex(data.numAttributes() - 1); //build model LinearRegression model = new LinearRegression(); model.buildClassifier(data); //the last instance with missing class is not used System.out.println(model); //classify the last instance Instance num = data.lastInstance(); int people = (int) model.classifyInstance(num); System.out.println("NumOfDropped (" + num + "): " + people); }
From source file:dataHandlers.DataClusterHandler.java
public void buildGraph(String filePath) { LOGGER.log(Level.WARNING, "May throw exception for poorly formated data files"); try {//from ww w. j a v a2s. c o m userPoints = new Instances(getDataFile(filePath)); int numberOfClusters = clusterCount(userPoints); int maxSeedAmount = seedAmount(userPoints); initiateClusters(maxSeedAmount, numberOfClusters); if (clusterInitiated) { LOGGER.log(Level.WARNING, "May throw exeption for instances type"); try { dataGraph.buildClusterer(userPoints); saveClusterInforamtion(); LOGGER.log(Level.INFO, "Clustering was completed"); } catch (Exception e) { LOGGER.log(Level.SEVERE, "Error@ClusterProcess_initiateCluster", e); } } } catch (IOException e) { LOGGER.log(Level.SEVERE, "Error@ClusterProcess_initiateCluster", e); } }
From source file:DataMiningLogHistoriKIRI.ArffIO.java
public Instances readArff(String name) throws IOException { Instances data;/*from w ww . ja v a 2 s .c o m*/ data = new Instances(new BufferedReader(new FileReader("temp.arff"))); data.setClassIndex(data.numAttributes() - 1); return data; }
From source file:DataMining_FP.interfaz.java
public static void inicializando_weka() { //Inicializando los objetos de weka try {//w ww . j ava2 s. com reader = new BufferedReader(new FileReader("WISDM_ar_v1.1_transformed.arff")); data = new Instances(reader); reader.close(); // especificando el atributo de clase data.setClassIndex(data.numAttributes() - 1); String[] options = new String[1]; options[0] = "-U"; // unpruned tree tree = new J48(); // new instance of tree tree.setOptions(options); // set the options tree.buildClassifier(data); // build classifier } catch (Exception e) { System.out.println("Error inicializando los objetos de weka"); } System.out.println("Weka inicio bien"); }
From source file:de.citec.sc.matoll.classifiers.WEKAclassifier.java
public void train(List<Provenance> provenances, Set<String> pattern_lookup, Set<String> pos_lookup) throws IOException { String path = "matoll" + Language.toString() + ".arff"; writeVectors(provenances, path, pattern_lookup, pos_lookup); Instances inst = new Instances(new BufferedReader(new FileReader(path))); inst.setClassIndex(inst.numAttributes() - 1); try {//from www. ja v a 2 s . c o m cls.buildClassifier(inst); // serialize model ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(path.replace(".arff", ".model"))); oos.writeObject(cls); oos.flush(); oos.close(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:de.lmu.ifi.dbs.knowing.core.model.internal.InstancesSerializationService.java
License:Apache License
@Override protected Object decodeFromString(String value) { StringReader reader = new StringReader(value); try {/*from ww w . j a v a 2 s. c o m*/ return new Instances(reader); } catch (IOException e) { e.printStackTrace(); return null; } }
From source file:de.tudarmstadt.ukp.alignment.framework.combined.WekaMachineLearning.java
License:Apache License
/** * * This method applies a serialized WEKA model file to an unlabeld .arff file for classification * * * @param input_arff the annotated gold standard in an .arff file * @param model output file for the model * @param output output file for evaluation of trained classifier (10-fold cross validation) * @throws Exception/*from w w w . j a v a 2s. com*/ */ public static void applyModelToUnlabeledArff(String input_arff, String model, String output) throws Exception { DataSource source = new DataSource(input_arff); Instances unlabeled = source.getDataSet(); if (unlabeled.classIndex() == -1) { unlabeled.setClassIndex(unlabeled.numAttributes() - 1); } Remove rm = new Remove(); rm.setAttributeIndices("1"); // remove ID attribute ObjectInputStream ois = new ObjectInputStream(new FileInputStream(model)); Classifier cls = (Classifier) ois.readObject(); ois.close(); // create copy Instances labeled = new Instances(unlabeled); // label instances for (int i = 0; i < unlabeled.numInstances(); i++) { double clsLabel = cls.classifyInstance(unlabeled.instance(i)); labeled.instance(i).setClassValue(clsLabel); } // save labeled data BufferedWriter writer = new BufferedWriter(new FileWriter(output)); writer.write(labeled.toString()); writer.newLine(); writer.flush(); writer.close(); }
From source file:de.tudarmstadt.ukp.dkpro.spelling.experiments.hoo2012.featureextraction.AllFeaturesExtractor.java
License:Apache License
private Instances getInstances(File instancesFile) throws FileNotFoundException, IOException { Instances trainData = null;//from w w w . j av a2 s . c o m Reader reader; if (instancesFile.getAbsolutePath().endsWith(".gz")) { reader = new BufferedReader( new InputStreamReader(new GZIPInputStream(new FileInputStream(instancesFile)))); } else { reader = new BufferedReader(new FileReader(instancesFile)); } try { trainData = new Instances(reader); trainData.setClassIndex(trainData.numAttributes() - 1); } finally { reader.close(); } return trainData; }