本文整理汇总了Java中weka.core.Attribute类的典型用法代码示例。如果您正苦于以下问题:Java Attribute类的具体用法?Java Attribute怎么用?Java Attribute使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Attribute类属于weka.core包,在下文中一共展示了Attribute类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: instanceToDenseDMatrix
import weka.core.Attribute; //导入依赖的package包/类
public static DMatrix instanceToDenseDMatrix(Instance instance) throws XGBoostError {
Attribute classAttribute = instance.classAttribute();
int classAttrIndex = classAttribute.index();
int colNum = instance.numAttributes()-1;
int rowNum = 1;
float[] data = new float[colNum*rowNum];
Enumeration<Attribute> attributeEnumeration = instance.enumerateAttributes();
int dataIndex = 0;
while (attributeEnumeration.hasMoreElements()) {
Attribute attribute = attributeEnumeration.nextElement();
int attrIndex = attribute.index();
if(attrIndex == classAttrIndex){
continue;
}
data[dataIndex]= (float) instance.value(attribute);
dataIndex++;
}
return new DMatrix(data, rowNum, colNum);
}
示例2: isClassTheMajortiy
import weka.core.Attribute; //导入依赖的package包/类
private boolean isClassTheMajortiy(ArrayList<Instance> instances, double classification){
List<Instance> instancesList = new ArrayList<>(instances);
TreeMap<Double, Double> classificationProbability = new TreeMap<>();
Attribute classAttribute = instances.get(0).classAttribute();
for (double i = 0; i < classAttribute.numValues(); i++) {
int matchedClassCount = 0;
for (Instance instance : instancesList) {
if(instance.classValue() == i){
matchedClassCount++;
}
}
classificationProbability.put(((double) matchedClassCount / (double) instancesList.size()), i);
}
return (classificationProbability.lastEntry().getValue() == classification);
}
示例3: main
import weka.core.Attribute; //导入依赖的package包/类
public static void main(String[] args){
ArrayList<Attribute> atts = new ArrayList<Attribute>();
/*Properties p1 = new Properties();
p1.setProperty("range", "[0,1]");
ProtectedProperties prop1 = new ProtectedProperties(p1);*/
Properties p2 = new Properties();
p2.setProperty("range", "[321,1E9]");
ProtectedProperties prop2 = new ProtectedProperties(p2);
ArrayList<String> attVals = new ArrayList<String>();
for (int i = 0; i < 5; i++)
attVals.add("val" + (i+1));
//atts.add(new Attribute("att1", prop1));
atts.add(new Attribute("att2", prop2));
//atts.add(new Attribute("att3", attVals));
//Instances data = LHSInitializer.getMultiDimContinuous(atts, 10, false);
//Instances data = LHSInitializer.getMultiDim(atts, 10, false);
Instances data = LHSInitializer.getMultiDimContinuous(atts, 1, false);
System.out.println(data);
}
示例4: createDataSet
import weka.core.Attribute; //导入依赖的package包/类
private Instances createDataSet(List<ConceptSimilarityMeasure> sims) {
ArrayList<Attribute> atts = new ArrayList<Attribute>();
for (ConceptSimilarityMeasure sim : sims)
atts.add(new Attribute(sim.getName()));
List<String> classes = new ArrayList<String>();
classes.add("no merge");
classes.add("merge");
atts.add(new Attribute("class", classes));
Instances data = new Instances("data", atts, 0);
data.setClassIndex(data.numAttributes() - 1);
return data;
}
示例5: ModelClassifier
import weka.core.Attribute; //导入依赖的package包/类
public ModelClassifier() {
name = new Attribute("name");
type = new Attribute("type");
attributes = new ArrayList();
classVal = new ArrayList();
classVal.add("Monday");
classVal.add("Tuesday");
classVal.add("Wednesday");
classVal.add("Thursday");
classVal.add("Friday");
classVal.add("Saturday");
classVal.add("Sunday");
attributes.add(name);
attributes.add(type);
attributes.add(new Attribute("class", classVal));
dataRaw = new Instances("TestInstances", attributes, 0);
dataRaw.setClassIndex(dataRaw.numAttributes() - 1);
}
示例6: main
import weka.core.Attribute; //导入依赖的package包/类
public static void main(String[] args){
ArrayList<Attribute> atts = new ArrayList<Attribute>();
/*Properties p1 = new Properties();
p1.setProperty("range", "[0,1]");
ProtectedProperties prop1 = new ProtectedProperties(p1);*/
Properties p2 = new Properties();
p2.setProperty("range", "[321,1E9]");
ProtectedProperties prop2 = new ProtectedProperties(p2);
ArrayList<String> attVals = new ArrayList<String>();
for (int i = 0; i < 5; i++)
attVals.add("val" + (i+1));
//atts.add(new Attribute("att1", prop1));
atts.add(new Attribute("att2", prop2));
//atts.add(new Attribute("att3", attVals));
//Instances data = LHSInitializer.getMultiDimContinuous(atts, 10, false);
//Instances data = LHSInitializer.getMultiDim(atts, 10, false);
LHSSampler sampler = new LHSSampler();
Instances data = sampler.sampleMultiDimContinuous(atts, 1, false);
System.out.println(data);
}
示例7: relationToInstances
import weka.core.Attribute; //导入依赖的package包/类
/**
* Create an Instances object from the tuples provided. The Instances has
* name `name` and every value from every tuple. The TupleDesc is provided
* separately just to validate that all of the provided Tuples share this
* TupleDesc.
* @param name the name of the resulting Instances object
* @param ts list of Tuples
* @param td TupleDesc
* @param fields indices identifying which fields should be included in the new Instances object.
* @return new Instances object containing the values from all the tuples.
*/
public static Instances relationToInstances(String name, List<Tuple> ts, TupleDesc td,
List<Integer> fields){
ArrayList<Attribute> attrs = tupleDescToAttributeList(td, fields);
int relationSize = ts.size();
Instances instances = new Instances(name, attrs, relationSize);
for (int i=0; i<ts.size(); i++){
Tuple t = ts.get(i);
if (!t.getTupleDesc().equals(td)){
throw new RuntimeException("All TupleDescs must match.");
}
instances.add(i, tupleToInstance(t, attrs, fields));
}
return instances;
}
示例8: setOptimal
import weka.core.Attribute; //导入依赖的package包/类
/**
* set the bestConf to cluster and get the running performance
* @param attributeToVal
* @return
*/
public double setOptimal(Map<Attribute,Double> attributeToVal){
HashMap hm = new HashMap();
for(Attribute key : attributeToVal.keySet()){
Double value = attributeToVal.get(key);
hm.put(key.name(), value);
}
this.startTest(hm, 0, false);
double y = 0;
y = performance;
return y;
}
示例9: prefix2attributes
import weka.core.Attribute; //导入依赖的package包/类
/**
* Helper method to convet Feature keys to Attributes
* @param data
* @param prefixes
* @return
*/
public static Set<Attribute> prefix2attributes(Instances data, String...prefixes) {
Set<Attribute> attributes = new ListOrderedSet<Attribute>();
for (String key : prefixes) {
Attribute attribute = data.attribute(key);
assert(attribute != null) : "Invalid Attribute key '" + key + "'";
attributes.add(attribute);
} // FOR
return (attributes);
}
示例10: convertToArff
import weka.core.Attribute; //导入依赖的package包/类
public static Instances convertToArff(List<Document> dataSet, List<String> vocabulary, String fileName) {
int dataSetSize = dataSet.size();
/* Create features */
ArrayList<Attribute> attributes = new ArrayList<>();
for (int i = 0; i < vocabulary.size(); i++) {
attributes.add(new Attribute("word_" + i));
}
Attribute classAttribute = new Attribute("Class");
attributes.add(classAttribute);
/* Add examples */
System.out.println("Building instances...");
Instances trainingDataSet = new Instances(fileName, attributes, 0);
for (int k = 0; k < dataSetSize; k++) {
Document document = dataSet.get(k);
Instance example = new DenseInstance(attributes.size());
for (int i = 0; i < vocabulary.size(); i++) {
String word = vocabulary.get(i);
example.setValue(i, Collections.frequency(document.getTerms(), word));
}
example.setValue(classAttribute, document.getDocumentClass());
trainingDataSet.add(example);
int progress = (int) ((k * 100.0) / dataSetSize);
System.out.printf("\rPercent completed: %3d%%", progress);
}
trainingDataSet.setClass(classAttribute);
System.out.println();
System.out.println("Writing to file ...");
try {
ArffSaver saver = new ArffSaver();
saver.setInstances(trainingDataSet);
saver.setFile(new File(fileName));
saver.writeBatch();
} catch (IOException e) {
e.printStackTrace();
}
return trainingDataSet;
}
示例11: uniBoundsGeneration
import weka.core.Attribute; //导入依赖的package包/类
private static void uniBoundsGeneration(double[] bounds, Attribute crntAttr, int sampleSetSize){
bounds[0] = crntAttr.getLowerNumericBound();
bounds[sampleSetSize] = crntAttr.getUpperNumericBound();
double pace = (bounds[sampleSetSize] - bounds[0])/sampleSetSize;
for(int j=1;j<sampleSetSize;j++){
bounds[j] = bounds[j-1] + pace;
}
}
示例12: Term
import weka.core.Attribute; //导入依赖的package包/类
/**
* Constructor for numeric attribute, each numeric attribute is
* represented by a term in form of x <= value < y
*
* @param attributeIn
* @param attributeIndexIn
*/
public Term(Attribute attributeIn, double attributeIndexIn){
attribute = attributeIn;
setAttributeIndex(attributeIndexIn);
// set type of the attribute
if(attributeIn.isNumeric()){
attributeType = TypeNumeric;
}else{
attributeType = 0;
}
}
示例13: tupleDescToAttributeList
import weka.core.Attribute; //导入依赖的package包/类
/**
* Create a list of Weka Attributes from a TupleDesc. The resulting list is
* suitable to pass to an Instances object.
* @param td the TupleDesc
* @return the list of Attributes
*/
public static ArrayList<Attribute> tupleDescToAttributeList(TupleDesc td){
List<Integer> fields = new ArrayList<>();
for (int i=0; i<td.numFields(); i++){
fields.add(i);
}
return tupleDescToAttributeList(td, fields);
}
示例14: main
import weka.core.Attribute; //导入依赖的package包/类
public static void main(String[] args){
ArrayList<Attribute> atts = new ArrayList<Attribute>();
Properties p1 = new Properties();
p1.setProperty("range", "[0,1]");
ProtectedProperties prop1 = new ProtectedProperties(p1);
Properties p2 = new Properties();
p2.setProperty("range", "[321,1E9]");
ProtectedProperties prop2 = new ProtectedProperties(p2);
Properties p3 = new Properties();
p3.setProperty("range", "[1,30]");
ProtectedProperties prop3 = new ProtectedProperties(p3);
ArrayList<String> attVals = new ArrayList<String>();
for (int i = 0; i < 5; i++)
attVals.add("val" + (i+1));
atts.add(new Attribute("att1", prop1));
atts.add(new Attribute("att2", prop2));
atts.add(new Attribute("att3", prop3));
//atts.add(new Attribute("att4", attVals));
//Instances data = LHSInitializer.getMultiDimContinuous(atts, 10, false);
//Instances data = LHSInitializer.getMultiDim(atts, 10, false);
DDSSampler sampler = new DDSSampler(3);
sampler.setCurrentRound(0);
Instances data = sampler.sampleMultiDimContinuous(atts, 2, false);
System.out.println(data);
sampler.setCurrentRound(01);
data = sampler.sampleMultiDimContinuous(atts, 2, false);
System.out.println(data);
sampler.setCurrentRound(2);
data = sampler.sampleMultiDimContinuous(atts, 2, false);
System.out.println(data);
}
示例15: getNominalAttribute
import weka.core.Attribute; //导入依赖的package包/类
private Attribute getNominalAttribute(Fields field) {
Set<String> values = new HashSet<>();
for(Object obj: dataDomain.get(field.name()))
values.add(Conversion.getValueAsStr(obj));
return new Attribute(field.name(), new ArrayList<>(values));
}