当前位置: 首页>>代码示例>>Java>>正文


Java NominalToBinary类代码示例

本文整理汇总了Java中weka.filters.unsupervised.attribute.NominalToBinary的典型用法代码示例。如果您正苦于以下问题:Java NominalToBinary类的具体用法?Java NominalToBinary怎么用?Java NominalToBinary使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


NominalToBinary类属于weka.filters.unsupervised.attribute包,在下文中一共展示了NominalToBinary类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: preProcessData

import weka.filters.unsupervised.attribute.NominalToBinary; //导入依赖的package包/类
/**
 * 
 * @param data the data to transform
 * @param shouldImpute impute the data?
 * @param shouldStandardize standardize the numeric attributes?
 * @param shouldBinarize binarize the attributes?
 * @return the transformed data
 * @throws Exception
 */
public static Instances preProcessData(Instances data, boolean shouldImpute, 
		boolean shouldStandardize, boolean shouldBinarize) throws Exception {
    if( shouldImpute ) {
    	Filter impute = new ReplaceMissingValues();
    	impute.setInputFormat(data);
		data = Filter.useFilter(data, impute);
    }
	if( shouldStandardize ) {
		Filter standardize = new Standardize();
		standardize.setInputFormat(data);
		data = Filter.useFilter(data, standardize);
	}
	if( shouldBinarize ) {
		Filter binarize = new NominalToBinary();
		binarize.setInputFormat(data);
    	// make resulting binary attrs nominal, not numeric
		binarize.setOptions(new String[] { "-N" } );
    	data = Filter.useFilter(data, binarize);
	}
	return data;
}
 
开发者ID:christopher-beckham,项目名称:weka-pyscript,代码行数:31,代码来源:Utility.java

示例2: setUp

import weka.filters.unsupervised.attribute.NominalToBinary; //导入依赖的package包/类
protected void setUp() throws Exception {
  super.setUp();

  Instances temp = new Instances(m_Instances);
  for (int j = 0; j < 2; j++) {
    for (int i = 0; i < temp.numInstances(); i++) {
      m_Instances.add(temp.instance(i));
    }
  }

  // now just filter the instances to convert String attributes
  // and binarize nominal attributes
  StringToNominal stn = new StringToNominal();
  stn.setAttributeRange("first-last");
  stn.setInputFormat(m_Instances);
  m_Instances = Filter.useFilter(m_Instances, stn);
  NominalToBinary ntb = new NominalToBinary();
  ntb.setInputFormat(m_Instances);
  m_Instances = Filter.useFilter(m_Instances, ntb);

  // remove the last column (date attribute)
  Remove r = new Remove();
  r.setAttributeIndices("last");
  r.setInputFormat(m_Instances);
  m_Instances = Filter.useFilter(m_Instances, r);
}
 
开发者ID:dsibournemouth,项目名称:autoweka,代码行数:27,代码来源:EMImputationTest.java

示例3: nominalToBinary

import weka.filters.unsupervised.attribute.NominalToBinary; //导入依赖的package包/类
/**
 * turns on nominal to binary filtering
 * if there are not only numeric attributes
 */
private Instances nominalToBinary( Instances insts ) throws Exception {
  boolean onlyNumeric = true;
  for (int i = 0; i < insts.numAttributes(); i++) {
    if (i != insts.classIndex()) {
      if (!insts.attribute(i).isNumeric()) {
        onlyNumeric = false;
        break;
      }
    }
  }

  if (!onlyNumeric) {
    m_NominalToBinary = new NominalToBinary();
    m_NominalToBinary.setInputFormat(insts);
    insts = Filter.useFilter(insts, m_NominalToBinary);
  }
  return insts;
}
 
开发者ID:williamClanton,项目名称:jbossBA,代码行数:23,代码来源:LibLINEAR.java

示例4: buildClassifier

import weka.filters.unsupervised.attribute.NominalToBinary; //导入依赖的package包/类
/**
 * Builds the logistic regression using LogitBoost.
 *
 * @param data the training data
 * @throws Exception if something goes wrong
 */
public void buildClassifier(Instances data) throws Exception {

  // can classifier handle the data?
  getCapabilities().testWithFail(data);

  // remove instances with missing class
  data = new Instances(data);
  data.deleteWithMissingClass();

  // replace missing values
  m_ReplaceMissingValues = new ReplaceMissingValues();
  m_ReplaceMissingValues.setInputFormat(data);
  data = Filter.useFilter(data, m_ReplaceMissingValues);

  // convert nominal attributes
  m_NominalToBinary = new NominalToBinary();
  m_NominalToBinary.setInputFormat(data);
  data = Filter.useFilter(data, m_NominalToBinary);

  // create actual logistic model
  m_boostedModel =
    new LogisticBase(m_numBoostingIterations, m_useCrossValidation,
      m_errorOnProbabilities);
  m_boostedModel.setMaxIterations(m_maxBoostingIterations);
  m_boostedModel.setHeuristicStop(m_heuristicStop);
  m_boostedModel.setWeightTrimBeta(m_weightTrimBeta);
  m_boostedModel.setUseAIC(m_useAIC);
  m_boostedModel.setNumDecimalPlaces(m_numDecimalPlaces);

  // build logistic model
  m_boostedModel.buildClassifier(data);
}
 
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:39,代码来源:SimpleLogistic.java

示例5: buildClassifier

import weka.filters.unsupervised.attribute.NominalToBinary; //导入依赖的package包/类
/**
    * Builds the logistic regression using LogitBoost.
    * @param data the training data
    * @throws Exception if something goes wrong 
    */
   public void buildClassifier(Instances data) throws Exception {

     // can classifier handle the data?
     getCapabilities().testWithFail(data);

     // remove instances with missing class
     data = new Instances(data);
     data.deleteWithMissingClass();

//replace missing values
m_ReplaceMissingValues = new ReplaceMissingValues();
m_ReplaceMissingValues.setInputFormat(data);
data = Filter.useFilter(data, m_ReplaceMissingValues);

//convert nominal attributes
m_NominalToBinary = new NominalToBinary();
m_NominalToBinary.setInputFormat(data);
data = Filter.useFilter(data, m_NominalToBinary);

//create actual logistic model
m_boostedModel = new LogisticBase(m_numBoostingIterations, m_useCrossValidation, m_errorOnProbabilities);
m_boostedModel.setMaxIterations(m_maxBoostingIterations);
m_boostedModel.setHeuristicStop(m_heuristicStop);
       m_boostedModel.setWeightTrimBeta(m_weightTrimBeta);
       m_boostedModel.setUseAIC(m_useAIC);

//build logistic model
m_boostedModel.buildClassifier(data);
   }
 
开发者ID:dsibournemouth,项目名称:autoweka,代码行数:35,代码来源:SimpleLogistic.java

示例6: testFilterWrappingAggregateableClassifier

import weka.filters.unsupervised.attribute.NominalToBinary; //导入依赖的package包/类
@Test
public void testFilterWrappingAggregateableClassifier() throws Exception {
  Instances train = new Instances(new BufferedReader(new StringReader(
    CorrelationMatrixMapTaskTest.IRIS)));

  train.setClassIndex(train.numAttributes() - 1);
  WekaClassifierMapTask task = setupAggregateableBatchClassifier();

  // Single filter with non-incremental Aggregateable classifier
  Filter oneF = new Remove();

  Filter[] filters = new Filter[1];
  filters[0] = oneF;
  task.setFiltersToUse(filters);

  task.setup(new Instances(train, 0));

  Classifier wrapped = task.getClassifier();
  assertTrue(wrapped instanceof AggregateableFilteredClassifier);

  // multiple filters with non-incremental Aggregateable classifier
  filters = new Filter[2];
  Filter twoF = new NominalToBinary();
  filters[0] = twoF;
  filters[1] = oneF;
  task.setFiltersToUse(filters);

  task.setup(new Instances(train, 0));

  wrapped = task.getClassifier();
  assertTrue(wrapped instanceof AggregateableFilteredClassifier);
  Filter f = ((AggregateableFilteredClassifier) wrapped)
    .getPreConstructedFilter();
  assertTrue(f instanceof MakePreconstructedFilter);

  // base filter should be a MultiFilter
  Filter f2 = ((MakePreconstructedFilter) f).getBaseFilter();
  assertTrue(f2 instanceof MultiFilter);

  // single filter with incremental Aggregateable classifier
  task = setupAggregateableIncrementalClassifier();
  filters = new Filter[1];
  filters[0] = oneF;
  task.setFiltersToUse(filters);
  task.setup(new Instances(train, 0));

  wrapped = task.getClassifier();

  assertTrue(wrapped instanceof AggregateableFilteredClassifierUpdateable);

  // single MakePreconstructedFilter
  assertTrue(((AggregateableFilteredClassifierUpdateable) wrapped)
    .getPreConstructedFilter() instanceof MakePreconstructedFilter);

  f = ((AggregateableFilteredClassifierUpdateable) wrapped)
    .getPreConstructedFilter();
  assertTrue(((MakePreconstructedFilter) f).getBaseFilter() instanceof Remove);

  // multiple filters with incremental Aggregateable classifier
  filters = new Filter[2];
  filters[0] = twoF;
  filters[1] = oneF;
  task.setFiltersToUse(filters);
  task.setup(new Instances(train, 0));

  wrapped = task.getClassifier();
  assertTrue(wrapped instanceof AggregateableFilteredClassifierUpdateable);
  assertTrue(((AggregateableFilteredClassifierUpdateable) wrapped)
    .getPreConstructedFilter() instanceof MakePreconstructedFilter);
  f = ((AggregateableFilteredClassifierUpdateable) wrapped)
    .getPreConstructedFilter();
  assertTrue(((MakePreconstructedFilter) f).getBaseFilter() instanceof MultiFilter);
}
 
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:74,代码来源:WekaClassifierTaskTest.java

示例7: MultilayerPerceptron

import weka.filters.unsupervised.attribute.NominalToBinary; //导入依赖的package包/类
/**
 * The constructor.
 */
public MultilayerPerceptron() {
  m_instances = null;
  m_currentInstance = null;
  m_controlPanel = null;
  m_nodePanel = null;
  m_epoch = 0;
  m_error = 0;

  m_outputs = new NeuralEnd[0];
  m_inputs = new NeuralEnd[0];
  m_numAttributes = 0;
  m_numClasses = 0;
  m_neuralNodes = new NeuralConnection[0];
  m_selected = new ArrayList<NeuralConnection>(4);
  m_nextId = 0;
  m_stopIt = true;
  m_stopped = true;
  m_accepted = false;
  m_numeric = false;
  m_random = null;
  m_nominalToBinaryFilter = new NominalToBinary();
  m_sigmoidUnit = new SigmoidUnit();
  m_linearUnit = new LinearUnit();
  // setting all the options to their defaults. To completely change these
  // defaults they will also need to be changed down the bottom in the
  // setoptions function (the text info in the accompanying functions should
  // also be changed to reflect the new defaults
  m_normalizeClass = true;
  m_normalizeAttributes = true;
  m_autoBuild = true;
  m_gui = false;
  m_useNomToBin = true;
  m_driftThreshold = 20;
  m_numEpochs = 500;
  m_valSize = 0;
  m_randomSeed = 0;
  m_hiddenLayers = "a";
  m_learningRate = .3;
  m_momentum = .2;
  m_reset = true;
  m_decay = false;
}
 
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:46,代码来源:MultilayerPerceptron.java

示例8: buildClassifier

import weka.filters.unsupervised.attribute.NominalToBinary; //导入依赖的package包/类
/**
  * Builds the ensemble of perceptrons.
  *
  * @param insts the data to train the classifier with
  * @throws Exception if something goes wrong during building
  */
 public void buildClassifier(Instances insts) throws Exception {

   // can classifier handle the data?
   getCapabilities().testWithFail(insts);

   // remove instances with missing class
   insts = new Instances(insts);
   insts.deleteWithMissingClass();
   
   // Filter data
   m_Train = new Instances(insts);
   m_ReplaceMissingValues = new ReplaceMissingValues();
   m_ReplaceMissingValues.setInputFormat(m_Train);
   m_Train = Filter.useFilter(m_Train, m_ReplaceMissingValues);
   
   m_NominalToBinary = new NominalToBinary();
   m_NominalToBinary.setInputFormat(m_Train);
   m_Train = Filter.useFilter(m_Train, m_NominalToBinary);

   /** Randomize training data */
   m_Train.randomize(new Random(m_Seed));

   /** Make space to store perceptrons */
   m_Additions = new int[m_MaxK + 1];
   m_IsAddition = new boolean[m_MaxK + 1];
   m_Weights = new int[m_MaxK + 1];

   /** Compute perceptrons */
   m_K = 0;
 out:
   for (int it = 0; it < m_NumIterations; it++) {
     for (int i = 0; i < m_Train.numInstances(); i++) {
Instance inst = m_Train.instance(i);
if (!inst.classIsMissing()) {
  int prediction = makePrediction(m_K, inst);
  int classValue = (int) inst.classValue();
  if (prediction == classValue) {
    m_Weights[m_K]++;
  } else {
    m_IsAddition[m_K] = (classValue == 1);
    m_Additions[m_K] = i;
    m_K++;
    m_Weights[m_K]++;
  }
  if (m_K == m_MaxK) {
    break out;
  }
}
     }
   }
 }
 
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:58,代码来源:VotedPerceptron.java

示例9: MultilayerPerceptron

import weka.filters.unsupervised.attribute.NominalToBinary; //导入依赖的package包/类
/**
 * The constructor.
 */
public MultilayerPerceptron() {
  m_instances = null;
  m_currentInstance = null;
  m_controlPanel = null;
  m_nodePanel = null;
  m_epoch = 0;
  m_error = 0;
  
  
  m_outputs = new NeuralEnd[0];
  m_inputs = new NeuralEnd[0];
  m_numAttributes = 0;
  m_numClasses = 0;
  m_neuralNodes = new NeuralConnection[0];
  m_selected = new FastVector(4);
  m_graphers = new FastVector(2);
  m_nextId = 0;
  m_stopIt = true;
  m_stopped = true;
  m_accepted = false;
  m_numeric = false;
  m_random = null;
  m_nominalToBinaryFilter = new NominalToBinary();
  m_sigmoidUnit = new SigmoidUnit();
  m_linearUnit = new LinearUnit();
  //setting all the options to their defaults. To completely change these
  //defaults they will also need to be changed down the bottom in the 
  //setoptions function (the text info in the accompanying functions should 
  //also be changed to reflect the new defaults
  m_normalizeClass = true;
  m_normalizeAttributes = true;
  m_autoBuild = true;
  m_gui = false;
  m_useNomToBin = true;
  m_driftThreshold = 20;
  m_numEpochs = 500;
  m_valSize = 0;
  m_randomSeed = 0;
  m_hiddenLayers = "a";
  m_learningRate = .3;
  m_momentum = .2;
  m_reset = true;
  m_decay = false;
}
 
开发者ID:dsibournemouth,项目名称:autoweka,代码行数:48,代码来源:MultilayerPerceptron.java

示例10: buildClassifier

import weka.filters.unsupervised.attribute.NominalToBinary; //导入依赖的package包/类
/**
  * Builds the ensemble of perceptrons.
  *
  * @param insts the data to train the classifier with
  * @throws Exception if something goes wrong during building
  */
 public void buildClassifier(Instances insts) throws Exception {

   // can classifier handle the data?
   getCapabilities().testWithFail(insts);

   // remove instances with missing class
   insts = new Instances(insts);
   insts.deleteWithMissingClass();
   
   // Filter data
   m_Train = new Instances(insts);
   m_ReplaceMissingValues = new ReplaceMissingValues();
   m_ReplaceMissingValues.setInputFormat(m_Train);
   m_Train = Filter.useFilter(m_Train, m_ReplaceMissingValues);
   
   m_NominalToBinary = new NominalToBinary();
   m_NominalToBinary.setInputFormat(m_Train);
   m_Train = Filter.useFilter(m_Train, m_NominalToBinary);

   /** Randomize training data */
   m_Train.randomize(new Random(m_Seed));

   /** Make space to store perceptrons */
   m_Additions = new int[m_MaxK + 1];
   m_IsAddition = new boolean[m_MaxK + 1];
   m_Weights = new int[m_MaxK + 1];

   /** Compute perceptrons */
   m_K = 0;
 out:
   for (int it = 0; it < m_NumIterations; it++) {
     for (int i = 0; i < m_Train.numInstances(); i++) {
Instance inst = m_Train.instance(i);
if (!inst.classIsMissing()) {
  int prediction = makePrediction(m_K, inst);
  int classValue = (int) inst.classValue();
  if (prediction == classValue) {
    m_Weights[m_K]++;
  } else {
    m_IsAddition[m_K] = (classValue == 1);
    m_Additions[m_K] = i;
    m_K++;
    m_Weights[m_K]++;
  }
  if (m_K == m_MaxK) {
    break out;
  }
}
     }
     if(Thread.interrupted())
       break;
   }
 }
 
开发者ID:dsibournemouth,项目名称:autoweka,代码行数:60,代码来源:VotedPerceptron.java

示例11: MultilayerPerceptron

import weka.filters.unsupervised.attribute.NominalToBinary; //导入依赖的package包/类
/**
 * The constructor.
 */
public MultilayerPerceptron() {
    m_instances = null;
    m_currentInstance = null;
    m_controlPanel = null;
    m_nodePanel = null;
    m_epoch = 0;
    m_error = 0;


    m_outputs = new NeuralEnd[0];
    m_inputs = new NeuralEnd[0];
    m_numAttributes = 0;
    m_numClasses = 0;
    m_neuralNodes = new NeuralConnection[0];
    m_selected = new FastVector(4);
    m_graphers = new FastVector(2);
    m_nextId = 0;
    m_stopIt = true;
    m_stopped = true;
    m_accepted = false;
    m_numeric = false;
    m_random = null;
    m_nominalToBinaryFilter = new NominalToBinary();
    m_sigmoidUnit = new SigmoidUnit();
    m_linearUnit = new LinearUnit();
    //setting all the options to their defaults. To completely change these
    //defaults they will also need to be changed down the bottom in the
    //setoptions function (the text info in the accompanying functions should
    //also be changed to reflect the new defaults
    m_normalizeClass = true;
    m_normalizeAttributes = true;
    m_autoBuild = true;
    m_gui = false;
    m_useNomToBin = true;
    m_driftThreshold = 20;
    m_numEpochs = 500;
    m_valSize = 0;
    m_randomSeed = 0;
    m_hiddenLayers = "a";
    m_learningRate = .3;
    m_momentum = .2;
    m_reset = true;
    m_decay = false;
}
 
开发者ID:williamClanton,项目名称:jbossBA,代码行数:48,代码来源:MultilayerPerceptron.java

示例12: buildClassifier

import weka.filters.unsupervised.attribute.NominalToBinary; //导入依赖的package包/类
/**
 * Method for building the classifier.
 * 
 * @param data the set of training instances.
 * @throws Exception if the classifier can't be built successfully.
 */
public void buildClassifier(Instances data) throws Exception {
  reset();
  
  // can classifier handle the data?
  getCapabilities().testWithFail(data);
  
  data = new Instances(data);
  data.deleteWithMissingClass();
  
  if (data.numInstances() > 0 && !m_dontReplaceMissing) {
    m_replaceMissing = new ReplaceMissingValues();
    m_replaceMissing.setInputFormat(data);
    data = Filter.useFilter(data, m_replaceMissing);
  }
  
  // check for only numeric attributes
  boolean onlyNumeric = true;
  for (int i = 0; i < data.numAttributes(); i++) {
    if (i != data.classIndex()) {
      if (!data.attribute(i).isNumeric()) {
        onlyNumeric = false;
        break;
      }
    }
  }
  
  if (!onlyNumeric) {
    m_nominalToBinary = new NominalToBinary();
    m_nominalToBinary.setInputFormat(data);
    data = Filter.useFilter(data, m_nominalToBinary);
  }
  
  if (!m_dontNormalize && data.numInstances() > 0) {

    m_normalize = new Normalize();
    m_normalize.setInputFormat(data);
    data = Filter.useFilter(data, m_normalize);
  }
  
  m_weights = new double[data.numAttributes() + 1];
  m_data = new Instances(data, 0);
  
  if (data.numInstances() > 0) {
    train(data);    
  }
}
 
开发者ID:williamClanton,项目名称:jbossBA,代码行数:53,代码来源:SPegasos.java

示例13: buildClassifier

import weka.filters.unsupervised.attribute.NominalToBinary; //导入依赖的package包/类
/**
  * Builds the classifier
  *
  * @param insts the data to train the classifier with
  * @throws Exception if something goes wrong during building
  */
 public void buildClassifier(Instances insts) throws Exception {

   // can classifier handle the data?
   getCapabilities().testWithFail(insts);

   // remove instances with missing class
   insts = new Instances(insts);
   insts.deleteWithMissingClass();
   
   // Filter data
   m_Train = new Instances(insts);
   
   m_ReplaceMissingValues = new ReplaceMissingValues();
   m_ReplaceMissingValues.setInputFormat(m_Train);
   m_Train = Filter.useFilter(m_Train, m_ReplaceMissingValues);
   m_NominalToBinary = new NominalToBinary();
   m_NominalToBinary.setInputFormat(m_Train);
   m_Train = Filter.useFilter(m_Train, m_NominalToBinary);

   /** Randomize training data */
   if(m_Seed != -1) {
     m_Train.randomize(new Random(m_Seed));
   }

   /** Make space to store weights */
   m_predPosVector = new double[m_Train.numAttributes()];

   if(m_Balanced) {
     m_predNegVector = new double[m_Train.numAttributes()];
   }

   /** Initialize the weights to starting values **/
   for(int i = 0; i < m_Train.numAttributes(); i++)
     m_predPosVector[i] = m_defaultWeight;

   if(m_Balanced) {
     for(int i = 0; i < m_Train.numAttributes(); i++) {
m_predNegVector[i] = m_defaultWeight;
     }
   }

   /** Set actual prediction threshold **/
   if(m_Threshold<0) {
     m_actualThreshold = (double)m_Train.numAttributes()-1;
   } else {
     m_actualThreshold = m_Threshold;
   }

   m_Mistakes=0;

   /** Compute the weight vectors **/
   if(m_Balanced) {
     for (int it = 0; it < m_numIterations; it++) {
for (int i = 0; i < m_Train.numInstances(); i++) {
  actualUpdateClassifierBalanced(m_Train.instance(i));
}
     }
   } else {
     for (int it = 0; it < m_numIterations; it++) {
for (int i = 0; i < m_Train.numInstances(); i++) {
  actualUpdateClassifier(m_Train.instance(i));
}
     }
   }
 }
 
开发者ID:williamClanton,项目名称:jbossBA,代码行数:72,代码来源:Winnow.java


注:本文中的weka.filters.unsupervised.attribute.NominalToBinary类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。