本文整理了Java中weka.core.Instances.enumerateAttributes()
方法的一些代码示例,展示了Instances.enumerateAttributes()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Instances.enumerateAttributes()
方法的具体详情如下:
包路径:weka.core.Instances
类名称:Instances
方法名:enumerateAttributes
[英]Returns an enumeration of all the attributes. The class attribute (if set) is skipped by this enumeration.
[中]返回所有属性的枚举。此枚举将跳过类属性(如果已设置)。
代码示例来源:origin: com.googlecode.obvious/obviousx-weka
@SuppressWarnings("unchecked")
@Override
public Enumeration enumerateAttributes() {
return super.enumerateAttributes();
}
代码示例来源:origin: com.googlecode.obvious/obviousx-weka
@Override
public Enumeration enumerateAttributes() {
return dataset().enumerateAttributes();
}
代码示例来源:origin: Waikato/weka-trunk
/**
* Returns an enumeration of all the attributes.
*
* @return enumeration of all the attributes
* @throws UnassignedDatasetException if the instance doesn't have access to a
* dataset
*/
// @ requires m_Dataset != null;
@Override
public/* @pure@ */Enumeration<Attribute> enumerateAttributes() {
if (m_Dataset == null) {
throw new UnassignedDatasetException(
"Instance doesn't have access to a dataset!");
}
return m_Dataset.enumerateAttributes();
}
代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable
/**
* Returns an enumeration of all the attributes.
*
* @return enumeration of all the attributes
* @throws UnassignedDatasetException if the instance doesn't have access to a
* dataset
*/
// @ requires m_Dataset != null;
@Override
public/* @pure@ */Enumeration<Attribute> enumerateAttributes() {
if (m_Dataset == null) {
throw new UnassignedDatasetException(
"Instance doesn't have access to a dataset!");
}
return m_Dataset.enumerateAttributes();
}
代码示例来源:origin: de.tudarmstadt.ukp.dkpro.tc/de.tudarmstadt.ukp.dkpro.tc.weka-gpl
/**
* @return The offset of the instanceId attribute within the weka instance
*/
@SuppressWarnings("unchecked")
public static int getInstanceIdAttributeOffset(Instances data)
{
int attOffset = 1;
Enumeration<Attribute> enumeration = data.enumerateAttributes();
while (enumeration.hasMoreElements()) {
Attribute att = enumeration.nextElement();
// System.out.println(att.name());
if (att.name().equals(AddIdFeatureExtractor.ID_FEATURE_NAME)) {
return attOffset;
}
attOffset++;
}
return -1;
}
代码示例来源:origin: sc.fiji/Trainable_Segmentation
/**
* Check if a set of Weka instances has 3D image attributes
* (given by the presence of the attribute names from FeatureStack3D
* which are not present in FeatureStack).
* @param data set of Weka instances
* @return true if the set contains exclusive 3D attributes, false otherwise
*/
public boolean containsExclusive3DFeatures( Instances data )
{
// make list of exclusive 3D feature names
final ArrayList<String> names3D = new ArrayList<String>();
for( int i=0; i<FeatureStack3D.availableFeatures.length; i++ )
names3D.add( FeatureStack3D.availableFeatures[ i ] );
for( int i=0; i<FeatureStack.availableFeatures.length; i++ )
{
if( names3D.contains( FeatureStack.availableFeatures[ i ] ) )
names3D.remove( FeatureStack.availableFeatures[ i ] );
}
Enumeration<Attribute> attributes = data.enumerateAttributes();
while(attributes.hasMoreElements())
{
final Attribute a = attributes.nextElement();
for( String s : names3D )
if( a.name().startsWith( s ) )
return true;
}
return false;
}
/**
代码示例来源:origin: fiji/Trainable_Segmentation
/**
* Check if a set of Weka instances has 2D image attributes
* (given by the presence of the attribute names from FeatureStack
* which are not present in FeatureStack3D).
* @param data set of Weka instances
* @return true if the set contains exclusive 2D attributes, false otherwise
*/
public boolean containsExclusive2DFeatures( Instances data )
{
// make list of exclusive 2D feature names
final ArrayList<String> names2D = new ArrayList<String>();
for( int i=0; i<FeatureStack.availableFeatures.length; i++ )
names2D.add( FeatureStack.availableFeatures[ i ] );
for( int i=0; i<FeatureStack3D.availableFeatures.length; i++ )
{
if( names2D.contains( FeatureStack3D.availableFeatures[ i ] ) )
names2D.remove( FeatureStack3D.availableFeatures[ i ] );
}
Enumeration<Attribute> attributes = data.enumerateAttributes();
while(attributes.hasMoreElements())
{
final Attribute a = attributes.nextElement();
for( String s : names2D )
if( a.name().startsWith( s ) )
return true;
}
return false;
}
/**
代码示例来源:origin: sc.fiji/Trainable_Segmentation
/**
* Check if a set of Weka instances has 2D image attributes
* (given by the presence of the attribute names from FeatureStack
* which are not present in FeatureStack3D).
* @param data set of Weka instances
* @return true if the set contains exclusive 2D attributes, false otherwise
*/
public boolean containsExclusive2DFeatures( Instances data )
{
// make list of exclusive 2D feature names
final ArrayList<String> names2D = new ArrayList<String>();
for( int i=0; i<FeatureStack.availableFeatures.length; i++ )
names2D.add( FeatureStack.availableFeatures[ i ] );
for( int i=0; i<FeatureStack3D.availableFeatures.length; i++ )
{
if( names2D.contains( FeatureStack3D.availableFeatures[ i ] ) )
names2D.remove( FeatureStack3D.availableFeatures[ i ] );
}
Enumeration<Attribute> attributes = data.enumerateAttributes();
while(attributes.hasMoreElements())
{
final Attribute a = attributes.nextElement();
for( String s : names2D )
if( a.name().startsWith( s ) )
return true;
}
return false;
}
/**
代码示例来源:origin: fiji/Trainable_Segmentation
/**
* Check if a set of Weka instances has 3D image attributes
* (given by the presence of the attribute names from FeatureStack3D
* which are not present in FeatureStack).
* @param data set of Weka instances
* @return true if the set contains exclusive 3D attributes, false otherwise
*/
public boolean containsExclusive3DFeatures( Instances data )
{
// make list of exclusive 3D feature names
final ArrayList<String> names3D = new ArrayList<String>();
for( int i=0; i<FeatureStack3D.availableFeatures.length; i++ )
names3D.add( FeatureStack3D.availableFeatures[ i ] );
for( int i=0; i<FeatureStack.availableFeatures.length; i++ )
{
if( names3D.contains( FeatureStack.availableFeatures[ i ] ) )
names3D.remove( FeatureStack.availableFeatures[ i ] );
}
Enumeration<Attribute> attributes = data.enumerateAttributes();
while(attributes.hasMoreElements())
{
final Attribute a = attributes.nextElement();
for( String s : names3D )
if( a.name().startsWith( s ) )
return true;
}
return false;
}
/**
代码示例来源:origin: amidst/toolbox
/**
* Creates a set of {@link Attributes} from a given {@link weka.core.Instances} object.
* @param modelContext a {@link weka.core.Instances} object.
* @return a set of {@link Attributes}.
*/
public static Attributes convertAttributes(Instances modelContext){
Enumeration attributesWeka = modelContext.enumerateAttributes();
return convertAttributes(attributesWeka, modelContext.classAttribute());
}
代码示例来源:origin: sc.fiji/Trainable_Segmentation
/**
* Check if a set of Weka instances has color attributes
* (given by the presence of the attribute names "Hue",
* "Saturation" or "Brightness").
* @param data set of Weka instances
* @return true if the set contains color attributes, false otherwise
*/
public boolean containsColorFeatures( Instances data )
{
Enumeration<Attribute> attributes = data.enumerateAttributes();
while(attributes.hasMoreElements())
{
final Attribute a = attributes.nextElement();
if( a.name().equals( "Hue" ) ||
a.name().equals( "Saturation" ) ||
a.name().equals( "Brightness" ) )
return true;
}
return false;
}
/**
代码示例来源:origin: fiji/Trainable_Segmentation
/**
* Check if a set of Weka instances has color attributes
* (given by the presence of the attribute names "Hue",
* "Saturation" or "Brightness").
* @param data set of Weka instances
* @return true if the set contains color attributes, false otherwise
*/
public boolean containsColorFeatures( Instances data )
{
Enumeration<Attribute> attributes = data.enumerateAttributes();
while(attributes.hasMoreElements())
{
final Attribute a = attributes.nextElement();
if( a.name().equals( "Hue" ) ||
a.name().equals( "Saturation" ) ||
a.name().equals( "Brightness" ) )
return true;
}
return false;
}
/**
代码示例来源:origin: com.googlecode.obvious/obviousx-weka
/**
* Constructor.
* @param inst a Weka Instances instance
*/
@SuppressWarnings("unchecked")
public WekaObviousTable(Instances inst) {
this.instances = inst;
this.schema = new SchemaImpl();
Enumeration attributes = instances.enumerateAttributes();
while (attributes.hasMoreElements()) {
Attribute att = (Attribute) attributes.nextElement();
Class<?> c = checkClass(att);
schema.addColumn(att.name(), c, null);
}
}
代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable
/**
* Compute the number of all possible conditions that could appear in a rule
* of a given data. For nominal attributes, it's the number of values that
* could appear; for numeric attributes, it's the number of values * 2, i.e.
* <= and >= are counted as different possible conditions.
*
* @param data the given data
* @return number of all conditions of the data
*/
public static double numAllConditions(Instances data) {
double total = 0;
Enumeration<Attribute> attEnum = data.enumerateAttributes();
while (attEnum.hasMoreElements()) {
Attribute att = attEnum.nextElement();
if (att.isNominal()) {
total += att.numValues();
} else {
total += 2.0 * data.numDistinctValues(att);
}
}
return total;
}
代码示例来源:origin: Waikato/weka-trunk
/**
* Compute the number of all possible conditions that could appear in a rule
* of a given data. For nominal attributes, it's the number of values that
* could appear; for numeric attributes, it's the number of values * 2, i.e.
* <= and >= are counted as different possible conditions.
*
* @param data the given data
* @return number of all conditions of the data
*/
public static double numAllConditions(Instances data) {
double total = 0;
Enumeration<Attribute> attEnum = data.enumerateAttributes();
while (attEnum.hasMoreElements()) {
Attribute att = attEnum.nextElement();
if (att.isNominal()) {
total += att.numValues();
} else {
total += 2.0 * data.numDistinctValues(att);
}
}
return total;
}
代码示例来源:origin: Waikato/weka-trunk
/**
* Updates the classifier with the given instance.
*
* @param instance the new training instance to include in the model
* @exception Exception if the instance could not be incorporated in the
* model.
*/
public void updateClassifier(Instance instance) throws Exception {
if (!instance.classIsMissing()) {
Enumeration<Attribute> enumAtts = m_Instances.enumerateAttributes();
int attIndex = 0;
while (enumAtts.hasMoreElements()) {
Attribute attribute = enumAtts.nextElement();
if (!instance.isMissing(attribute)) {
m_Distributions[attIndex][(int) instance.classValue()].addValue(
instance.value(attribute), instance.weight());
}
attIndex++;
}
m_ClassDistribution.addValue(instance.classValue(), instance.weight());
}
}
代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable
/**
* Updates the classifier with the given instance.
*
* @param instance the new training instance to include in the model
* @exception Exception if the instance could not be incorporated in the
* model.
*/
public void updateClassifier(Instance instance) throws Exception {
if (!instance.classIsMissing()) {
Enumeration<Attribute> enumAtts = m_Instances.enumerateAttributes();
int attIndex = 0;
while (enumAtts.hasMoreElements()) {
Attribute attribute = enumAtts.nextElement();
if (!instance.isMissing(attribute)) {
m_Distributions[attIndex][(int) instance.classValue()].addValue(
instance.value(attribute), instance.weight());
}
attIndex++;
}
m_ClassDistribution.addValue(instance.classValue(), instance.weight());
}
}
代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable
/**
* ensure that all variables are nominal and that there are no missing values
*
* @param instances data set to check and quantize and/or fill in missing
* values
* @return filtered instances
* @throws Exception if a filter (Discretize, ReplaceMissingValues) fails
*/
protected Instances normalizeDataSet(Instances instances) throws Exception {
m_nNonDiscreteAttribute = -1;
Enumeration<Attribute> enu = instances.enumerateAttributes();
while (enu.hasMoreElements()) {
Attribute attribute = enu.nextElement();
if (attribute.type() != Attribute.NOMINAL) {
m_nNonDiscreteAttribute = attribute.index();
}
}
if ((m_nNonDiscreteAttribute > -1)
&& (instances.attribute(m_nNonDiscreteAttribute).type() != Attribute.NOMINAL)) {
m_DiscretizeFilter = new Discretize();
m_DiscretizeFilter.setInputFormat(instances);
instances = Filter.useFilter(instances, m_DiscretizeFilter);
}
m_MissingValuesFilter = new ReplaceMissingValues();
m_MissingValuesFilter.setInputFormat(instances);
instances = Filter.useFilter(instances, m_MissingValuesFilter);
return instances;
} // normalizeDataSet
代码示例来源:origin: Waikato/weka-trunk
/**
* ensure that all variables are nominal and that there are no missing values
*
* @param instances data set to check and quantize and/or fill in missing
* values
* @return filtered instances
* @throws Exception if a filter (Discretize, ReplaceMissingValues) fails
*/
protected Instances normalizeDataSet(Instances instances) throws Exception {
m_nNonDiscreteAttribute = -1;
Enumeration<Attribute> enu = instances.enumerateAttributes();
while (enu.hasMoreElements()) {
Attribute attribute = enu.nextElement();
if (attribute.type() != Attribute.NOMINAL) {
m_nNonDiscreteAttribute = attribute.index();
}
}
if ((m_nNonDiscreteAttribute > -1)
&& (instances.attribute(m_nNonDiscreteAttribute).type() != Attribute.NOMINAL)) {
m_DiscretizeFilter = new Discretize();
m_DiscretizeFilter.setInputFormat(instances);
instances = Filter.useFilter(instances, m_DiscretizeFilter);
}
m_MissingValuesFilter = new ReplaceMissingValues();
m_MissingValuesFilter.setInputFormat(instances);
instances = Filter.useFilter(instances, m_MissingValuesFilter);
return instances;
} // normalizeDataSet
代码示例来源:origin: amidst/toolbox
@Override
public void buildClusterer(Instances data) throws Exception {
attributes_ = Converter.convertAttributes(data.enumerateAttributes());
Variables modelHeader = new Variables(attributes_);
clusterVar_ = modelHeader.newMultinomialVariable("clusterVar", this.numberOfClusters());
inferenceAlgorithm_ = new ImportanceSampling();
inferenceAlgorithm_.setSeed(this.getSeed());
dag = new DAG(modelHeader);
/* Set DAG structure. */
/* Add the hidden cluster variable as a parent of all the predictive attributes. */
dag.getParentSets().stream()
.filter(w -> w.getMainVar().getVarID() != clusterVar_.getVarID())
.filter(w -> w.getMainVar().isObservable())
.forEach(w -> w.addParent(clusterVar_));
System.out.println(dag.toString());
parameterLearningAlgorithm_ = new SVB();
parameterLearningAlgorithm_.setDAG(dag);
DataOnMemoryListContainer<DataInstance> batch_ = new DataOnMemoryListContainer(attributes_);
data.stream().forEach(instance ->
batch_.add(new DataInstanceFromDataRow(new DataRowWeka(instance, this.attributes_)))
);
parameterLearningAlgorithm_.setDataStream(batch_);
parameterLearningAlgorithm_.initLearning();
parameterLearningAlgorithm_.runLearning();
bnModel_ = parameterLearningAlgorithm_.getLearntBayesianNetwork();
System.out.println(bnModel_);
inferenceAlgorithm_.setModel(bnModel_);
}
内容来源于网络,如有侵权,请联系作者删除!