本文整理汇总了Java中com.rapidminer.tools.math.function.aggregation.VarianceFunction类的典型用法代码示例。如果您正苦于以下问题:Java VarianceFunction类的具体用法?Java VarianceFunction怎么用?Java VarianceFunction使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
VarianceFunction类属于com.rapidminer.tools.math.function.aggregation包,在下文中一共展示了VarianceFunction类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: apply
import com.rapidminer.tools.math.function.aggregation.VarianceFunction; //导入依赖的package包/类
public SignificanceTestResult apply(ExampleSet exampleSet) throws OperatorException {
// init and checks
String attributeName = getParameterAsString(PARAMETER_ANOVA_ATTRIBUTE);
String groupByAttributeName = getParameterAsString(PARAMETER_GROUP_BY_ATTRIBUTE);
boolean onlyDistinct = getParameterAsBoolean(PARAMETER_ONLY_DISTINCT);
Attribute anovaAttribute = exampleSet.getAttributes().get(attributeName);
if (anovaAttribute == null) {
throw new AttributeNotFoundError(this, PARAMETER_ANOVA_ATTRIBUTE,
getParameterAsString(PARAMETER_ANOVA_ATTRIBUTE));
}
if (anovaAttribute.isNominal()) {
throw new UserError(this, 104, new Object[] { "anova calculation",
this.getParameterAsString(PARAMETER_ANOVA_ATTRIBUTE) });
}
Attribute groupByAttribute = exampleSet.getAttributes().get(groupByAttributeName);
if (groupByAttribute == null) {
throw new AttributeNotFoundError(this, PARAMETER_GROUP_BY_ATTRIBUTE,
getParameterAsString(PARAMETER_GROUP_BY_ATTRIBUTE));
}
if (!groupByAttribute.isNominal()) {
throw new UserError(this, 103, new Object[] { "the parameter grouping by",
this.getParameterAsString(PARAMETER_GROUP_BY_ATTRIBUTE) });
}
// create anova calculator
AnovaCalculator anovaCalculator = new AnovaCalculator();
double alpha = getParameterAsDouble(PARAMETER_SIGNIFICANCE_LEVEL);
anovaCalculator.setAlpha(alpha);
// add groups
SplittedExampleSet grouped = SplittedExampleSet.splitByAttribute(exampleSet, groupByAttribute);
AggregationFunction meanFunction = new AverageFunction();
AggregationFunction varianceFunction = new VarianceFunction();
for (int i = 0; i < grouped.getNumberOfSubsets(); i++) {
grouped.selectSingleSubset(i);
double[] values = getValues(grouped, anovaAttribute, onlyDistinct);
double mean = meanFunction.calculate(values);
double variance = varianceFunction.calculate(values);
anovaCalculator.addGroup(grouped.size(), mean, variance);
}
// calculate and return result
SignificanceTestResult result = null;
try {
result = anovaCalculator.performSignificanceTest();
} catch (SignificanceCalculationException e) {
throw new UserError(this, 920, e.getMessage());
}
exampleSetOutput.deliver(exampleSet);
return result;
}
示例2: apply
import com.rapidminer.tools.math.function.aggregation.VarianceFunction; //导入依赖的package包/类
public SignificanceTestResult apply(ExampleSet exampleSet) throws OperatorException {
// init and checks
String attributeName = getParameterAsString(PARAMETER_ANOVA_ATTRIBUTE);
String groupByAttributeName = getParameterAsString(PARAMETER_GROUP_BY_ATTRIBUTE);
boolean onlyDistinct = getParameterAsBoolean(PARAMETER_ONLY_DISTINCT);
Attribute anovaAttribute = exampleSet.getAttributes().get(attributeName);
if (anovaAttribute == null) {
throw new UserError(this, 111, this.getParameterAsString(PARAMETER_ANOVA_ATTRIBUTE));
}
if (anovaAttribute.isNominal()) {
throw new UserError(this, 104, new Object[] { "anova calculation", this.getParameterAsString(PARAMETER_ANOVA_ATTRIBUTE)});
}
Attribute groupByAttribute = exampleSet.getAttributes().get(groupByAttributeName);
if (groupByAttribute == null) {
throw new UserError(this, 111, this.getParameterAsString(PARAMETER_GROUP_BY_ATTRIBUTE));
}
if (!groupByAttribute.isNominal()) {
throw new UserError(this, 103, new Object[] {"the parameter grouping by", this.getParameterAsString(PARAMETER_GROUP_BY_ATTRIBUTE)});
}
// create anova calculator
AnovaCalculator anovaCalculator = new AnovaCalculator();
double alpha = getParameterAsDouble(PARAMETER_SIGNIFICANCE_LEVEL);
anovaCalculator.setAlpha(alpha);
// add groups
SplittedExampleSet grouped = SplittedExampleSet.splitByAttribute(exampleSet, groupByAttribute);
AggregationFunction meanFunction = new AverageFunction();
AggregationFunction varianceFunction = new VarianceFunction();
for (int i = 0; i < grouped.getNumberOfSubsets(); i++) {
grouped.selectSingleSubset(i);
double[] values = getValues(grouped, anovaAttribute, onlyDistinct);
double mean = meanFunction.calculate(values);
double variance = varianceFunction.calculate(values);
anovaCalculator.addGroup(grouped.size(), mean, variance);
}
// calculate and return result
SignificanceTestResult result = null;
try {
result = anovaCalculator.performSignificanceTest();
} catch (SignificanceCalculationException e) {
throw new UserError(this, 920, e.getMessage());
}
exampleSetOutput.deliver(exampleSet);
return result;
}