本文整理汇总了Java中weka.core.AttributeStats类的典型用法代码示例。如果您正苦于以下问题:Java AttributeStats类的具体用法?Java AttributeStats怎么用?Java AttributeStats使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AttributeStats类属于weka.core包,在下文中一共展示了AttributeStats类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: calculate
import weka.core.AttributeStats; //导入依赖的package包/类
/**
* Calculate metric value
*
* @param mlData Multi-label dataset to which calculate the metric
* @return Value of the metric
*/
public double calculate(MultiLabelInstances mlData){
double mean = 0.0;
Instances instances = mlData.getDataSet();
int countNominal = 0;
int [] featureIndices = mlData.getFeatureIndices();
for(int fIndex : featureIndices){
AttributeStats attStats = instances.attributeStats(fIndex);
if(attStats.nominalCounts != null){
countNominal++;
mean += Utils.entropy(attStats.nominalCounts);
}
}
mean = mean/countNominal;
this.value = mean;
return value;
}
开发者ID:i02momuj,项目名称:MLDA,代码行数:28,代码来源:MeanEntropiesNominalAttributes.java
示例2: setT2T1BasedOnStdDev
import weka.core.AttributeStats; //导入依赖的package包/类
/**
* Pretty hokey heuristic to try and set t2 distance automatically based on
* standard deviation
*
* @param trainingBatch the training instances
* @throws Exception if a problem occurs
*/
protected void setT2T1BasedOnStdDev(Instances trainingBatch) throws Exception {
double normalizedStdDevSum = 0;
for (int i = 0; i < trainingBatch.numAttributes(); i++) {
if (trainingBatch.attribute(i).isNominal()) {
normalizedStdDevSum += 0.25;
} else if (trainingBatch.attribute(i).isNumeric()) {
AttributeStats stats = trainingBatch.attributeStats(i);
if (trainingBatch.numInstances() - stats.missingCount > 2) {
double stdDev = stats.numericStats.stdDev;
double min = stats.numericStats.min;
double max = stats.numericStats.max;
if (!Utils.isMissingValue(stdDev) && max - min > 0) {
stdDev = 0.5 * stdDev / (max - min);
normalizedStdDevSum += stdDev;
}
}
}
}
normalizedStdDevSum = Math.sqrt(normalizedStdDevSum);
if (normalizedStdDevSum > 0) {
m_t2 = normalizedStdDevSum;
}
}
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:33,代码来源:Canopy.java
示例3: setInstances
import weka.core.AttributeStats; //导入依赖的package包/类
/**
* Tells the panel to use a new set of instances.
*
* @param inst a set of Instances
*/
public void setInstances(Instances inst) {
m_Instances = inst;
m_AttributeStats = new AttributeStats[inst.numAttributes()];
m_AttributeNameLab.setText(NO_SOURCE);
m_AttributeTypeLab.setText(NO_SOURCE);
m_MissingLab.setText(NO_SOURCE);
m_UniqueLab.setText(NO_SOURCE);
m_DistinctLab.setText(NO_SOURCE);
m_StatsTable.setModel(new DefaultTableModel());
m_allEqualWeights = true;
if (m_Instances.numInstances() == 0) {
return;
}
double w = m_Instances.instance(0).weight();
for (int i = 1; i < m_Instances.numInstances(); i++) {
if (m_Instances.instance(i).weight() != w) {
m_allEqualWeights = false;
break;
}
}
}
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:29,代码来源:AttributeSummaryPanel.java
示例4: testTypical
import weka.core.AttributeStats; //导入依赖的package包/类
public void testTypical() {
Instances result = useFilter();
// Number of attributes shouldn't change
assertEquals(m_Instances.numAttributes(), result.numAttributes());
// Number of instances may change (if an instance has all missing values)
// assertEquals(m_Instances.numInstances(), result.numInstances());
for (int j = 0; j < result.numAttributes(); j++) {
if (j == m_Instances.classIndex() && m_Instances.attribute(j).isNumeric() == false) {
continue;
}
AttributeStats currentStats = m_Instances.attributeStats(j);
if (currentStats.distinctCount < 2) {
continue;
}
assertTrue("All missing values except for those in nonnumeric class " +
"attributes should be replaced.",
result.attributeStats(j).missingCount == 0);
}
}
开发者ID:dsibournemouth,项目名称:autoweka,代码行数:20,代码来源:EMImputationTest.java
示例5: setInstances
import weka.core.AttributeStats; //导入依赖的package包/类
/**
* Tells the panel to use a new set of instances.
*
* @param inst a set of Instances
*/
public void setInstances(Instances inst) {
m_Instances = inst;
m_AttributeStats = new AttributeStats [inst.numAttributes()];
m_AttributeNameLab.setText(NO_SOURCE);
m_AttributeTypeLab.setText(NO_SOURCE);
m_MissingLab.setText(NO_SOURCE);
m_UniqueLab.setText(NO_SOURCE);
m_DistinctLab.setText(NO_SOURCE);
m_StatsTable.setModel(new DefaultTableModel());
m_allEqualWeights = true;
double w = m_Instances.instance(0).weight();
for (int i = 1; i < m_Instances.numInstances(); i++) {
if (m_Instances.instance(i).weight() != w) {
m_allEqualWeights = false;
break;
}
}
}
开发者ID:dsibournemouth,项目名称:autoweka,代码行数:26,代码来源:AttributeSummaryPanel.java
示例6: testDistributionSpread_X
import weka.core.AttributeStats; //导入依赖的package包/类
private void testDistributionSpread_X(double factor) throws Exception {
AttributeStats origs = m_Instances.attributeStats(1);
assertNotNull(origs.nominalCounts);
((SpreadSubsample)m_Filter).setDistributionSpread(factor);
Instances result = useFilter();
assertEquals(m_Instances.numAttributes(), result.numAttributes());
AttributeStats outs = result.attributeStats(1);
// Check distributions are pretty similar
assertNotNull(outs.nominalCounts);
assertEquals(origs.nominalCounts.length, outs.nominalCounts.length);
int min = outs.nominalCounts[0];
int max = outs.nominalCounts[0];
for (int i = 1; i < outs.nominalCounts.length; i++) {
if (outs.nominalCounts[i] < min) {
min = outs.nominalCounts[i];
}
if (outs.nominalCounts[i] > max) {
max = outs.nominalCounts[i];
}
}
assertTrue(max / factor <= min);
}
开发者ID:dsibournemouth,项目名称:autoweka,代码行数:25,代码来源:SpreadSubsampleTest.java
示例7: testNoBias
import weka.core.AttributeStats; //导入依赖的package包/类
public void testNoBias() throws Exception {
m_Instances.setClassIndex(1);
AttributeStats origs = m_Instances.attributeStats(1);
assertNotNull(origs.nominalCounts);
Instances result = useFilter();
assertEquals(m_Instances.numAttributes(), result.numAttributes());
AttributeStats outs = result.attributeStats(1);
// Check distributions are pretty similar
assertNotNull(outs.nominalCounts);
assertEquals(origs.nominalCounts.length, outs.nominalCounts.length);
for (int i = 0; i < origs.nominalCounts.length; i++) {
int est = origs.nominalCounts[i] / 2 - 1;
assertTrue("Counts for value:" + i
+ " orig:" + origs.nominalCounts[i]
+ " out50%:" + outs.nominalCounts[i],
(est <= outs.nominalCounts[i]) &&
(outs.nominalCounts[i] <= (est + 3)));
}
}
开发者ID:dsibournemouth,项目名称:autoweka,代码行数:22,代码来源:ResampleTest.java
示例8: testBiasToUniform
import weka.core.AttributeStats; //导入依赖的package包/类
public void testBiasToUniform() throws Exception {
m_Instances.setClassIndex(1);
AttributeStats origs = m_Instances.attributeStats(1);
assertNotNull(origs.nominalCounts);
((Resample)m_Filter).setBiasToUniformClass(1.0);
Instances result = useFilter();
assertEquals(m_Instances.numAttributes(), result.numAttributes());
AttributeStats outs = result.attributeStats(1);
// Check distributions are pretty similar
assertNotNull(outs.nominalCounts);
assertEquals(origs.nominalCounts.length, outs.nominalCounts.length);
int est = (origs.totalCount - origs.missingCount) / origs.distinctCount;
est = est / 2 - 1;
for (int i = 0; i < origs.nominalCounts.length; i++) {
assertTrue("Counts for value:" + i
+ " orig:" + origs.nominalCounts[i]
+ " out50%:" + outs.nominalCounts[i]
+ " ~wanted:" + est,
(est <= outs.nominalCounts[i]) &&
(outs.nominalCounts[i] <= (est + 3)));
}
}
开发者ID:dsibournemouth,项目名称:autoweka,代码行数:25,代码来源:ResampleTest.java
示例9: calculate
import weka.core.AttributeStats; //导入依赖的package包/类
/**
* Calculate metric value
*
* @param mlData Multi-label dataset to which calculate the metric
* @return Value of the metric
*/
public double calculate(MultiLabelInstances mlData){
Instances instances = mlData.getDataSet();
int nLabels = mlData.getNumLabels();
int [] labels = mlData.getLabelIndices();
double [] entropies = new double[nLabels];
for(int i=0; i<nLabels; i++){
AttributeStats attStats = instances.attributeStats(labels[i]);
if(attStats.nominalCounts != null){
entropies[i] = Utils.entropy(attStats.nominalCounts);
}
}
double minEntropy = Double.MAX_VALUE;
for(double e : entropies){
if(e < minEntropy){
minEntropy = e;
}
}
this.value = minEntropy;
return value;
}
开发者ID:i02momuj,项目名称:MLDA,代码行数:34,代码来源:MinEntropy.java
示例10: calculate
import weka.core.AttributeStats; //导入依赖的package包/类
/**
* Calculate metric value
*
* @param mlData Multi-label dataset to which calculate the metric
* @return Value of the metric
*/
public double calculate(MultiLabelInstances mlData){
Instances instances = mlData.getDataSet();
int nLabels = mlData.getNumLabels();
int [] labels = mlData.getLabelIndices();
double [] entropies = new double[nLabels];
for(int i=0; i<nLabels; i++){
AttributeStats attStats = instances.attributeStats(labels[i]);
if(attStats.nominalCounts != null){
entropies[i] = Utils.entropy(attStats.nominalCounts);
}
}
double maxEntropy = Double.MIN_VALUE;
for(double e : entropies){
if(e > maxEntropy){
maxEntropy = e;
}
}
this.value = maxEntropy;
return value;
}
开发者ID:i02momuj,项目名称:MLDA,代码行数:34,代码来源:MaxEntropy.java
示例11: calculate
import weka.core.AttributeStats; //导入依赖的package包/类
/**
* Calculate metric value
*
* @param mlData Multi-label dataset to which calculate the metric
* @return Value of the metric
*/
public double calculate(MultiLabelInstances mlData){
Instances instances = mlData.getDataSet();
int nLabels = mlData.getNumLabels();
int [] labels = mlData.getLabelIndices();
double [] entropies = new double[nLabels];
for(int i=0; i<nLabels; i++){
AttributeStats attStats = instances.attributeStats(labels[i]);
if(attStats.nominalCounts != null){
entropies[i] = Utils.entropy(attStats.nominalCounts);
}
}
double meanEntropy = 0;
for(double e : entropies){
meanEntropy += e;
}
meanEntropy /= entropies.length;
this.value = meanEntropy;
return value;
}
开发者ID:i02momuj,项目名称:MLDA,代码行数:33,代码来源:MeanEntropy.java
示例12: main
import weka.core.AttributeStats; //导入依赖的package包/类
public static void main(String[] args) {
try {
weka.core.Instances inst =
new weka.core.Instances(new java.io.FileReader(args[0]));
double quantile = Double.parseDouble(args[1]);
IncrementalQuantileEstimator ps =
new IncrementalQuantileEstimator(quantile);
int attIndex = Integer.parseInt(args[2]) - 1;
for (int i = 0; i < inst.numInstances(); i++) {
if (!inst.instance(i).isMissing(attIndex)) {
ps.add(inst.instance(i).value(attIndex));
}
}
System.err.println("Estimated quantile (" + quantile + ") "
+ ps.getQuantile());
inst.sort(attIndex);
double actualQuant = 0;
AttributeStats as = inst.attributeStats(attIndex);
double pIndex = quantile * (inst.numInstances() - as.missingCount);
double mean = as.numericStats.mean;
if (pIndex - (int) pIndex > 0) {
pIndex = (int) pIndex;
actualQuant = inst.instance((int) pIndex).value(attIndex);
} else {
double f = inst.instance((int) pIndex - 1).value(attIndex);
double s = inst.instance((int) pIndex).value(attIndex);
actualQuant = (f + s) / 2.0;
}
System.err.println("Actual quantile (" + quantile + ") " + actualQuant);
System.err.println("Mean: " + mean);
} catch (Exception ex) {
ex.printStackTrace();
}
}
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:41,代码来源:IncrementalQuantileEstimator.java
示例13: updateStats
import weka.core.AttributeStats; //导入依赖的package包/类
/**
* Update attribute stats using the supplied instance.
*
* @param updateInstance the instance for updating
* @param delete true if the values of the supplied instance are to be
* removed from the statistics
*/
protected void updateStats(Instance updateInstance, boolean delete) {
if (m_attStats == null) {
m_attStats = new AttributeStats[m_numAttributes];
for (int i = 0; i < m_numAttributes; i++) {
m_attStats[i] = new AttributeStats();
if (m_clusterInstances.attribute(i).isNominal()) {
m_attStats[i].nominalCounts = new int[m_clusterInstances.attribute(
i).numValues()];
} else {
m_attStats[i].numericStats = new Stats();
}
}
}
for (int i = 0; i < m_numAttributes; i++) {
if (!updateInstance.isMissing(i)) {
double value = updateInstance.value(i);
if (m_clusterInstances.attribute(i).isNominal()) {
m_attStats[i].nominalCounts[(int) value] += (delete) ? (-1.0 * updateInstance
.weight()) : updateInstance.weight();
m_attStats[i].totalCount += (delete) ? (-1.0 * updateInstance
.weight()) : updateInstance.weight();
} else {
if (delete) {
m_attStats[i].numericStats.subtract(value,
updateInstance.weight());
} else {
m_attStats[i].numericStats.add(value, updateInstance.weight());
}
}
}
}
m_totalInstances += (delete) ? (-1.0 * updateInstance.weight())
: (updateInstance.weight());
}
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:43,代码来源:Cobweb.java
示例14: setInstances
import weka.core.AttributeStats; //导入依赖的package包/类
/**
* Sets the instances for use
*
* @param newins a set of Instances
*/
public void setInstances(Instances newins) {
m_attribIndex = 0;
m_as = null;
m_data = new Instances(newins);
if (m_colorAttrib != null) {
m_colorAttrib.removeAllItems();
m_colorAttrib.addItem("No class");
for (int i = 0; i < m_data.numAttributes(); i++) {
String type = "(" + Attribute.typeToStringShort(m_data.attribute(i))
+ ")";
m_colorAttrib.addItem(new String("Class: " + m_data.attribute(i).name()
+ " " + type));
}
if (m_data.classIndex() >= 0) {
m_colorAttrib.setSelectedIndex(m_data.classIndex() + 1);
} else {
m_colorAttrib.setSelectedIndex(m_data.numAttributes());
}
// if (m_data.classIndex() >= 0) {
// m_colorAttrib.setSelectedIndex(m_data.classIndex());
// }
}
if (m_data.classIndex() >= 0) {
m_classIndex = m_data.classIndex();
} else {
m_classIndex = m_data.numAttributes() - 1;
}
m_asCache = new AttributeStats[m_data.numAttributes()];
}
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:37,代码来源:AttributeVisualizationPanel.java
示例15: setDerived
import weka.core.AttributeStats; //导入依赖的package包/类
/**
* Sets the gui elements for fields that are stored in the AttributeStats
* structure.
*
* @param index the index of the attribute
*/
protected void setDerived(int index) {
AttributeStats as = m_AttributeStats[index];
long percent = Math.round(100.0 * as.missingCount / as.totalCount);
m_MissingLab.setText("" + as.missingCount + " (" + percent + "%)");
percent = Math.round(100.0 * as.uniqueCount / as.totalCount);
m_UniqueLab.setText("" + as.uniqueCount + " (" + percent + "%)");
m_DistinctLab.setText("" + as.distinctCount);
setTable(as, index);
}
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:17,代码来源:AttributeSummaryPanel.java
示例16: build
import weka.core.AttributeStats; //导入依赖的package包/类
/**
* builds the classifier
*
* @throws Exception if something goes wrong
*/
@Override
protected void build() throws Exception {
AttributeStats stats;
int i;
// determine class distribution
m_ClassDistribution = new double[2];
stats = m_Trainset.attributeStats(m_Trainset.classIndex());
for (i = 0; i < 2; i++)
m_ClassDistribution[i] = stats.nominalCounts[i] / stats.totalCount;
// the number of instances added to the training set in each iteration
m_InstancesPerIteration = (double) m_Testset.numInstances()
/ getFolds();
if (getDebug())
System.out.println("InstancesPerIteration: " + m_InstancesPerIteration);
// build classifier
m_Random = new Random(getSeed());
for (i = 0; i <= getFolds(); i++) {
if (getVerbose() || getDebug()) {
if (getCutOff() > 0)
System.out.println( "\nFold " + i + "/" + getFolds()
+ " (CutOff at " + getCutOff() + ")");
else
System.out.println("\nFold " + i + "/" + getFolds());
}
buildTrainSet(i);
buildClassifier();
// cutoff of folds reached?
if ( (i > 0) && (i == getCutOff()) )
break;
}
}
开发者ID:fracpete,项目名称:collective-classification-weka-package,代码行数:41,代码来源:Chopper.java
示例17: setClassProbabilities
import weka.core.AttributeStats; //导入依赖的package包/类
/**
* sets the class probabilities based on the given data
*
* @param data the data to get the class probabilities from
*/
public void setClassProbabilities(Instances data) {
AttributeStats stats;
int total;
int i;
stats = data.attributeStats(data.classIndex());
total = Utils.sum(stats.nominalCounts);
m_ClassProbs = new double[data.classAttribute().numValues()];
for (i = 0; i < m_ClassProbs.length; i++)
m_ClassProbs[i] = (double) stats.nominalCounts[i] / (double) total;
}
开发者ID:fracpete,项目名称:collective-classification-weka-package,代码行数:17,代码来源:DecisionTreeNode.java
示例18: initializeLabels
import weka.core.AttributeStats; //导入依赖的package包/类
/**
* randomly initializes the class labels in the given set according to the
* class distribution in the training set
* @param train the training instances to retrieve the class
* distribution from
* @param instances the instances to initialize
* @param from the first instance to initialize
* @param count the number of instances to initialize
* @return the initialize instances
* @throws Exception if something goes wrong
*/
public Instances initializeLabels( Instances train, Instances instances,
int from, int count )
throws Exception {
int i;
AttributeStats stats;
Attribute classAttr;
double percentage;
// reset flip count
m_FlippedLabels = 0;
// explicitly set labels to "missing"
for (i = from; i < from + count; i++)
instances.instance(i).setClassMissing();
// determining the percentage of the first class
stats = train.attributeStats(train.classIndex());
percentage = (double) stats.nominalCounts[0] / (double) stats.totalCount;
// set lables
classAttr = instances.attribute(instances.classIndex());
for (i = from; i < from + count; i++) {
// random class
if (m_Random.nextDouble() < percentage)
instances.instance(i).setClassValue(classAttr.value(0));
else
instances.instance(i).setClassValue(classAttr.value(1));
}
return instances;
}
开发者ID:fracpete,项目名称:collective-classification-weka-package,代码行数:44,代码来源:CollectiveInstances.java
示例19: updateStats
import weka.core.AttributeStats; //导入依赖的package包/类
/**
* Update attribute stats using the supplied instance.
*
* @param updateInstance the instance for updating
* @param delete true if the values of the supplied instance are
* to be removed from the statistics
*/
protected void updateStats(Instance updateInstance,
boolean delete) {
if (m_attStats == null) {
m_attStats = new AttributeStats[m_numAttributes];
for (int i = 0; i < m_numAttributes; i++) {
m_attStats[i] = new AttributeStats();
if (m_clusterInstances.attribute(i).isNominal()) {
m_attStats[i].nominalCounts =
new int [m_clusterInstances.attribute(i).numValues()];
} else {
m_attStats[i].numericStats = new Stats();
}
}
}
for (int i = 0; i < m_numAttributes; i++) {
if (!updateInstance.isMissing(i)) {
double value = updateInstance.value(i);
if (m_clusterInstances.attribute(i).isNominal()) {
m_attStats[i].nominalCounts[(int)value] += (delete) ?
(-1.0 * updateInstance.weight()) :
updateInstance.weight();
m_attStats[i].totalCount += (delete) ?
(-1.0 * updateInstance.weight()) :
updateInstance.weight();
} else {
if (delete) {
m_attStats[i].numericStats.subtract(value,
updateInstance.weight());
} else {
m_attStats[i].numericStats.add(value, updateInstance.weight());
}
}
}
}
m_totalInstances += (delete)
? (-1.0 * updateInstance.weight())
: (updateInstance.weight());
}
开发者ID:dsibournemouth,项目名称:autoweka,代码行数:47,代码来源:Cobweb.java
示例20: setInstances
import weka.core.AttributeStats; //导入依赖的package包/类
/**
* Sets the instances for use
*
* @param newins a set of Instances
*/
public void setInstances(Instances newins) {
m_attribIndex = 0;
m_as = null;
m_data = new Instances(newins);
if(m_colorAttrib!=null) {
m_colorAttrib.removeAllItems();
m_colorAttrib.addItem("No class");
for(int i=0; i<m_data.numAttributes(); i++) {
String type = "(" + Attribute.typeToStringShort(m_data.attribute(i)) + ")";
m_colorAttrib.addItem(new String("Class: " + m_data.attribute(i).name() + " " + type));
}
if (m_data.classIndex() >= 0) {
m_colorAttrib.setSelectedIndex(m_data.classIndex() + 1);
} else {
m_colorAttrib.setSelectedIndex(m_data.numAttributes());
}
//if (m_data.classIndex() >= 0) {
// m_colorAttrib.setSelectedIndex(m_data.classIndex());
//}
}
if (m_data.classIndex() >= 0) {
m_classIndex = m_data.classIndex();
} else {
m_classIndex = m_data.numAttributes()-1;
}
m_asCache = new AttributeStats[m_data.numAttributes()];
}
开发者ID:dsibournemouth,项目名称:autoweka,代码行数:35,代码来源:AttributeVisualizationPanel.java
注:本文中的weka.core.AttributeStats类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论