meka.classifiers.multilabel.MultiLabelClassifier Java Examples

The following examples show how to use meka.classifiers.multilabel.MultiLabelClassifier. 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: KeyValuePairs.java    From meka with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Retrieves the statis for the specified combination of classifier and dataset.
 *
 * @param classifier    the classifier to check
 * @param dataset       the dataset to check
 * @return              the stats, null if not available
 */
public List<EvaluationStatistics> retrieve(MultiLabelClassifier classifier, Instances dataset) {
	List<EvaluationStatistics>  result;
	String                      cls;
	String                      rel;

	result = new ArrayList<>();

	cls = Utils.toCommandLine(classifier);
	rel = dataset.relationName();

	for (EvaluationStatistics stat: m_Statistics) {
		if (stat.getCommandLine().equals(cls) && stat.getRelation().equals(rel))
			result.add(stat);
	}

	return result;
}
 
Example #2
Source File: RepeatedRuns.java    From meka with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Executes the runs in sequential order.
 *
 * @param classifier    the classifier to evaluate
 * @param dataset       the dataset to evaluate on
 * @return              the statistics
 */
protected List<EvaluationStatistics> evaluateSequential(MultiLabelClassifier classifier, Instances dataset) {
	List<EvaluationStatistics>  result;
	List<EvaluationStatistics>  stats;
	int                         i;

	result = new ArrayList<>();

	for (i = m_LowerRuns; i <= m_UpperRuns; i++) {
		log("Run: " + i);
		if (m_Evaluator instanceof Randomizable)
			((Randomizable) m_Evaluator).setSeed(i);
		m_Evaluator.initialize();
		stats = m_Evaluator.evaluate(classifier, dataset);
		if (stats != null) {
			for (EvaluationStatistics stat: stats) {
				stat.put(KEY_RUN, i);
				result.add(stat);
			}
		}
		if (m_Stopped)
			break;
	}

	return result;
}
 
Example #3
Source File: ExpertSetup.java    From meka with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Lets the user add a classifier.
 */
protected void addClassifier() {
	GenericObjectEditorDialog   dialog;

	dialog = getGOEDialog(MultiLabelClassifier.class, new BR());
	dialog.setTitle("Add classifier");
	dialog.setLocationRelativeTo(this);
	dialog.setVisible(true);
	if (dialog.getResult() != GenericObjectEditorDialog.APPROVE_OPTION)
		return;

	if (m_ListClassifiers.getList().getSelectedIndex() > -1)
		m_ModelClassifiers.insertElementAt(OptionUtils.toCommandLine(dialog.getCurrent()), m_ListClassifiers.getList().getSelectedIndex());
	else
		m_ModelClassifiers.addElement(OptionUtils.toCommandLine(dialog.getCurrent()));
	m_Modified = true;
	updateButtons();
}
 
Example #4
Source File: ExpertSetup.java    From meka with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Lets the user edit a classifier.
 */
protected void editClassifier() {
	GenericObjectEditorDialog   dialog;
	String                      classifier;

	if (m_ListClassifiers.getList().getSelectedIndex() == -1)
		return;

	dialog     = getGOEDialog(MultiLabelClassifier.class, new BR());
	dialog.setTitle("Edit classifier");
	classifier = m_ModelClassifiers.get(m_ListClassifiers.getList().getSelectedIndex());
	try {
		dialog.setCurrent(OptionUtils.fromCommandLine(MultiLabelClassifier.class, classifier));
	}
	catch (Exception e) {
		handleException("Failed to edit classifier: " + classifier, e);
	}
	dialog.setLocationRelativeTo(this);
	dialog.setVisible(true);
	if (dialog.getResult() != GenericObjectEditorDialog.APPROVE_OPTION)
		return;

	m_ModelClassifiers.setElementAt(OptionUtils.toCommandLine(dialog.getCurrent()), m_ListClassifiers.getList().getSelectedIndex());
	m_Modified = true;
	updateButtons();
}
 
Example #5
Source File: ExpertSetup.java    From meka with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Stores the parameters in an experiment.
 *
 * @return          the generated experiment
 */
protected Experiment toExperiment() {
	Experiment              result;
	MultiLabelClassifier[]  classifiers;
	int                     i;

	result = (Experiment) ObjectUtils.deepCopy(m_Experiment);
	classifiers = new MultiLabelClassifier[m_ModelClassifiers.getSize()];
	for (i = 0; i < m_ModelClassifiers.getSize(); i++) {
		try {
			classifiers[i] = OptionUtils.fromCommandLine(MultiLabelClassifier.class, m_ModelClassifiers.get(i));
		}
		catch (Exception e) {
			handleException("Failed to instantiate classifier: " + m_ModelClassifiers.get(i), e);
			classifiers[i] = new BR();
		}
	}
	result.setClassifiers(classifiers);
	result.setDatasetProvider((DatasetProvider) m_GOEDatasets.getValue());
	result.setEvaluator((Evaluator) m_GOEEvaluator.getValue());
	result.setStatisticsHandler((EvaluationStatisticsHandler) m_GOEStatisticsHandler.getValue());
	result.setNotes(m_Notes);

	return result;
}
 
Example #6
Source File: RepeatedRuns.java    From meka with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns the evaluation statistics generated for the dataset.
 *
 * @param classifier    the classifier to evaluate
 * @param dataset       the dataset to evaluate on
 * @return              the statistics
 */
@Override
public List<EvaluationStatistics> evaluate(MultiLabelClassifier classifier, Instances dataset) {
	List<EvaluationStatistics>  result;

	m_ActualNumThreads = ThreadUtils.getActualNumThreads(m_NumThreads, m_UpperRuns - m_LowerRuns + 1);

	log("Number of threads (" + ThreadUtils.SEQUENTIAL + " = sequential): " + m_ActualNumThreads);
	if (m_ActualNumThreads == ThreadUtils.SEQUENTIAL)
		result = evaluateSequential(classifier, dataset);
	else
		result = evaluateParallel(classifier, dataset);

	if (m_Stopped)
		result.clear();

	return result;
}
 
Example #7
Source File: CrossValidation.java    From meka with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns the evaluation statistics generated for the dataset.
 *
 * @param classifier    the classifier to evaluate
 * @param dataset       the dataset to evaluate on
 * @return              the statistics
 */
@Override
public List<EvaluationStatistics> evaluate(MultiLabelClassifier classifier, Instances dataset) {
	List<EvaluationStatistics>  result;

	m_ActualNumThreads = ThreadUtils.getActualNumThreads(m_NumThreads, m_NumFolds);

	log("Number of threads (" + ThreadUtils.SEQUENTIAL + " = sequential): " + m_ActualNumThreads);
	if (m_ActualNumThreads == ThreadUtils.SEQUENTIAL)
		result = evaluateSequential(classifier, dataset);
	else
		result = evaluateParallel(classifier, dataset);

	if (m_Stopped)
		result.clear();

	return result;
}
 
Example #8
Source File: EvaluationStatisticsUtils.java    From meka with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns all the unique classifiers of all the statistics.
 *
 * @param stats     the stats to inspect
 * @param sort      whether to sort the classifiers alphabetically
 * @return          the classifiers
 */
public static List<MultiLabelClassifier> classifiers(List<EvaluationStatistics> stats, boolean sort) {
	List<MultiLabelClassifier>      result;
	List<String>                    cmdlines;

	result   = new ArrayList<>();
	cmdlines = commandLines(stats, sort);
	for (String cmdline: cmdlines) {
		try {
			result.add(OptionUtils.fromCommandLine(MultiLabelClassifier.class, cmdline));
		}
		catch (Exception e) {
			System.err.println("Failed to instantiate command-line: " + cmdline);
			e.printStackTrace();
		}
	}

	return result;
}
 
Example #9
Source File: KeyValuePairs.java    From meka with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Checks whether the specified combination of classifier and dataset is required for evaluation
 * or already present from previous evaluation.
 *
 * @param classifier    the classifier to check
 * @param dataset       the dataset to check
 * @return              true if it needs evaluating
 */
public boolean requires(MultiLabelClassifier classifier, Instances dataset) {
	boolean     result;
	String      cls;
	String      rel;

	result = true;

	cls = Utils.toCommandLine(classifier);
	rel = dataset.relationName();

	for (EvaluationStatistics stat: m_Statistics) {
		if (stat.getCommandLine().equals(cls) && stat.getRelation().equals(rel)) {
			result = false;
			break;
		}
	}

	return result;
}
 
Example #10
Source File: ClassifyTab.java    From meka with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Initializes the members.
 */
@Override
protected void initialize() {
	super.initialize();

	m_LastNonIncrementalClassifier = new meka.classifiers.multilabel.BR();
	m_LastIncrementalClassifier    = new meka.classifiers.multilabel.incremental.BRUpdateable();

	m_GenericObjectEditor = new GenericObjectEditor(true);
	m_GenericObjectEditor.setClassType(MultiLabelClassifier.class);
	m_GenericObjectEditor.setValue(m_LastNonIncrementalClassifier);

	m_Seed                = 1;
	m_SplitPercentage     = 66.0;
	m_Folds               = 10;
	m_Samples             = 10;
	m_Randomize           = true;
	m_TOP                 = "PCut1";
	m_VOP                 = "3";
	m_TestInstances       = null;
	m_ClassifyTabOptions  = null;
	m_AdditionalMenuItems = new HashMap<>();
}
 
Example #11
Source File: BasicSetup.java    From meka with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Lets the user add a classifier.
 */
protected void addClassifier() {
	GenericObjectEditorDialog dialog;

	dialog = getGOEDialog(MultiLabelClassifier.class, new BR());
	dialog.setTitle("Add classifier");
	dialog.setLocationRelativeTo(this);
	dialog.setVisible(true);
	if (dialog.getResult() != GenericObjectEditorDialog.APPROVE_OPTION)
		return;

	if (m_ListClassifiers.getList().getSelectedIndex() > -1)
		m_ModelClassifiers.insertElementAt(OptionUtils.toCommandLine(dialog.getCurrent()), m_ListClassifiers.getList().getSelectedIndex());
	else
		m_ModelClassifiers.addElement(OptionUtils.toCommandLine(dialog.getCurrent()));
	m_Modified = true;
	updateButtons();
}
 
Example #12
Source File: BasicSetup.java    From meka with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Lets the user edit a classifier.
 */
protected void editClassifier() {
	GenericObjectEditorDialog   dialog;
	String                      classifier;

	if (m_ListClassifiers.getList().getSelectedIndex() == -1)
		return;

	dialog     = getGOEDialog(MultiLabelClassifier.class, new BR());
	dialog.setTitle("Edit classifier");
	classifier = m_ModelClassifiers.get(m_ListClassifiers.getList().getSelectedIndex());
	try {
		dialog.setCurrent(OptionUtils.fromCommandLine(MultiLabelClassifier.class, classifier));
	}
	catch (Exception e) {
		handleException("Failed to edit classifier: " + classifier, e);
	}
	dialog.setLocationRelativeTo(this);
	dialog.setVisible(true);
	if (dialog.getResult() != GenericObjectEditorDialog.APPROVE_OPTION)
		return;

	m_ModelClassifiers.setElementAt(OptionUtils.toCommandLine(dialog.getCurrent()), m_ListClassifiers.getList().getSelectedIndex());
	m_Modified = true;
	updateButtons();
}
 
Example #13
Source File: MultiSearch.java    From meka with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Set the base learner.
 *
 * @param newClassifier 	the classifier to use.
 */
@Override
public void setClassifier(Classifier newClassifier) {
	if (!(newClassifier instanceof MultiLabelClassifier))
		throw new IllegalStateException(
			"Base classifier must implement " + MultiLabelClassifier.class.getName()
				+ ", provided: " + newClassifier.getClass().getName());
	super.setClassifier(newClassifier);
}
 
Example #14
Source File: AbstractShowThresholdCurve.java    From meka with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Checks whether the current item can be handled. Disables/enables the menu item.
 *
 * @param history   the current history
 * @param index     the selected history item
 * @return          true if can be handled
 */
@Override
public boolean handles(ResultHistoryList history, int index) {
	boolean     result;

	result = (getClassifier(history, index) instanceof MultiLabelClassifier)
			|| (getClassifier(history, index) instanceof MultiTargetClassifier);

	result = result && (history.getResultAt(index).getMeasurement(CURVE_DATA) != null);

	return result;
}
 
Example #15
Source File: DefaultExperiment.java    From meka with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Sets the options.
 *
 * @param options       the options
 * @throws Exception    if parsing fails
 */
@Override
public void setOptions(String[] options) throws Exception {
	setNotes(Utils.unbackQuoteChars(OptionUtils.parse(options, "notes", "")));
	setClassifiers(OptionUtils.parse(options, 'C', MultiLabelClassifier.class));
	setDatasetProvider((DatasetProvider) OptionUtils.parse(options, 'D', getDefaultDatasetProvider()));
	setEvaluator((Evaluator) OptionUtils.parse(options, 'E', getDefaultEvaluator()));
	setStatisticsHandler((EvaluationStatisticsHandler) OptionUtils.parse(options, 'S', getDefaultStatisticsHandler()));
}
 
Example #16
Source File: DefaultExperiment.java    From meka with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Notifies all listeners of a new classifier/dataset combination.
 *
 * @param classifier    the classifier
 * @param dataset       the dataset
 */
protected synchronized void notifyIterationNotificationListeners(MultiLabelClassifier classifier, Instances dataset) {
	IterationNotificationEvent  e;

	if (m_IterationNotficationListeners == null)
		return;

	e = new IterationNotificationEvent(this, classifier, dataset);
	for (IterationNotificationListener l: m_IterationNotficationListeners)
		l.nextIteration(e);
}
 
Example #17
Source File: ExpertSetup.java    From meka with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Maps the experiment onto the parameters.
 */
protected void fromExperiment() {
	m_ModelClassifiers.removeAllElements();
	for (MultiLabelClassifier classifier: m_Experiment.getClassifiers())
		m_ModelClassifiers.addElement(OptionUtils.toCommandLine(classifier));

	m_GOEDatasets.setValue(m_Experiment.getDatasetProvider());
	m_GOEEvaluator.setValue(m_Experiment.getEvaluator());
	m_GOEStatisticsHandler.setValue(m_Experiment.getStatisticsHandler());
	m_Notes = m_Experiment.getNotes();
}
 
Example #18
Source File: FilteredClassifier.java    From meka with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Set the base learner.
 *
 * @param newClassifier the classifier to use.
 */
@Override
public void setClassifier(Classifier newClassifier) {
	if (!(newClassifier instanceof MultiLabelClassifier))
		throw new IllegalArgumentException("Classifier must be a " + MultiLabelClassifier.class.getName() + "!");
	super.setClassifier(newClassifier);
}
 
Example #19
Source File: FilteredClassifier.java    From meka with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns a string representation of the model.
 *
 * @return the model
 */
@Override
public String getModel() {
	if (m_Classifier instanceof MultiLabelClassifier)
		return ((MultiLabelClassifier) m_Classifier).getModel();
	else
		return toString();
}
 
Example #20
Source File: ARAMNetworkSparseV.java    From meka with GNU General Public License v3.0 5 votes vote down vote up
public static void main(String [] argv) {

    try {
    	Evaluation.runExperiment(((MultiLabelClassifier) new WvARAM()), argv);
    } catch (Exception e) {
      e.printStackTrace();
      System.err.println(e.getMessage());
    }
  }
 
Example #21
Source File: StatUtils.java    From meka with GNU General Public License v3.0 5 votes vote down vote up
/**
 * LEAD - Performs LEAD on dataset 'D', using BR with base classifier 'h', under random seed 'r'.
 * <br>
 * WARNING: changing this method will affect the perfomance of e.g., BCC -- on the other hand the original BCC paper did not use LEAD, so don't worry.
 */
public static double[][] LEAD(Instances D, Classifier h, Random r)  throws Exception {
	Instances D_r = new Instances(D);
	D_r.randomize(r);
	Instances D_train = new Instances(D_r,0,D_r.numInstances()*60/100);
	Instances D_test = new Instances(D_r,D_train.numInstances(),D_r.numInstances()-D_train.numInstances());
	BR br = new BR();
	br.setClassifier(h);
	Result result = Evaluation.evaluateModel((MultiLabelClassifier)br,D_train,D_test,"PCut1","1");
	return LEAD2(D_test,result);
}
 
Example #22
Source File: ARAMNetworkSparseHT.java    From meka with GNU General Public License v3.0 5 votes vote down vote up
public static void main(String [] argv) {

    try {
    	Evaluation.runExperiment(((MultiLabelClassifier) new WvARAM()), argv);
    } catch (Exception e) {
      e.printStackTrace();
      System.err.println(e.getMessage());
    }
  }
 
Example #23
Source File: StatUtils.java    From meka with GNU General Public License v3.0 5 votes vote down vote up
public static double[][] LEAD(Instances D, Classifier h, Random r, String MDType)  throws Exception {
	Instances D_r = new Instances(D);
	D_r.randomize(r);
	Instances D_train = new Instances(D_r,0,D_r.numInstances()*60/100);
	Instances D_test = new Instances(D_r,D_train.numInstances(),D_r.numInstances()-D_train.numInstances());
	BR br = new BR();
	br.setClassifier(h);
	Result result = Evaluation.evaluateModel((MultiLabelClassifier)br,D_train,D_test,"PCut1","1");

	return LEAD(D_test, result, MDType);
}
 
Example #24
Source File: BasicSetup.java    From meka with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Stores the parameters in an experiment.
 *
 * @return          the generated experiment
 */
@Override
protected Experiment toExperiment() {
	Experiment              result;
	MultiLabelClassifier[]  classifiers;
	File[]                  datasets;
	LocalDatasetProvider    provider;
	int                     i;
	RepeatedRuns            runs;
	CrossValidation         cv;
	PercentageSplit         split;

	result = (Experiment) ObjectUtils.deepCopy(m_Experiment);

	// classifiers
	classifiers = new MultiLabelClassifier[m_ModelClassifiers.getSize()];
	for (i = 0; i < m_ModelClassifiers.getSize(); i++) {
		try {
			classifiers[i] = OptionUtils.fromCommandLine(MultiLabelClassifier.class, m_ModelClassifiers.get(i));
		}
		catch (Exception e) {
			handleException("Failed to instantiate classifier: " + m_ModelClassifiers.get(i), e);
			classifiers[i] = new BR();
		}
	}
	result.setClassifiers(classifiers);

	// dataset provider
	datasets = new File[m_ModelDatasets.getSize()];
	for (i = 0; i < m_ModelDatasets.getSize(); i++)
		datasets[i] = new File(m_ModelDatasets.get(i));
	provider = new LocalDatasetProvider();
	provider.setDatasets(datasets);
	result.setDatasetProvider(provider);

	// evaluator
	runs = null;
	if (((Integer) m_SpinnerNumRuns.getValue()) > 1) {
		runs = new RepeatedRuns();
		runs.setLowerRuns(1);
		runs.setUpperRuns((Integer) m_SpinnerNumRuns.getValue());
	}

	cv    = null;
	split = null;
	if (m_ComboBoxEvaluation.getSelectedIndex() == 0) {
		cv = new CrossValidation();
		cv.setNumFolds((Integer) m_SpinnerNumFolds.getValue());
		cv.setPreserveOrder(m_CheckBoxPreserveOrder.isSelected());
	}
	else {
		split = new PercentageSplit();
		split.setTrainPercentage(Double.parseDouble(m_TextPercentage.getText()));
		split.setPreserveOrder(m_CheckBoxPreserveOrder.isSelected());
	}
	if (runs != null) {
		if (cv != null)
			runs.setEvaluator(cv);
		else
			runs.setEvaluator(split);
		result.setEvaluator(runs);
	}
	else {
		if (cv != null)
			result.setEvaluator(cv);
		else
			result.setEvaluator(split);
	}

	// statistics
	result.setStatisticsHandler((EvaluationStatisticsHandler) m_GOEStatisticsHandler.getValue());

	// notes
	result.setNotes(m_Notes);

	return result;
}
 
Example #25
Source File: MekaClassifier.java    From AILibs with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public MultiLabelClassifier getClassifier() {
	return this.classifier;
}
 
Example #26
Source File: BasicSetup.java    From meka with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Maps the experiment onto the parameters.
 */
@Override
protected void fromExperiment() {
	LocalDatasetProvider    provider;
	Evaluator               evaluator;
	RepeatedRuns            runs;
	CrossValidation         cv;
	PercentageSplit         split;

	// classifiers
	m_ModelClassifiers.removeAllElements();
	for (MultiLabelClassifier classifier: m_Experiment.getClassifiers())
		m_ModelClassifiers.addElement(OptionUtils.toCommandLine(classifier));

	// datasets
	provider = (LocalDatasetProvider) m_Experiment.getDatasetProvider();
	m_ModelDatasets.removeAllElements();
	for (File dataset: provider.getDatasets())
		m_ModelDatasets.addElement(dataset.getAbsolutePath());

	// evaluator
	evaluator = m_Experiment.getEvaluator();
	if (evaluator instanceof RepeatedRuns) {
		runs = (RepeatedRuns) evaluator;
		m_SpinnerNumRuns.setValue(runs.getUpperRuns() - runs.getLowerRuns() + 1);
		evaluator = ((RepeatedRuns) evaluator).getEvaluator();
	}
	if (evaluator instanceof CrossValidation) {
		cv = (CrossValidation) evaluator;
		m_SpinnerNumFolds.setValue(cv.getNumFolds());
		m_CheckBoxPreserveOrder.setSelected(cv.getPreserveOrder());
	}
	else {
		split = (PercentageSplit) evaluator;
		m_TextPercentage.setText("" + split.getTrainPercentage());
		m_CheckBoxPreserveOrder.setSelected(split.getPreserveOrder());
	}

	// statistics
	m_GOEStatisticsHandler.setValue(m_Experiment.getStatisticsHandler());

	// notes
	m_Notes = m_Experiment.getNotes();
}
 
Example #27
Source File: GenericObjectEditor.java    From meka with GNU General Public License v3.0 4 votes vote down vote up
/**
 * For testing only.
 *
 * @param args	ignored
 */
public static void main(String[] args) {
	Project.initialize();
	try {
		registerAllEditors();
		GenericObjectEditor ce = new GenericObjectEditor(true);
		ce.setClassType(MultiLabelClassifier.class);
		Object initial = new meka.classifiers.multilabel.BR();
		if (args.length > 0){
			ce.setClassType(Class.forName(args[0]));
			if (args.length > 1) {
				initial = Class.forName(args[1]).newInstance();
				ce.setValue(initial);
			}
			else {
				ce.setDefaultValue();
			}
		}
		else {
			ce.setValue(initial);
		}

		PropertyDialog pd = new PropertyDialog((Frame) null, ce, 100, 100);
		pd.addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosing(WindowEvent e) {
				PropertyEditor pe = ((PropertyDialog)e.getSource()).getEditor();
				Object c = pe.getValue();
				String options = "";
				if (c instanceof OptionHandler)
					options = Utils.joinOptions(((OptionHandler)c).getOptions());
				System.out.println(c.getClass().getName() + " " + options);
				System.exit(0);
			}
		});
		pd.setVisible(true);
	}
	catch (Exception ex) {
		ex.printStackTrace();
		System.err.println(ex.getMessage());
	}
}
 
Example #28
Source File: WekaFilter.java    From meka with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Converts the Instances back into statistics.
 *
 * @param data          the data to convert
 * @return              the generated statistics
 */
protected List<EvaluationStatistics> fromInstances(Instances data) {
	List<EvaluationStatistics>      result;
	EvaluationStatistics            stat;
	MultiLabelClassifier            cls;
	String                          rel;
	int                             i;
	int                             n;
	Instance                        inst;

	result = new ArrayList<>();

	if (data.attribute(EvaluationStatistics.KEY_CLASSIFIER) == null) {
		log("Failed to locate attribute: " + EvaluationStatistics.KEY_CLASSIFIER);
		return result;
	}
	if (data.attribute(EvaluationStatistics.KEY_RELATION) == null) {
		log("Failed to locate attribute: " + EvaluationStatistics.KEY_RELATION);
		return result;
	}

	for (i = 0; i < data.numInstances(); i++) {
		inst = data.instance(i);
		try {
			cls = OptionUtils.fromCommandLine(MultiLabelClassifier.class, inst.stringValue(data.attribute(EvaluationStatistics.KEY_CLASSIFIER)));
			rel = inst.stringValue(data.attribute(EvaluationStatistics.KEY_RELATION));
			stat = new EvaluationStatistics(cls, rel, null);
			for (n = 0; n < inst.numAttributes(); n++) {
				if (inst.attribute(n).isNumeric() && !inst.isMissing(n)) {
					stat.put(inst.attribute(n).name(), inst.value(n));
				}
			}
			result.add(stat);
		}
		catch (Exception e) {
			handleException("Failed to process instance: " + inst, e);
		}
	}

	return result;
}
 
Example #29
Source File: IncrementalEvaluation.java    From meka with GNU General Public License v3.0 4 votes vote down vote up
/**
 * EvaluateModel - over 20 windows.
 */
public static Result evaluateModel(MultiLabelClassifier h, Instances D) throws Exception {
	return evaluateModelPrequentialBasic(h,D,20,1.0,"PCut1","3");
}
 
Example #30
Source File: MekaClassifier.java    From AILibs with GNU Affero General Public License v3.0 4 votes vote down vote up
public MekaClassifier(final MultiLabelClassifier classifier) {
	this.reconstructionPlan = new ReconstructionPlan();
	this.classifier = classifier;
	this.id = ID_COUNTER.getAndIncrement();
}