Java Code Examples for weka.core.Instances#relationName()
The following examples show how to use
weka.core.Instances#relationName() .
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: Filter.java From tsml with GNU General Public License v3.0 | 6 votes |
/** * Sets the format of output instances. The derived class should use this * method once it has determined the outputformat. The * output queue is cleared. * * @param outputFormat the new output format */ protected void setOutputFormat(Instances outputFormat) { if (outputFormat != null) { m_OutputFormat = outputFormat.stringFreeStructure(); initOutputLocators(m_OutputFormat, null); // Rename the relation String relationName = outputFormat.relationName() + "-" + this.getClass().getName(); if (this instanceof OptionHandler) { String [] options = ((OptionHandler)this).getOptions(); for (int i = 0; i < options.length; i++) { relationName += options[i].trim(); } } m_OutputFormat.setRelationName(relationName); } else { m_OutputFormat = null; } m_OutputQueue = new Queue(); }
Example 2
Source File: Tuner.java From tsml with GNU General Public License v3.0 | 6 votes |
public ClassifierResults evaluateParameterSetByIndex(AbstractClassifier baseClassifier, Instances trainSet, ParameterSpace parameterSpace, int parameterIndex) throws Exception { classifierName = baseClassifier.getClass().getSimpleName(); datasetName = trainSet.relationName(); searcher.setParameterSpace(parameterSpace); Iterator<ParameterSet> iter = searcher.iterator(); //iterate up to the specified parameter int id = 0; while (iter.hasNext()) { ParameterSet pset = iter.next(); if (id++ == parameterIndex) { //para found, evaluate it and return the results ClassifierResults results = evaluateParameterSet(baseClassifier, trainSet, pset); return results; } } return null; //todo, this should probs be an exception throw instead, tbd }
Example 3
Source File: ClusteredShapeletTransform.java From tsml with GNU General Public License v3.0 | 6 votes |
/** * * @param inputFormat - the format of the input data * @return a new Instances object in the desired output format * @throws Exception - if all required attributes of the filter are not initialised correctly */ @Override protected Instances determineOutputFormat(Instances inputFormat) throws Exception{ int s=st.getNumberOfShapelets(); if(s < 1 || s<noClust){ throw new Exception("ShapeletFilter not initialised correctly - please specify a value of k that is greater than or equal to 1. You entered s="+s+" num clusters ="+noClust); } ArrayList<Attribute> atts = new ArrayList<>(); String name; for(int i = 0; i < noClust; i++){ name = "CShapelet_" + i; atts.add(new Attribute(name)); } Attribute target = inputFormat.attribute(inputFormat.classIndex()); ArrayList<String> vals = new ArrayList(target.numValues()); for(int i = 0; i < target.numValues(); i++){ vals.add(target.value(i)); } atts.add(new Attribute(inputFormat.attribute(inputFormat.classIndex()).name(), vals)); Instances result = new Instances("CShapelets" + inputFormat.relationName(), atts, inputFormat.numInstances()); result.setClassIndex(result.numAttributes() - 1); return result; }
Example 4
Source File: TweetToWordListCountFeatureVector.java From AffectiveTweets with GNU General Public License v3.0 | 6 votes |
@Override protected Instances determineOutputFormat(Instances inputFormat) throws Exception { ArrayList<Attribute> att = new ArrayList<Attribute>(); // Adds all attributes of the inputformat for (int i = 0; i < inputFormat.numAttributes(); i++) { att.add(inputFormat.attribute(i)); } // adds the new attribute att.add(new Attribute("wordListCount")); Instances result = new Instances(inputFormat.relationName(), att, 0); // set the class index result.setClassIndex(inputFormat.classIndex()); return result; }
Example 5
Source File: Reorder.java From tsml with GNU General Public License v3.0 | 6 votes |
/** * Sets the format of the input instances. * * @param instanceInfo an Instances object containing the input instance * structure (any instances contained in the object are ignored - only the * structure is required). * @return true if the outputFormat may be collected immediately * @throws Exception if a problem occurs setting the input format */ public boolean setInputFormat(Instances instanceInfo) throws Exception { super.setInputFormat(instanceInfo); FastVector attributes = new FastVector(); int outputClass = -1; m_SelectedAttributes = determineIndices(instanceInfo.numAttributes()); for (int i = 0; i < m_SelectedAttributes.length; i++) { int current = m_SelectedAttributes[i]; if (instanceInfo.classIndex() == current) { outputClass = attributes.size(); } Attribute keep = (Attribute)instanceInfo.attribute(current).copy(); attributes.addElement(keep); } initInputLocators(instanceInfo, m_SelectedAttributes); Instances outputFormat = new Instances(instanceInfo.relationName(), attributes, 0); outputFormat.setClassIndex(outputClass); setOutputFormat(outputFormat); return true; }
Example 6
Source File: PLSNominalClassifier.java From tsml with GNU General Public License v3.0 | 5 votes |
@Override public void buildClassifier(Instances data) throws Exception { Instances train = new Instances(data); numClasses = train.numClasses(); classind = train.classIndex(); classAttribute = train.classAttribute(); FastVector<Attribute> atts = new FastVector<>(train.numAttributes()); for (int i = 0; i < train.numAttributes(); i++) { if (i != classind) atts.add(train.attribute(i)); else { //class attribute Attribute numericClassAtt = new Attribute(train.attribute(i).name()); atts.add(numericClassAtt); } } Instances temp = new Instances(train.relationName(), atts, train.numInstances()); temp.setClassIndex(classind); for (int i = 0; i < train.numInstances(); i++) { temp.add(new DenseInstance(1.0, train.instance(i).toDoubleArray())); temp.instance(i).setClassValue(train.instance(i).classValue()); } train = temp; //datset is in the proper format, now do the model fitting as normal super.buildClassifier(train); }
Example 7
Source File: Remove.java From tsml with GNU General Public License v3.0 | 5 votes |
/** * Sets the format of the input instances. * * @param instanceInfo an Instances object containing the input instance * structure (any instances contained in the object are ignored - only the * structure is required). * @return true if the outputFormat may be collected immediately * @throws Exception if the format couldn't be set successfully */ public boolean setInputFormat(Instances instanceInfo) throws Exception { super.setInputFormat(instanceInfo); m_SelectCols.setUpper(instanceInfo.numAttributes() - 1); // Create the output buffer FastVector attributes = new FastVector(); int outputClass = -1; m_SelectedAttributes = m_SelectCols.getSelection(); for (int i = 0; i < m_SelectedAttributes.length; i++) { int current = m_SelectedAttributes[i]; if (instanceInfo.classIndex() == current) { outputClass = attributes.size(); } Attribute keep = (Attribute)instanceInfo.attribute(current).copy(); attributes.addElement(keep); } //initInputLocators(instanceInfo, m_SelectedAttributes); initInputLocators(getInputFormat(), m_SelectedAttributes); Instances outputFormat = new Instances(instanceInfo.relationName(), attributes, 0); outputFormat.setClassIndex(outputClass); setOutputFormat(outputFormat); return true; }
Example 8
Source File: PartitionMembership.java From tsml with GNU General Public License v3.0 | 5 votes |
/** * Signify that this batch of input to the filter is finished. * * @return true if there are instances pending output * @throws IllegalStateException if no input structure has been defined */ public boolean batchFinished() throws Exception { if (getInputFormat() == null) { throw new IllegalStateException("No input instance format defined"); } if (outputFormatPeek() == null) { Instances toFilter = getInputFormat(); // Build the partition generator m_partitionGenerator.generatePartition(toFilter); // Create output dataset FastVector attInfo = new FastVector(); for (int i = 0; i < m_partitionGenerator.numElements(); i++) { attInfo.addElement(new Attribute("partition_" + i)); } if (toFilter.classIndex() >= 0) { attInfo.addElement(toFilter.classAttribute().copy()); } attInfo.trimToSize(); Instances filtered = new Instances(toFilter.relationName() + "_partitionMembership", attInfo, 0); if (toFilter.classIndex() >= 0) { filtered.setClassIndex(filtered.numAttributes() - 1); } setOutputFormat(filtered); // build new dataset for (int i = 0; i < toFilter.numInstances(); i++) { convertInstance(toFilter.instance(i)); } } flushInput(); m_NewBatch = true; return (numPendingOutput() != 0); }
Example 9
Source File: Differences.java From tsml with GNU General Public License v3.0 | 5 votes |
protected Instances determineOutputFormat(Instances inputFormat) throws Exception { //Check all attributes are real valued, otherwise throw exception for(int i=0;i<inputFormat.numAttributes();i++) if(inputFormat.classIndex()!=i) { if (!inputFormat.attribute(i).isNumeric()) throw new Exception("Non numeric attribute not allowed in Moments"); } //Set up instances size and format. ArrayList<Attribute> atts = new ArrayList<>(); String name; for(int i=0;i<inputFormat.numAttributes()-order-1;i++){ name = attName+"Difference"+order+"_"+(i+1); atts.add(new Attribute(name)); } if(inputFormat.classIndex()>=0){ //Classification set, set class //Get the class values as a fast vector Attribute target =inputFormat.attribute(inputFormat.classIndex()); ArrayList<String> vals=new ArrayList<>(); for(int i=0;i<target.numValues();i++) vals.add(target.value(i)); atts.add(new Attribute(inputFormat.attribute(inputFormat.classIndex()).name(),vals)); } Instances result = new Instances("Difference"+order+inputFormat.relationName(),atts,inputFormat.numInstances()); if(inputFormat.classIndex()>=0){ result.setClassIndex(result.numAttributes()-1); } return result; }
Example 10
Source File: PAA.java From tsml with GNU General Public License v3.0 | 5 votes |
@Override protected Instances determineOutputFormat(Instances inputFormat) throws Exception { //Check all attributes are real valued, otherwise throw exception for (int i = 0; i < inputFormat.numAttributes(); i++) { if (inputFormat.classIndex() != i) { if (!inputFormat.attribute(i).isNumeric()) { throw new Exception("Non numeric attribute not allowed for PAA"); } } } //Set up instances size and format. ArrayList<Attribute> attributes = new ArrayList<>(); for (int i = 0; i < numIntervals; i++) attributes.add(new Attribute("PAAInterval_" + i)); if (inputFormat.classIndex() >= 0) { //Classification set, set class //Get the class values as a fast vector Attribute target = inputFormat.attribute(inputFormat.classIndex()); ArrayList<String> vals = new ArrayList<>(target.numValues()); for (int i = 0; i < target.numValues(); i++) { vals.add(target.value(i)); } attributes.add(new Attribute(inputFormat.attribute(inputFormat.classIndex()).name(), vals)); } Instances result = new Instances("PAA" + inputFormat.relationName(), attributes, inputFormat.numInstances()); if (inputFormat.classIndex() >= 0) { result.setClassIndex(result.numAttributes() - 1); } return result; }
Example 11
Source File: PACF.java From tsml with GNU General Public License v3.0 | 5 votes |
@Override protected Instances determineOutputFormat(Instances inputFormat) throws Exception { //Check capabilities for the filter. Can only handle real valued, no missing. getCapabilities().testWithFail(inputFormat); seriesLength=inputFormat.numAttributes(); if(inputFormat.classIndex()>=0) seriesLength--; if(maxLag>seriesLength-endTerms) maxLag=seriesLength-endTerms; if(maxLag<0) maxLag=inputFormat.numAttributes()-1; //Set up instances size and format. ArrayList<Attribute> atts=new ArrayList<>(); String name; for(int i=0;i<maxLag;i++){ name = "PACF_"+i; atts.add(new Attribute(name)); } if(inputFormat.classIndex()>=0){ //Classification set, set class //Get the class values Attribute target =inputFormat.attribute(inputFormat.classIndex()); ArrayList<String> vals=new ArrayList<>(target.numValues()); for(int i=0;i<target.numValues();i++) vals.add(target.value(i)); atts.add(new Attribute(inputFormat.attribute(inputFormat.classIndex()).name(),vals)); } Instances result = new Instances("PACF"+inputFormat.relationName(),atts,inputFormat.numInstances()); if(inputFormat.classIndex()>=0) result.setClassIndex(result.numAttributes()-1); return result; }
Example 12
Source File: SummaryStats.java From tsml with GNU General Public License v3.0 | 5 votes |
protected Instances determineOutputFormat(Instances inputFormat) throws Exception { //Check all attributes are real valued, otherwise throw exception for(int i=0;i<inputFormat.numAttributes();i++) if(inputFormat.classIndex()!=i) if(!inputFormat.attribute(i).isNumeric()) throw new Exception("Non numeric attribute not allowed in SummaryStats"); //Set up instances size and format. ArrayList<Attribute> atts=new ArrayList(); String source=inputFormat.relationName(); String name; for(int i=0;i<numMoments;i++){ name =source+"Moment_"+(i+1); atts.add(new Attribute(name)); } atts.add(new Attribute(source+"MIN")); atts.add(new Attribute(source+"MAX")); if(inputFormat.classIndex()>=0){ //Classification set, set class //Get the class values as a fast vector Attribute target =inputFormat.attribute(inputFormat.classIndex()); ArrayList<String> vals=new ArrayList<>(target.numValues()); for(int i=0;i<target.numValues();i++) vals.add(target.value(i)); atts.add(new Attribute(inputFormat.attribute(inputFormat.classIndex()).name(),vals)); } Instances result = new Instances("Moments"+inputFormat.relationName(),atts,inputFormat.numInstances()); if(inputFormat.classIndex()>=0){ result.setClassIndex(result.numAttributes()-1); } return result; }
Example 13
Source File: BinaryTransform.java From tsml with GNU General Public License v3.0 | 5 votes |
@Override protected Instances determineOutputFormat(Instances inputFormat) throws Exception{ //Check all are numerical //Check all attributes are real valued, otherwise throw exception for(int i=0;i<inputFormat.numAttributes();i++) if(inputFormat.classIndex()!=i) if(!inputFormat.attribute(i).isNumeric()) throw new Exception("Non numeric attribute not allowed in BinaryTransform"); int length=inputFormat.numAttributes(); if(inputFormat.classIndex()>=0) length--; //Set up instances size and format. ArrayList<Attribute> atts=new ArrayList<>(); ArrayList<String> attributeValues=new ArrayList<>(); attributeValues.add("0"); attributeValues.add("1"); String name; for(int i=0;i<length;i++){ name = "Binary_"+i; atts.add(new Attribute(name,attributeValues)); } if(inputFormat.classIndex()>=0){ //Classification set, set class //Get the class values as a fast vector Attribute target =inputFormat.attribute(inputFormat.classIndex()); ArrayList<String> vals=new ArrayList<>(); for(int i=0;i<target.numValues();i++) vals.add(target.value(i)); atts.add(new Attribute(inputFormat.attribute(inputFormat.classIndex()).name(),vals)); } Instances result = new Instances("Binary"+inputFormat.relationName(),atts,inputFormat.numInstances()); if(inputFormat.classIndex()>=0){ result.setClassIndex(result.numAttributes()-1); } return result; }
Example 14
Source File: WekaInstancesUtil.java From AILibs with GNU Affero General Public License v3.0 | 5 votes |
public static ILabeledInstanceSchema extractSchema(final Instances dataset) { int targetIndex = dataset.classIndex(); if (targetIndex < 0) { throw new IllegalArgumentException("Class index of Instances object is not set!"); } List<IAttribute> attributes = IntStream.range(0, dataset.numAttributes()).mapToObj(dataset::attribute).map(WekaInstancesUtil::transformWEKAAttributeToAttributeType).collect(Collectors.toList()); IAttribute labelAttribute = attributes.remove(targetIndex); return new LabeledInstanceSchema(dataset.relationName(), attributes, labelAttribute); }
Example 15
Source File: TweetToEmbeddingsFeatureVector.java From AffectiveTweets with GNU General Public License v3.0 | 4 votes |
@Override protected Instances determineOutputFormat(Instances inputFormat) throws Exception { // set upper value for text index m_textIndex.setUpper(inputFormat.numAttributes() - 1); ArrayList<Attribute> att = new ArrayList<Attribute>(); // Adds all attributes of the inputformat for (int i = 0; i < inputFormat.numAttributes(); i++) { att.add(inputFormat.attribute(i)); } // The dictionaries of the lexicons are initialized only in the first batch if(!this.isFirstBatchDone()){ this.embeddingHandler.createDict(); } if(this.m_action.equals(Action.AVERAGE_ACTION) || this.m_action.equals(Action.ADD_ACTION)){ for(int j=0;j<this.embeddingHandler.getDimensions();j++){ att.add(new Attribute("Embedding-"+j)); } } else if(this.m_action.equals(Action.CONCATENATE_ACTION)){ for(int i=0;i<this.k;i++){ for(int j=0;j<this.embeddingHandler.getDimensions();j++){ att.add(new Attribute("Embedding-"+i+","+j)); } } } Instances result = new Instances(inputFormat.relationName(), att, 0); // set the class index result.setClassIndex(inputFormat.classIndex()); return result; }
Example 16
Source File: FirstOrder.java From tsml with GNU General Public License v3.0 | 4 votes |
/** * Sets the format of the input instances. * * @param instanceInfo an Instances object containing the input instance * structure (any instances contained in the object are ignored - only the * structure is required). * @return true if the outputFormat may be collected immediately * @throws UnsupportedAttributeTypeException if any of the * selected attributes are not numeric * @throws Exception if only one attribute has been selected. */ public boolean setInputFormat(Instances instanceInfo) throws Exception { super.setInputFormat(instanceInfo); m_DeltaCols.setUpper(getInputFormat().numAttributes() - 1); int selectedCount = 0; for (int i = getInputFormat().numAttributes() - 1; i >= 0; i--) { if (m_DeltaCols.isInRange(i)) { selectedCount++; if (!getInputFormat().attribute(i).isNumeric()) { throw new UnsupportedAttributeTypeException("Selected attributes must be all numeric"); } } } if (selectedCount == 1) { throw new Exception("Cannot select only one attribute."); } // Create the output buffer FastVector newAtts = new FastVector(); boolean inRange = false; String foName = null; int clsIndex = -1; for(int i = 0; i < instanceInfo.numAttributes(); i++) { if (m_DeltaCols.isInRange(i) && (i != instanceInfo.classIndex())) { if (inRange) { Attribute newAttrib = new Attribute(foName); newAtts.addElement(newAttrib); } foName = instanceInfo.attribute(i).name(); foName = "'FO " + foName.replace('\'', ' ').trim() + '\''; inRange = true; } else { newAtts.addElement((Attribute)instanceInfo.attribute(i).copy()); if ((i == instanceInfo.classIndex())) clsIndex = newAtts.size() - 1; } } Instances data = new Instances(instanceInfo.relationName(), newAtts, 0); data.setClassIndex(clsIndex); setOutputFormat(data); return true; }
Example 17
Source File: ClusterMembership.java From tsml with GNU General Public License v3.0 | 4 votes |
/** * Signify that this batch of input to the filter is finished. * * @return true if there are instances pending output * @throws IllegalStateException if no input structure has been defined */ public boolean batchFinished() throws Exception { if (getInputFormat() == null) { throw new IllegalStateException("No input instance format defined"); } if (outputFormatPeek() == null) { Instances toFilter = getInputFormat(); Instances[] toFilterIgnoringAttributes; // Make subsets if class is nominal if ((toFilter.classIndex() >= 0) && toFilter.classAttribute().isNominal()) { toFilterIgnoringAttributes = new Instances[toFilter.numClasses()]; for (int i = 0; i < toFilter.numClasses(); i++) { toFilterIgnoringAttributes[i] = new Instances(toFilter, toFilter.numInstances()); } for (int i = 0; i < toFilter.numInstances(); i++) { toFilterIgnoringAttributes[(int)toFilter.instance(i).classValue()].add(toFilter.instance(i)); } m_priors = new double[toFilter.numClasses()]; for (int i = 0; i < toFilter.numClasses(); i++) { toFilterIgnoringAttributes[i].compactify(); m_priors[i] = toFilterIgnoringAttributes[i].sumOfWeights(); } Utils.normalize(m_priors); } else { toFilterIgnoringAttributes = new Instances[1]; toFilterIgnoringAttributes[0] = toFilter; m_priors = new double[1]; m_priors[0] = 1; } // filter out attributes if necessary for (int i = 0; i < toFilterIgnoringAttributes.length; i++) toFilterIgnoringAttributes[i] = removeIgnored(toFilterIgnoringAttributes[i]); // build the clusterers if ((toFilter.classIndex() <= 0) || !toFilter.classAttribute().isNominal()) { m_clusterers = AbstractDensityBasedClusterer.makeCopies(m_clusterer, 1); m_clusterers[0].buildClusterer(toFilterIgnoringAttributes[0]); } else { m_clusterers = AbstractDensityBasedClusterer.makeCopies(m_clusterer, toFilter.numClasses()); for (int i = 0; i < m_clusterers.length; i++) { if (toFilterIgnoringAttributes[i].numInstances() == 0) { m_clusterers[i] = null; } else { m_clusterers[i].buildClusterer(toFilterIgnoringAttributes[i]); } } } // create output dataset FastVector attInfo = new FastVector(); for (int j = 0; j < m_clusterers.length; j++) { if (m_clusterers[j] != null) { for (int i = 0; i < m_clusterers[j].numberOfClusters(); i++) { attInfo.addElement(new Attribute("pCluster_" + j + "_" + i)); } } } if (toFilter.classIndex() >= 0) { attInfo.addElement(toFilter.classAttribute().copy()); } attInfo.trimToSize(); Instances filtered = new Instances(toFilter.relationName()+"_clusterMembership", attInfo, 0); if (toFilter.classIndex() >= 0) { filtered.setClassIndex(filtered.numAttributes() - 1); } setOutputFormat(filtered); // build new dataset for (int i = 0; i < toFilter.numInstances(); i++) { convertInstance(toFilter.instance(i)); } } flushInput(); m_NewBatch = true; return (numPendingOutput() != 0); }
Example 18
Source File: PMILexiconExpander.java From AffectiveTweets with GNU General Public License v3.0 | 4 votes |
@Override protected Instances determineOutputFormat(Instances inputFormat) { // set upper value for text index m_textIndex.setUpper(inputFormat.numAttributes() - 1); ArrayList<Attribute> att = new ArrayList<Attribute>(); att.add(new Attribute("WORD_NAME", (ArrayList<String>) null)); att.add(new Attribute("PMI-SO")); Instances result = new Instances(inputFormat.relationName(), att, 0); return result; }
Example 19
Source File: Tuner.java From tsml with GNU General Public License v3.0 | 4 votes |
public ParameterResults tune(AbstractClassifier baseClassifier, Instances trainSet, ParameterSpace parameterSpace) throws Exception { //System.out.println("Evaluating para space: " + parameterSpace); //for contracting long startTime = System.nanoTime(); long maxParaEvalTime = 0; //meta info in case we're saving para files classifierName = baseClassifier.getClass().getSimpleName(); datasetName = trainSet.relationName(); //init the space searcher searcher.setParameterSpace(parameterSpace); Iterator<ParameterSet> iter = searcher.iterator(); //for resolving ties for the best paraset List<ParameterResults> tiesBestSoFar = new ArrayList<>(); //iterate over the space int parameterSetID = -1; while (iter.hasNext()) { parameterSetID++; ParameterSet pset = iter.next(); long thisParaStartTime = System.nanoTime(); if (saveParameters && parametersAlreadyEvaluated(parameterSetID)) continue; // THE WORK ClassifierResults results = evaluateParameterSet(baseClassifier, trainSet, pset); if (saveParameters) saveParaResults(parameterSetID, results); else storeParaResult(pset, results, tiesBestSoFar); if (trainTimeContract) { long thisParaTime = System.nanoTime() - thisParaStartTime; if (thisParaTime > maxParaEvalTime) maxParaEvalTime = thisParaTime; long totalTimeSoFar = System.nanoTime() - startTime; // int numParasEvald = parameterSetID + 1; // long avgTimePerPara = totalTimeSoFar / numParasEvald; if (!canWeEvaluateAnotherParaSet(maxParaEvalTime, totalTimeSoFar)) break; } //System.out.println("Score: " + String.format("%5f", score) + "\tParas: " + pset); } if (saveParameters) { // if we're contracting, (but also saving parasets) // we might not have had time to eval ALL the psets, justfind the best so far // if we're contracting but not saving each paraset, we'll have been using // storeParaResult() and have them in memory currently anyway if (trainTimeContract) tiesBestSoFar = loadBestOfSavedParas_SoFar(); else tiesBestSoFar = loadBestOfSavedParas_All(parameterSpace.numUniqueParameterSets()); //conversely if we're NOT contracting, we have the strict requirement that //the entire space has been evaluated (or at least has been fully iterated over as defined by the //searcher, e.g RandomSearcher has searched it's full 1000 times etc) } bestParaSetAndResults = resolveTies(tiesBestSoFar); //System.out.println("Best parameter set was: " + bestSet); return bestParaSetAndResults; }
Example 20
Source File: TweetToInputLexiconFeatureVector.java From AffectiveTweets with GNU General Public License v3.0 | 3 votes |
@Override protected Instances determineOutputFormat(Instances inputFormat) throws Exception { ArrayList<Attribute> att = new ArrayList<Attribute>(); // Adds all attributes of the inputformat for (int i = 0; i < inputFormat.numAttributes(); i++) { att.add(inputFormat.attribute(i)); } // The dictionaries of the lexicons are initialized only in the first batch if(!this.isFirstBatchDone()) this.initializeDicts(); for(ArffLexiconEvaluator lexEval:this.lexiconEval){ for(String attName:lexEval.getFeatureNames()) att.add(new Attribute(attName)); } Instances result = new Instances(inputFormat.relationName(), att, 0); // set the class index result.setClassIndex(inputFormat.classIndex()); return result; }