⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 numerizationstream.java

📁 一个数据挖掘软件ALPHAMINERR的整个过程的JAVA版源代码
💻 JAVA
字号:
/*
 *    This program is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation; either version 2 of the License, or
 *    (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with this program; if not, write to the Free Software
 *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

/**
 * <p>Title: XELOPES</p>
 * <p>Description: Java Data Mining API. Supported standarts: <a href="http://www.dmg.org">Predictive Model Markup Language (PMML 2.0) </a>;  <a href="http://www.omg.org/cwm">DataMining specification for Common Warehouse Metamodel (OMG)</a>.</p>
 * <p>Copyright: Copyright (c) 2002-2004 prudsys AG</p>
 * <p>Company: prudsys, ZSoft</p>
 * @authorv Michael Thess
 * @version 1.2
 */
package com.prudsys.pdm.Transform.Special;

import com.prudsys.pdm.Core.CategoricalAttribute;
import com.prudsys.pdm.Core.MiningAttribute;
import com.prudsys.pdm.Core.MiningDataSpecification;
import com.prudsys.pdm.Core.MiningException;
import com.prudsys.pdm.Input.MiningInputStream;
import com.prudsys.pdm.Transform.MiningTransformationFactory;
import com.prudsys.pdm.Transform.MiningTransformationStep;
import com.prudsys.pdm.Transform.OneToOne.Identity;
import com.prudsys.pdm.Transform.OneToOne.Numerization;
import com.prudsys.pdm.Transform.OneToOne.NumerizationNumber;

/**
 * Realization of numerization for a given mining input stream.
 * All categorical attributes are numerized using the Numerization
 * transformation.
 */
public class NumerizationStream extends VectorTransformationStream {

  // -----------------------------------------------------------------------
  //  Variables declarations
  // -----------------------------------------------------------------------
  /** Use NumerizationNumber trafo instead of Numerization. */
  private boolean useNumerizationNumber = false;

  // -----------------------------------------------------------------------
  //  Constructors
  // -----------------------------------------------------------------------
  /**
   * Empty constructor.
   */
  public NumerizationStream() {
  }

  /**
   * Constructor for given stream.
   *
   * @param inputStream mining input stream for numerization
   */
  public NumerizationStream(MiningInputStream inputStream) {

    this.inputStream = inputStream;
  }

  // -----------------------------------------------------------------------
  //  Getter and setter methods
  // -----------------------------------------------------------------------
  /**
   * Use NumerizationNumber transformation instead of Numerization.
   *
   * @return true, if NumerizationNumber is used, false otherwise
   */
  public boolean isUseNumerizationNumber() {

    return useNumerizationNumber;
  }

  /**
   * Set use NumerizationNumber transformation instead of Numerization.
   *
   * @param useNumerizationNumber use NumerizationNumber transformation
   */
  public void setUseNumerizationNumber(boolean useNumerizationNumber) {

    this.useNumerizationNumber = useNumerizationNumber;
  }

  // -----------------------------------------------------------------------
  //  Transformation methods
  // -----------------------------------------------------------------------
  /**
   * Creates mining transformation step for numerization of categorical
   * attributes with respect to target attribute.
   *
   * @return mining transformation step
   * @exception MiningException no input stream defined
   */
  public MiningTransformationStep createMiningTransformationStep() throws MiningException  {

      // No mining input stream defined => exception:
      if (inputStream == null)
        throw new MiningException("No mining input stream defined");

      // Mining transformation factory:
      MiningTransformationFactory mtf = new MiningTransformationFactory();

      boolean notrans = true;
      MiningDataSpecification metaData = inputStream.getMetaData();
      for (int i = 0; i < metaData.getAttributesNumber(); i++) {
        // Get attribute and name:
        MiningAttribute mAtt = metaData.getMiningAttribute(i);
        String attName = mAtt.getName();

        // Don't use excluded attributes, if defined:
        if ( excludedAttributeNames != null && excludedAttributeNames.indexOf(attName) > -1)
          continue;

        // Add numerization if categorical attribute:
        if (mAtt instanceof CategoricalAttribute) {
          Numerization num = new Numerization();
          if (useNumerizationNumber)
            num = new NumerizationNumber();
          num.setSourceName( attName );
          num.setTargetName( "n_" + attName );
          mtf.addOneToOneMapping(num);
          notrans = false;
        };
      };

      // No transformations at all => just 1 required, use first attribute:
      if (notrans) {
        MiningAttribute mAtt = metaData.getMiningAttribute(0);
        Identity id          = new Identity();
        id.setSourceName( mAtt.getName() );
        mtf.addOneToOneMapping(id);
      };

      // Create transformation step for normalization:
      mts = mtf.createMiningTransformationStep();

      return mts;
  }

  // -----------------------------------------------------------------------
  //  Other methods
  // -----------------------------------------------------------------------
  /**
   * Returns numerization stream description.
   *
   * @returns description of numerization stream
   */
  public String toString() {

    String mess = "Numerization stream";
    if (useNumerizationNumber)
      mess = mess + " (NumerizationNumber)";
    mess = mess + ".";

    return mess;
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -