本文整理汇总了Java中weka.filters.supervised.attribute.Discretize类的典型用法代码示例。如果您正苦于以下问题:Java Discretize类的具体用法?Java Discretize怎么用?Java Discretize使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Discretize类属于weka.filters.supervised.attribute包,在下文中一共展示了Discretize类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildEvaluator
import weka.filters.supervised.attribute.Discretize; //导入依赖的package包/类
/**
* Initializes a symmetrical uncertainty attribute evaluator. Discretizes all
* attributes that are numeric.
*
* @param data set of instances serving as training data
* @throws Exception if the evaluator has not been generated successfully
*/
@Override
public void buildEvaluator(Instances data) throws Exception {
// can evaluator handle data?
getCapabilities().testWithFail(data);
m_trainInstances = data;
m_classIndex = m_trainInstances.classIndex();
m_numInstances = m_trainInstances.numInstances();
Discretize disTransform = new Discretize();
disTransform.setUseBetterEncoding(true);
disTransform.setInputFormat(m_trainInstances);
m_trainInstances = Filter.useFilter(m_trainInstances, disTransform);
m_numClasses = m_trainInstances.attribute(m_classIndex).numValues();
}
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:23,代码来源:SymmetricalUncertAttributeEval.java
示例2: buildEvaluator
import weka.filters.supervised.attribute.Discretize; //导入依赖的package包/类
/**
* Initializes a gain ratio attribute evaluator. Discretizes all attributes
* that are numeric.
*
* @param data set of instances serving as training data
* @throws Exception if the evaluator has not been generated successfully
*/
@Override
public void buildEvaluator(Instances data) throws Exception {
// can evaluator handle data?
getCapabilities().testWithFail(data);
m_trainInstances = data;
m_classIndex = m_trainInstances.classIndex();
m_numInstances = m_trainInstances.numInstances();
Discretize disTransform = new Discretize();
disTransform.setUseBetterEncoding(true);
disTransform.setInputFormat(m_trainInstances);
m_trainInstances = Filter.useFilter(m_trainInstances, disTransform);
m_numClasses = m_trainInstances.attribute(m_classIndex).numValues();
}
示例3: normalizeDataSet
import weka.filters.supervised.attribute.Discretize; //导入依赖的package包/类
/**
* 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;
}
示例4: buildEvaluator
import weka.filters.supervised.attribute.Discretize; //导入依赖的package包/类
/**
* Initializes a symmetrical uncertainty attribute evaluator.
* Discretizes all attributes that are numeric.
*
* @param data set of instances serving as training data
* @throws Exception if the evaluator has not been
* generated successfully
*/
public void buildEvaluator (Instances data)
throws Exception {
// can evaluator handle data?
getCapabilities().testWithFail(data);
m_trainInstances = data;
m_classIndex = m_trainInstances.classIndex();
m_numAttribs = m_trainInstances.numAttributes();
m_numInstances = m_trainInstances.numInstances();
Discretize disTransform = new Discretize();
disTransform.setUseBetterEncoding(true);
disTransform.setInputFormat(m_trainInstances);
m_trainInstances = Filter.useFilter(m_trainInstances, disTransform);
m_numClasses = m_trainInstances.attribute(m_classIndex).numValues();
}
示例5: buildEvaluator
import weka.filters.supervised.attribute.Discretize; //导入依赖的package包/类
/**
* Initializes a gain ratio attribute evaluator.
* Discretizes all attributes that are numeric.
*
* @param data set of instances serving as training data
* @throws Exception if the evaluator has not been
* generated successfully
*/
public void buildEvaluator (Instances data)
throws Exception {
// can evaluator handle data?
getCapabilities().testWithFail(data);
m_trainInstances = data;
m_classIndex = m_trainInstances.classIndex();
m_numAttribs = m_trainInstances.numAttributes();
m_numInstances = m_trainInstances.numInstances();
Discretize disTransform = new Discretize();
disTransform.setUseBetterEncoding(true);
disTransform.setInputFormat(m_trainInstances);
m_trainInstances = Filter.useFilter(m_trainInstances, disTransform);
m_numClasses = m_trainInstances.attribute(m_classIndex).numValues();
}
示例6: buildEvaluator
import weka.filters.supervised.attribute.Discretize; //导入依赖的package包/类
/**
* Generates a attribute evaluator. Has to initialize all fields of the
* evaluator that are not being set via options.
*
* @param data set of instances serving as training data
* @throws Exception if the evaluator has not been
* generated successfully
*/
public void buildEvaluator (Instances data) throws Exception {
// can evaluator handle data?
getCapabilities().testWithFail(data);
m_trainInstances = new Instances(data);
m_trainInstances.deleteWithMissingClass();
m_classIndex = m_trainInstances.classIndex();
m_numAttribs = m_trainInstances.numAttributes();
m_numInstances = m_trainInstances.numInstances();
m_disTransform = new Discretize();
m_disTransform.setUseBetterEncoding(true);
m_disTransform.setInputFormat(m_trainInstances);
m_trainInstances = Filter.useFilter(m_trainInstances, m_disTransform);
}
示例7: buildClassifier
import weka.filters.supervised.attribute.Discretize; //导入依赖的package包/类
/**
* Build the no-split node
*
* @param instances an <code>Instances</code> value
* @exception Exception if an error occurs
*/
public final void buildClassifier(Instances instances) throws Exception {
m_nb = new NaiveBayesUpdateable();
m_disc = new Discretize();
m_disc.setInputFormat(instances);
Instances temp = Filter.useFilter(instances, m_disc);
m_nb.buildClassifier(temp);
if (temp.numInstances() >= 5) {
m_errors = crossValidate(m_nb, temp, new Random(1));
}
m_numSubsets = 1;
}
示例8: buildEvaluator
import weka.filters.supervised.attribute.Discretize; //导入依赖的package包/类
/**
* Generates a attribute evaluator. Has to initialize all fields of the
* evaluator that are not being set via options.
*
* CFS also discretises attributes (if necessary) and initializes
* the correlation matrix.
*
* @param data set of instances serving as training data
* @throws Exception if the evaluator has not been
* generated successfully
*/
public void buildEvaluator (Instances data)
throws Exception {
// can evaluator handle data?
getCapabilities().testWithFail(data);
m_trainInstances = new Instances(data);
m_trainInstances.deleteWithMissingClass();
m_classIndex = m_trainInstances.classIndex();
m_numAttribs = m_trainInstances.numAttributes();
m_numInstances = m_trainInstances.numInstances();
m_isNumeric = m_trainInstances.attribute(m_classIndex).isNumeric();
if (!m_isNumeric) {
m_disTransform = new Discretize();
m_disTransform.setUseBetterEncoding(true);
m_disTransform.setInputFormat(m_trainInstances);
m_trainInstances = Filter.useFilter(m_trainInstances, m_disTransform);
}
m_std_devs = new double[m_numAttribs];
m_corr_matrix = new float [m_numAttribs][];
for (int i = 0; i < m_numAttribs; i++) {
m_corr_matrix[i] = new float [i+1];
}
for (int i = 0; i < m_corr_matrix.length; i++) {
m_corr_matrix[i][i] = 1.0f;
m_std_devs[i] = 1.0;
}
for (int i = 0; i < m_numAttribs; i++) {
for (int j = 0; j < m_corr_matrix[i].length - 1; j++) {
m_corr_matrix[i][j] = -999;
}
}
}
示例9: handleNumericAttribute
import weka.filters.supervised.attribute.Discretize; //导入依赖的package包/类
/**
* Creates split on numeric attribute.
*
* @exception Exception if something goes wrong
*/
private void handleNumericAttribute(Instances trainInstances)
throws Exception {
m_c45S = new C45Split(m_attIndex, 2, m_sumOfWeights, true);
m_c45S.buildClassifier(trainInstances);
if (m_c45S.numSubsets() == 0) {
return;
}
m_errors = 0;
Instances[] trainingSets = new Instances[m_complexityIndex];
trainingSets[0] = new Instances(trainInstances, 0);
trainingSets[1] = new Instances(trainInstances, 0);
int subset = -1;
// populate the subsets
for (int i = 0; i < trainInstances.numInstances(); i++) {
Instance instance = trainInstances.instance(i);
subset = m_c45S.whichSubset(instance);
if (subset != -1) {
trainingSets[subset].add((Instance) instance.copy());
} else {
double[] weights = m_c45S.weights(instance);
for (int j = 0; j < m_complexityIndex; j++) {
Instance temp = (Instance) instance.copy();
if (weights.length == m_complexityIndex) {
temp.setWeight(temp.weight() * weights[j]);
} else {
temp.setWeight(temp.weight() / m_complexityIndex);
}
trainingSets[j].add(temp);
}
}
}
/*
* // compute weights (weights of instances per subset m_weights = new
* double [m_complexityIndex]; for (int i = 0; i < m_complexityIndex; i++) {
* m_weights[i] = trainingSets[i].sumOfWeights(); }
* Utils.normalize(m_weights);
*/
Random r = new Random(1);
int minNumCount = 0;
for (int i = 0; i < m_complexityIndex; i++) {
if (trainingSets[i].numInstances() > 5) {
minNumCount++;
// Discretize the sets
Discretize disc = new Discretize();
disc.setInputFormat(trainingSets[i]);
trainingSets[i] = Filter.useFilter(trainingSets[i], disc);
trainingSets[i].randomize(r);
trainingSets[i].stratify(5);
NaiveBayesUpdateable fullModel = new NaiveBayesUpdateable();
fullModel.buildClassifier(trainingSets[i]);
// add the errors for this branch of the split
m_errors += NBTreeNoSplit.crossValidate(fullModel, trainingSets[i], r);
} else {
for (int j = 0; j < trainingSets[i].numInstances(); j++) {
m_errors += trainingSets[i].instance(j).weight();
}
}
}
// Check if minimum number of Instances in at least two
// subsets.
if (minNumCount > 1) {
m_numSubsets = m_complexityIndex;
}
}
示例10: handleNumericAttribute
import weka.filters.supervised.attribute.Discretize; //导入依赖的package包/类
/**
* Creates split on numeric attribute.
*
* @exception Exception if something goes wrong
*/
private void handleNumericAttribute(Instances trainInstances)
throws Exception {
m_c45S = new C45Split(m_attIndex, 2, m_sumOfWeights, true);
m_c45S.buildClassifier(trainInstances);
if (m_c45S.numSubsets() == 0) {
return;
}
m_errors = 0;
Instances [] trainingSets = new Instances [m_complexityIndex];
trainingSets[0] = new Instances(trainInstances, 0);
trainingSets[1] = new Instances(trainInstances, 0);
int subset = -1;
// populate the subsets
for (int i = 0; i < trainInstances.numInstances(); i++) {
Instance instance = trainInstances.instance(i);
subset = m_c45S.whichSubset(instance);
if (subset != -1) {
trainingSets[subset].add((Instance)instance.copy());
} else {
double [] weights = m_c45S.weights(instance);
for (int j = 0; j < m_complexityIndex; j++) {
Instance temp = (Instance)instance.copy();
if (weights.length == m_complexityIndex) {
temp.setWeight(temp.weight() * weights[j]);
} else {
temp.setWeight(temp.weight() / m_complexityIndex);
}
trainingSets[j].add(temp);
}
}
}
/* // compute weights (weights of instances per subset
m_weights = new double [m_complexityIndex];
for (int i = 0; i < m_complexityIndex; i++) {
m_weights[i] = trainingSets[i].sumOfWeights();
}
Utils.normalize(m_weights); */
Random r = new Random(1);
int minNumCount = 0;
for (int i = 0; i < m_complexityIndex; i++) {
if (trainingSets[i].numInstances() > 5) {
minNumCount++;
// Discretize the sets
Discretize disc = new Discretize();
disc.setInputFormat(trainingSets[i]);
trainingSets[i] = Filter.useFilter(trainingSets[i], disc);
trainingSets[i].randomize(r);
trainingSets[i].stratify(5);
NaiveBayesUpdateable fullModel = new NaiveBayesUpdateable();
fullModel.buildClassifier(trainingSets[i]);
// add the errors for this branch of the split
m_errors += NBTreeNoSplit.crossValidate(fullModel, trainingSets[i], r);
} else {
for (int j = 0; j < trainingSets[i].numInstances(); j++) {
m_errors += trainingSets[i].instance(j).weight();
}
}
}
// Check if minimum number of Instances in at least two
// subsets.
if (minNumCount > 1) {
m_numSubsets = m_complexityIndex;
}
}
示例11: handleNumericAttribute
import weka.filters.supervised.attribute.Discretize; //导入依赖的package包/类
/**
* Creates split on numeric attribute.
*
* @exception Exception if something goes wrong
*/
private void handleNumericAttribute(Instances trainInstances)
throws Exception {
m_c45S = new C45Split(m_attIndex, 2, m_sumOfWeights);
m_c45S.buildClassifier(trainInstances);
if (m_c45S.numSubsets() == 0) {
return;
}
m_errors = 0;
Instances [] trainingSets = new Instances [m_complexityIndex];
trainingSets[0] = new Instances(trainInstances, 0);
trainingSets[1] = new Instances(trainInstances, 0);
int subset = -1;
// populate the subsets
for (int i = 0; i < trainInstances.numInstances(); i++) {
Instance instance = trainInstances.instance(i);
subset = m_c45S.whichSubset(instance);
if (subset != -1) {
trainingSets[subset].add((Instance)instance.copy());
} else {
double [] weights = m_c45S.weights(instance);
for (int j = 0; j < m_complexityIndex; j++) {
Instance temp = (Instance)instance.copy();
if (weights.length == m_complexityIndex) {
temp.setWeight(temp.weight() * weights[j]);
} else {
temp.setWeight(temp.weight() / m_complexityIndex);
}
trainingSets[j].add(temp);
}
}
}
/* // compute weights (weights of instances per subset
m_weights = new double [m_complexityIndex];
for (int i = 0; i < m_complexityIndex; i++) {
m_weights[i] = trainingSets[i].sumOfWeights();
}
Utils.normalize(m_weights); */
Random r = new Random(1);
int minNumCount = 0;
for (int i = 0; i < m_complexityIndex; i++) {
if (trainingSets[i].numInstances() > 5) {
minNumCount++;
// Discretize the sets
Discretize disc = new Discretize();
disc.setInputFormat(trainingSets[i]);
trainingSets[i] = Filter.useFilter(trainingSets[i], disc);
trainingSets[i].randomize(r);
trainingSets[i].stratify(5);
NaiveBayesUpdateable fullModel = new NaiveBayesUpdateable();
fullModel.buildClassifier(trainingSets[i]);
// add the errors for this branch of the split
m_errors += NBTreeNoSplit.crossValidate(fullModel, trainingSets[i], r);
} else {
for (int j = 0; j < trainingSets[i].numInstances(); j++) {
m_errors += trainingSets[i].instance(j).weight();
}
}
}
// Check if minimum number of Instances in at least two
// subsets.
if (minNumCount > 1) {
m_numSubsets = m_complexityIndex;
}
}
示例12: getDiscretizer
import weka.filters.supervised.attribute.Discretize; //导入依赖的package包/类
/**
* Return the discretizer used at this node
*
* @return a <code>Discretize</code> value
*/
public Discretize getDiscretizer() {
return m_disc;
}