List of usage examples for weka.core Attribute Attribute
public Attribute(String attributeName, Instances header, int index)
From source file:com.reactivetechnologies.analytics.mapper.TEXTDataMapper.java
License:Open Source License
@Override public Dataset mapStringToModel(JsonRequest request) throws ParseException { if (request != null && request.getData() != null && request.getData().length > 0) { FastVector fvWekaAttributes = new FastVector(2); FastVector nil = null;//from ww w .ja v a 2 s .c om Attribute attr0 = new Attribute("text", nil, 0); FastVector fv = new FastVector(); for (String nominal : request.getClassVars()) { fv.addElement(nominal); } Attribute attr1 = new Attribute("class", fv, 1); fvWekaAttributes.addElement(attr0); fvWekaAttributes.addElement(attr1); Instances ins = new Instances("attr-reln", fvWekaAttributes, request.getData().length); ins.setClassIndex(1); for (Text s : request.getData()) { Instance i = new Instance(2); i.setValue(attr0, s.getText()); i.setValue(attr1, s.getTclass()); ins.add(i); } return new Dataset(ins); } return null; }
From source file:de.uni_potsdam.hpi.bpt.promnicat.analysisModules.clustering.ProcessInstances.java
License:Open Source License
/** * Create a copy of the structure if the data has string or relational * attributes, "cleanses" string types (i.e. doesn't contain references to * the strings seen in the past) and all relational attributes. * // ww w. j a v a 2s. com * @return a copy of the instance structure. */ public ProcessInstances stringFreeStructure() { FastVector newAtts = new FastVector(); for (int i = 0; i < m_Attributes.size(); i++) { Attribute att = (Attribute) m_Attributes.elementAt(i); if (att.type() == Attribute.STRING) { newAtts.addElement(new Attribute(att.name(), (FastVector) null, i)); } else if (att.type() == Attribute.RELATIONAL) { newAtts.addElement( new Attribute(att.name(), new ProcessInstances((ProcessInstances) att.relation(), 0), i)); } } if (newAtts.size() == 0) { return new ProcessInstances(this, 0); } FastVector atts = (FastVector) m_Attributes.copy(); for (int i = 0; i < newAtts.size(); i++) { atts.setElementAt(newAtts.elementAt(i), ((Attribute) newAtts.elementAt(i)).index()); } ProcessInstances result = new ProcessInstances(this, 0); result.m_Attributes = atts; return result; }
From source file:edu.cuny.qc.speech.AuToBI.util.ClassifierUtils.java
License:Open Source License
/** * Generate a FastVector of weka Attributes from a set of features. * * @param features the set of features/* ww w . j a va2 s . co m*/ * @return a FastVector of weka attributes */ public static ArrayList<Attribute> generateWekaAttributes(Set<Feature> features) { ArrayList<Attribute> attributes = new ArrayList<Attribute>(); for (Feature f : features) { String attribute_name = f.getName(); if (f.isNominal()) { List<String> attribute_values = new ArrayList<String>(); for (String s : f.getNominalValues()) { attribute_values.add(s); } attributes.add(new Attribute(attribute_name, attribute_values, attributes.size())); } else if (f.isString()) { attributes.add(new weka.core.Attribute(attribute_name, (List<String>) null, attributes.size())); } else { attributes.add(new weka.core.Attribute(attribute_name, attributes.size())); } } return attributes; }
From source file:moa.classifiers.novelClass.AbstractNovelClassClassifier.java
License:Apache License
final public static Instances augmentInstances(Instances datum) { ArrayList<Attribute> attInfo = new ArrayList<>(datum.numAttributes()); for (int aIdx = 0; aIdx < datum.numAttributes(); aIdx++) { Attribute a = datum.attribute(aIdx).copy(datum.attribute(aIdx).name()); if ((aIdx == datum.classIndex()) && (a.indexOfValue(NOVEL_LABEL_STR) < 0)) { // only if we don't already have these List<String> values = new ArrayList<>(a.numValues() + 2); for (int i = 0; i < a.numValues(); ++i) { values.add(a.value(i));/*from w w w .j a v a 2s .c om*/ } values.add(OUTLIER_LABEL_STR); values.add(NOVEL_LABEL_STR); a = new Attribute(a.name(), values, a.getMetadata()); } attInfo.add(a); } String relationshipName = NOVEL_CLASS_INSTANCE_RELATIONSHIP_TYPE + "-" + datum.relationName(); Instances ret = new Instances(relationshipName, attInfo, 1); ret.setClassIndex(datum.classIndex()); return ret; }
From source file:moa.streams.generators.DriftingExemplarAttribute.java
License:Apache License
/** * Construct a nominal or string attribute * * @param p_name name of this feature//from ww w .j a v a 2s . c o m * @param p_corpus bag of words to choose from for this concept * @param p_conceptId index of this feature * @param p_rng Shared Random Number Generator */ public DriftingExemplarAttribute(String p_name, int p_conceptId, Random p_rng, List<String> p_corpus) { attribute = new Attribute(p_name, p_corpus, p_conceptId); rng = p_rng; variance = 0;//rng.nextDouble() * 0.15; // Default to modest variance expectedValues = new double[Math.max(1, rng.nextInt(2) + 1)]; // Between 1 and 3 models in mixture velocity = new double[expectedValues.length]; for (int i = 0; i < expectedValues.length; i++) { velocity[i] = 0;//rng.nextDouble() * 0.5 - 0.25; expectedValues[i] = rng.nextDouble(); } }
From source file:org.goai.classification.impl.WekaClassifier.java
License:Apache License
/** * Create empty weka data set//from w w w .j a va2 s .c o m * @param numOfAttr int Number of attributes without class attribute * @param capacity int Capacity of sample * @return Instances weka data set */ private Instances createEmptyInstancesDataSet(int numOfAttr, int capacity) { //Vector for class attribute possible values FastVector fvClassVal = new FastVector(); //Map double value for every possible class value classVals = new HashMap<String, Double>(); //Map class label with double key value classValsDoubleAsKey = new HashMap<Double, String>(); //ind represents double value for class attribute int ind = 0; //loop through possible class values for (String values : classValues) { //add value to vector fvClassVal.addElement(values); //map double value for class value classVals.put(values, new Double(ind)); //map class label for double key value classValsDoubleAsKey.put(new Double(ind), values); ind++; } //Class attribute with possible values Attribute classAttribute = new Attribute("theClass", fvClassVal, classValues.size()); //Creating attribute vector for Instances class instance FastVector fvWekaAttributes = new FastVector(numOfAttr + 1); //Fill vector with simple attributes for (int i = 0; i < numOfAttr; i++) { fvWekaAttributes.addElement(new Attribute(i + "", i)); } //Add class attribute to vector fvWekaAttributes.addElement(classAttribute); //newDataSet as Instances class instance Instances newDataSet = new Instances("newDataSet", fvWekaAttributes, capacity); return newDataSet; }
From source file:reactivetechnologies.sentigrade.dto.RequestData.java
License:Apache License
/** * /*w w w. ja v a2 s. c o m*/ */ protected void buildStructure() { Assert.notEmpty(getClasses(), "'class' is empty or null"); Attribute attr0 = new Attribute(ClassificationModelEngine.CLASSIFIER_ATTRIB_TEXT, (List<String>) null, ClassificationModelEngine.CLASSIFIER_ATTRIB_TEXT_IDX); Attribute attr1 = new Attribute(ClassificationModelEngine.CLASSIFIER_ATTRIB_CLASS, getClasses(), ClassificationModelEngine.CLASSIFIER_ATTRIB_CLASS_IDX); structure = new Instances(getDomain(), new ArrayList<>(Arrays.asList(attr0, attr1)), getDataSet().size()); structure.setClass(attr1); }