Search in sources :

Example 26 with Attribute

use of weka.core.Attribute in project dkpro-tc by dkpro.

the class WekaUtilTest method tcInstanceToMekaInstanceTest.

@Test
public void tcInstanceToMekaInstanceTest() throws Exception {
    List<String> outcomeValues = Arrays.asList(new String[] { "outc_1", "outc_2", "outc_3" });
    Instance i1 = new Instance();
    i1.addFeature(new Feature("feature1", 2, FeatureType.NUMERIC));
    i1.addFeature(new Feature("feature2", 2, FeatureType.NUMERIC));
    i1.addFeature(new Feature("feature3_{{", "a", FeatureType.STRING));
    Instance i2 = new Instance();
    i2.addFeature(new Feature("feature1", 1, FeatureType.NUMERIC));
    i2.addFeature(new Feature("feature4", "val_1", FeatureType.STRING));
    i2.addFeature(new Feature("feature3_{{", "b", FeatureType.STRING));
    ArrayList<Attribute> attributes = new ArrayList<Attribute>();
    attributes.add(new Attribute("outc_1", Arrays.asList(new String[] { "0", "1" })));
    attributes.add(new Attribute("outc_2", Arrays.asList(new String[] { "0", "1" })));
    attributes.add(new Attribute("outc_3", Arrays.asList(new String[] { "0", "1" })));
    attributes.add(new Attribute("feature5"));
    attributes.add(new Attribute("feature2"));
    attributes.add(new Attribute("feature4", Arrays.asList(new String[] { "val_1", "val_2" })));
    attributes.add(new Attribute("feature1"));
    Instances trainingData = new Instances("test", attributes, 0);
    weka.core.Instance wekaInstance1 = WekaUtils.tcInstanceToMekaInstance(i1, trainingData, outcomeValues);
    weka.core.Instance wekaInstance2 = WekaUtils.tcInstanceToMekaInstance(i2, trainingData, outcomeValues);
    assertEquals(true, wekaInstance1.equalHeaders(wekaInstance2));
    assertEquals(7, wekaInstance1.numAttributes());
    wekaInstance1.dataset().add(wekaInstance1);
    wekaInstance2.dataset().add(wekaInstance2);
    System.out.println(wekaInstance1.dataset() + "\n");
    System.out.println(wekaInstance2.dataset() + "\n");
}
Also used : Instances(weka.core.Instances) Instance(org.dkpro.tc.api.features.Instance) Attribute(weka.core.Attribute) ArrayList(java.util.ArrayList) Feature(org.dkpro.tc.api.features.Feature) Test(org.junit.Test)

Example 27 with Attribute

use of weka.core.Attribute in project dkpro-tc by dkpro.

the class WekaUtilTest method tcInstanceToWekaInstanceRegressionTest.

@Test
public void tcInstanceToWekaInstanceRegressionTest() throws Exception {
    Instance i1 = new Instance();
    i1.addFeature(new Feature("feature1", 2, FeatureType.NUMERIC));
    i1.addFeature(new Feature("feature2", 2, FeatureType.NUMERIC));
    i1.addFeature(new Feature("feature3_{{", "a", FeatureType.STRING));
    Instance i2 = new Instance();
    i2.addFeature(new Feature("feature1", 1, FeatureType.NUMERIC));
    i2.addFeature(new Feature("feature4", "val_1", FeatureType.STRING));
    i2.addFeature(new Feature("feature3_{{", "b", FeatureType.STRING));
    ArrayList<Attribute> attributes = new ArrayList<Attribute>();
    attributes.add(new Attribute("feature5"));
    attributes.add(new Attribute("feature2"));
    attributes.add(new Attribute("feature4", Arrays.asList(new String[] { "val_1", "val_2" })));
    attributes.add(new Attribute("feature1"));
    attributes.add(new Attribute("outcome"));
    Instances trainingData = new Instances("test", attributes, 0);
    weka.core.Instance wekaInstance1 = WekaUtils.tcInstanceToWekaInstance(i1, trainingData, null, true);
    weka.core.Instance wekaInstance2 = WekaUtils.tcInstanceToWekaInstance(i2, trainingData, null, true);
    assertEquals(true, wekaInstance1.equalHeaders(wekaInstance2));
    assertEquals(5, wekaInstance1.numAttributes());
    wekaInstance1.dataset().add(wekaInstance1);
    wekaInstance2.dataset().add(wekaInstance2);
    System.out.println(wekaInstance1.dataset() + "\n");
    System.out.println(wekaInstance2.dataset() + "\n");
}
Also used : Instances(weka.core.Instances) Instance(org.dkpro.tc.api.features.Instance) Attribute(weka.core.Attribute) ArrayList(java.util.ArrayList) Feature(org.dkpro.tc.api.features.Feature) Test(org.junit.Test)

Example 28 with Attribute

use of weka.core.Attribute in project mcib3d-core by mcib3d.

the class Attributes method addAttribute.

public void addAttribute(String name) {
    Attribute att = new Attribute(name);
    atts.add(att);
    attributes.put(name, att);
}
Also used : Attribute(weka.core.Attribute)

Aggregations

Attribute (weka.core.Attribute)28 ArrayList (java.util.ArrayList)12 Instances (weka.core.Instances)12 Feature (org.dkpro.tc.api.features.Feature)8 Instance (org.dkpro.tc.api.features.Instance)8 SparseInstance (weka.core.SparseInstance)5 Test (org.junit.Test)4 DenseInstance (weka.core.DenseInstance)4 Instance (weka.core.Instance)4 ArffSaver (weka.core.converters.ArffSaver)4 File (java.io.File)3 MultiLabelInstances (mulan.data.MultiLabelInstances)3 TextClassificationException (org.dkpro.tc.api.exception.TextClassificationException)3 AttributeStore (org.dkpro.tc.ml.weka.util.AttributeStore)3 FastVector (weka.core.FastVector)3 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 Optional (java.util.Optional)2 FeatureType (org.dkpro.tc.api.features.FeatureType)2 Request (io.milton.http.Request)1