Java Code Examples for weka.core.Instances#setClass()

The following examples show how to use weka.core.Instances#setClass() . 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: Predictor.java    From browserprint with MIT License 5 votes vote down vote up
public static String browserClassify(double classifyMeArray[]) throws Exception{
	Instance classifyMe = new DenseInstance(1.0, classifyMeArray);
	Instances classifyMeDataSet = new Instances("testingDataset", browserAttributes, 0);
	classifyMeDataSet.setClass(browserClassAttribute);
	classifyMe.setDataset(classifyMeDataSet);
	classifyMe.setClassMissing();
	
	double prediction = browserClassifier.classifyInstance(classifyMe);
	return browserClassAttribute.value((int)Math.ceil(prediction));
}
 
Example 2
Source File: Predictor.java    From browserprint with MIT License 5 votes vote down vote up
public static String osClassify(double classifyMeArray[]) throws Exception{
	Instance classifyMe = new DenseInstance(1.0, classifyMeArray);
	Instances classifyMeDataSet = new Instances("testingDataset", osAttributes, 0);
	classifyMeDataSet.setClass(osClassAttribute);
	classifyMe.setDataset(classifyMeDataSet);
	classifyMe.setClassMissing();
	
	double prediction = osClassifier.classifyInstance(classifyMe);
	return osClassAttribute.value((int)Math.ceil(prediction));
}
 
Example 3
Source File: NutchOnlineClassifier.java    From anthelion with Apache License 2.0 5 votes vote down vote up
/**
 * Internal function which initialized the {@link Instances} used by the
 * {@link Classifier} wrapped by the {@link AnthOnlineClassifier} class.
 */
private void initInstances() {
	// gather attributes
	ArrayList<Attribute> attributes = new ArrayList<Attribute>();
	ArrayList<String> allowedClasses = new ArrayList<String>();
	allowedClasses.add("sem");
	allowedClasses.add("nonsem");
	Attribute classAttribute = new Attribute("class", allowedClasses);
	attributes.add(classAttribute);
	// this looks somehow stupid to me :/
	List<String> vector = null;
	attributes.add(new Attribute("domain", vector));
	attributes.add(new Attribute("sempar"));
	attributes.add(new Attribute("nonsempar"));
	attributes.add(new Attribute("semsib"));
	attributes.add(new Attribute("nonsemsib"));
	for (int i = 0; i < hashTrickSize; i++) {
		// the boolAttValues here should not be necessary but based on some
		// runtime experiements they make a (slight) difference as it is not
		// possible to create directly boolean attributes. The time to
		// define a split is reduced by doing this with nominal.
		attributes.add(new Attribute(getAttributeNameOfHash(i), boolAttValues));
	}
	// now we create the Instances
	instances = new Instances("Anthelion", attributes, 1);
	instances.setClass(classAttribute);
	attributesIndex = new HashMap<String, Integer>();
	for (int i = 0; i < attributes.size(); i++) {
		attributesIndex.put(attributes.get(i).name(), i);
	}
	// set dimension (class + domain + 4xgraph + hashes)
	dimension = 1 + 1 + 4 + hashTrickSize;
	// init replacement array
	replaceMissingValues = new double[dimension];
	for (int i = 0; i < dimension; i++) {
		replaceMissingValues[i] = 0.0;
	}
}
 
Example 4
Source File: NutchOnlineClassifier.java    From anthelion with Apache License 2.0 5 votes vote down vote up
/**
 * Internal function which initialized the {@link Instances} used by the
 * {@link Classifier} wrapped by the {@link AnthOnlineClassifier} class.
 */
private void initInstances() {
	// gather attributes
	ArrayList<Attribute> attributes = new ArrayList<Attribute>();
	ArrayList<String> allowedClasses = new ArrayList<String>();
	allowedClasses.add("sem");
	allowedClasses.add("nonsem");
	Attribute classAttribute = new Attribute("class", allowedClasses);
	attributes.add(classAttribute);
	// this looks somehow stupid to me :/
	List<String> vector = null;
	attributes.add(new Attribute("domain", vector));
	attributes.add(new Attribute("sempar"));
	attributes.add(new Attribute("nonsempar"));
	attributes.add(new Attribute("semsib"));
	attributes.add(new Attribute("nonsemsib"));
	for (int i = 0; i < hashTrickSize; i++) {
		// the boolAttValues here should not be necessary but based on some
		// runtime experiements they make a (slight) difference as it is not
		// possible to create directly boolean attributes. The time to
		// define a split is reduced by doing this with nominal.
		attributes.add(new Attribute(getAttributeNameOfHash(i), boolAttValues));
	}
	// now we create the Instances
	instances = new Instances("Anthelion", attributes, 1);
	instances.setClass(classAttribute);
	attributesIndex = new HashMap<String, Integer>();
	for (int i = 0; i < attributes.size(); i++) {
		attributesIndex.put(attributes.get(i).name(), i);
	}
	// set dimension (class + domain + 4xgraph + hashes)
	dimension = 1 + 1 + 4 + hashTrickSize;
	// init replacement array
	replaceMissingValues = new double[dimension];
	for (int i = 0; i < dimension; i++) {
		replaceMissingValues[i] = 0.0;
	}
}
 
Example 5
Source File: ReduceDimensionFilter.java    From anthelion with Apache License 2.0 5 votes vote down vote up
/**
 * Called by {@link ReduceDimensionFilter#restartImpl()}
 */
private void init() {
	if (this.inputStream == null) {
		System.out.println("Could not find input stream.");
		System.exit(0);
	}
	InstancesHeader oldHeader = this.inputStream.getHeader();
	ArrayList<Attribute> attributes = new ArrayList<Attribute>();
	// the class
	Attribute classAttribute = oldHeader.classAttribute();
	attributes.add(classAttribute);
	// the unchanged attributes
	for (int i = 0; i < notHashableAttributes.size(); i++) {
		attributes
				.add(1, oldHeader.attribute(notHashableAttributes.get(i)));
	}
	// our new elements
	if (hashSize == 0) {
		System.out.println("Max attribute number is 0.");
		System.exit(0);
	}
	for (int i = 0; i < hashSize; i++) {
		attributes.add(notHashableAttributes.size() + 1, new Attribute(
				getAttributeNameOfHash(i), boolAttValues));
	}
	newInstances = new Instances("reduced", attributes, 1);
	newInstances.setClass(classAttribute);
	attributesIndex = new HashMap<String, Integer>();
	for (int i = 0; i < attributes.size(); i++) {
		attributesIndex.put(attributes.get(i).name(), i);
	}
	replacementArray = new double[hashSize + notHashableAttributes.size()];
	for (int i = 0; i < hashSize + notHashableAttributes.size(); i++) {
		replacementArray[i] = 0.0;
	}

}
 
Example 6
Source File: AnthOnlineClassifier.java    From anthelion with Apache License 2.0 5 votes vote down vote up
/**
 * Internal function which initialized the {@link Instances} used by the
 * {@link Classifier} wrapped by the {@link AnthOnlineClassifier} class.
 */
private void initInstances() {
	// gather attributes
	ArrayList<Attribute> attributes = new ArrayList<Attribute>();
	ArrayList<String> allowedClasses = new ArrayList<String>();
	allowedClasses.add("sem");
	allowedClasses.add("nonsem");
	Attribute classAttribute = new Attribute("class", allowedClasses);
	attributes.add(classAttribute);
	// this looks somehow stupid to me :/
	List<String> vector = null;
	attributes.add(new Attribute("domain", vector));
	attributes.add(new Attribute("sempar"));
	attributes.add(new Attribute("nonsempar"));
	attributes.add(new Attribute("semsib"));
	attributes.add(new Attribute("nonsemsib"));
	for (int i = 0; i < hashTrickSize; i++) {
		// the boolAttValues here should not be necessary but based on some
		// runtime experiements they make a (slight) difference as it is not
		// possible to create directly boolean attributes. The time to
		// define a split is reduced by doing this with nominal.
		attributes.add(new Attribute(getAttributeNameOfHash(i),
				boolAttValues));
	}
	// now we create the Instances
	instances = new Instances("Anthelion", attributes, 1);
	instances.setClass(classAttribute);
	attributesIndex = new HashMap<String, Integer>();
	for (int i = 0; i < attributes.size(); i++) {
		attributesIndex.put(attributes.get(i).name(), i);
	}
	// set dimension (class + domain + 4xgraph + hashes)
	dimension = 1 + 1 + 4 + hashTrickSize;
	// init replacement array
	replaceMissingValues = new double[dimension];
	for (int i = 0; i < dimension; i++) {
		replaceMissingValues[i] = 0.0;
	}
}