weka.filters.unsupervised.attribute.Standardize Java Examples

The following examples show how to use weka.filters.unsupervised.attribute.Standardize. 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: PrincipalComponents.java    From tsml with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Fill the correlation matrix
 */
private void fillCorrelation() throws Exception {
  m_correlation = new double[m_numAttribs][m_numAttribs];
  double [] att1 = new double [m_numInstances];
  double [] att2 = new double [m_numInstances];
  double corr;

  for (int i = 0; i < m_numAttribs; i++) {
    for (int j = 0; j < m_numAttribs; j++) {
      for (int k = 0; k < m_numInstances; k++) {
        att1[k] = m_trainInstances.instance(k).value(i);
        att2[k] = m_trainInstances.instance(k).value(j);
      }
      if (i == j) {
        m_correlation[i][j] = 1.0;
          // store the standard deviation
        m_stdDevs[i] = Math.sqrt(Utils.variance(att1));
      } else {
        corr = Utils.correlation(att1,att2,m_numInstances);
        m_correlation[i][j] = corr;
        m_correlation[j][i] = corr;
      }
    }
  }
  
  // now standardize the input data
  m_standardizeFilter = new Standardize();
  m_standardizeFilter.setInputFormat(m_trainInstances);
  m_trainInstances = Filter.useFilter(m_trainInstances, m_standardizeFilter);
}
 
Example #2
Source File: DataSetUtilsTest.java    From AILibs with GNU Affero General Public License v3.0 5 votes vote down vote up
public void updateIntermediateInstancesTest() throws Exception {
    DataSet data = DataSetUtils.getDataSetByID(FASHION_MNIST_ID);
    data = DataSetUtils.getStratifiedSplit(data, new Random(42), 0.1).get(0);
    WEKAFilter filter = new WEKAFilter(new Standardize());

    DataSet result = filter.applyFilter(data, false);
    System.out.println(result.getInstances().get(0).value(0));
    System.out.println(result.getIntermediateInstances().get(0).getDouble(0));

    System.out.println(result.getInstances().numAttributes());
    System.out.println(result.getIntermediateInstances().get(0).shapeInfoToString());

    Assert.assertEquals(result.getInstances().get(0).value(0),
            result.getIntermediateInstances().get(0).getDouble(0), 0.01);
}