weka.filters.unsupervised.attribute.Normalize Java Examples

The following examples show how to use weka.filters.unsupervised.attribute.Normalize. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WekaNeurophSample.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {

        // create weka dataset from file
        DataSource dataSource = new DataSource("datasets/iris.arff");
        Instances wekaDataset = dataSource.getDataSet();
        wekaDataset.setClassIndex(4);

        // normalize dataset
        Normalize filter = new Normalize();
        filter.setInputFormat(wekaDataset);
        wekaDataset = Filter.useFilter(wekaDataset, filter);    
        
        // convert weka dataset to neuroph dataset
        DataSet neurophDataset = WekaDataSetConverter.convertWekaToNeurophDataset(wekaDataset, 4, 3);

        // convert back neuroph dataset to weka dataset
        Instances testWekaDataset = WekaDataSetConverter.convertNeurophToWekaDataset(neurophDataset);

        // print out all to compare
        System.out.println("Weka data set from file");
        printDataSet(wekaDataset);
        
        System.out.println("Neuroph data set converted from Weka data set");
        printDataSet(neurophDataset);
        
        System.out.println("Weka data set reconverted from Neuroph data set");
        printDataSet(testWekaDataset);

        System.out.println("Testing WekaNeurophClassifier");
        testNeurophWekaClassifier(wekaDataset);
    }
 
Example #2
Source File: BayesianLogisticRegression.java    From tsml with GNU General Public License v3.0 4 votes vote down vote up
/**
 * <pre>
 * (1)Initialize m_Beta[j] to 0.
 * (2)Initialize m_DeltaUpdate[j].
 * </pre>
 *
 * */
public void initialize() throws Exception {
  int numOfAttributes;
  int numOfInstances;
  int i;
  int j;

  Change = 0.0;

  //Manipulate Data
  if (NormalizeData) {
    m_Filter = new Normalize();
    m_Filter.setInputFormat(m_Instances);
    m_Instances = Filter.useFilter(m_Instances, m_Filter);
  }

  //Set the intecept coefficient.
  Attribute att = new Attribute("(intercept)");
  Instance instance;

  m_Instances.insertAttributeAt(att, 0);

  for (i = 0; i < m_Instances.numInstances(); i++) {
    instance = m_Instances.instance(i);
    instance.setValue(0, 1.0);
  }

  //Get the number of attributes
  numOfAttributes = m_Instances.numAttributes();
  numOfInstances = m_Instances.numInstances();
  ClassIndex = m_Instances.classIndex();
  iterationCounter = 0;

  //Initialize Arrays.
  switch (HyperparameterSelection) {
  case 1:
    HyperparameterValue = normBasedHyperParameter();

    if (debug) {
      System.out.println("Norm-based Hyperparameter: " + HyperparameterValue);
    }

    break;

  case 2:
    HyperparameterValue = CVBasedHyperparameter();

    if (debug) {
      System.out.println("CV-based Hyperparameter: " + HyperparameterValue);
    }

    break;
  }

  BetaVector = new double[numOfAttributes];
  Delta = new double[numOfAttributes];
  DeltaBeta = new double[numOfAttributes];
  Hyperparameters = new double[numOfAttributes];
  DeltaUpdate = new double[numOfAttributes];

  for (j = 0; j < numOfAttributes; j++) {
    BetaVector[j] = 0.0;
    Delta[j] = 1.0;
    DeltaBeta[j] = 0.0;
    DeltaUpdate[j] = 0.0;

    //TODO: Change the way it takes values.
    Hyperparameters[j] = HyperparameterValue;
  }

  DeltaR = new double[numOfInstances];
  R = new double[numOfInstances];

  for (i = 0; i < numOfInstances; i++) {
    DeltaR[i] = 0.0;
    R[i] = 0.0;
  }

  //Set the Prior interface to the appropriate prior implementation.
  if (PriorClass == GAUSSIAN) {
    m_PriorUpdate = new GaussianPriorImpl();
  } else {
    m_PriorUpdate = new LaplacePriorImpl();
  }
}