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

📄 supervisedminingmodel.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.
 */

/**
 * Title: XELOPES Data Mining Library
 * Description: The XELOPES library is an open platform-independent and data-source-independent library for Embedded Data Mining.
 * Copyright: Copyright (c) 2002 Prudential Systems Software GmbH
 * Company: ZSoft (www.zsoft.ru), Prudsys (www.prudsys.com)
 * @author Valentine Stepanenko (valentine.stepanenko@zsoft.ru)
 * @version 1.0
 */

package com.prudsys.pdm.Models.Supervised;

import java.io.Reader;
import java.io.Writer;

import com.prudsys.pdm.Core.ApplicationAttribute;
import com.prudsys.pdm.Core.MiningException;
import com.prudsys.pdm.Core.MiningMatrixElement;
import com.prudsys.pdm.Core.MiningModel;
import com.prudsys.pdm.Input.MiningVector;

/**
  * Description of data produced by a predictive mining function. <p>
  *
  * From CWM Data Mining. <p>
  *
  * Superclasses:
  * <ul>
  *   <li> MiningModel
  * </ul>
  * Reference:
  * <ul>
  *   <li> <i>target</i>: References the "target" ApplicationAttribute. <br>
  *     - class: ApplicationAttribute <br>
  *     - defined by: SupervisedMiningModelReferencesTargetAttribute::target <br>
  *     - multiplicity: exactly one
  * </ul>
  *
  * Additions from PDM CWM extension. <p>
  *
  * References added:
  * <ul>
  *   <li> <i>classifier</i>: Reference Classifier as classification object. <br>
  *       - interface: Classifier <br>
  *       - multiplicity: exactly one
  * </ul>
  *
  * @see ApplicationAttribute
  * @see Classifier
  */
public class SupervisedMiningModel extends MiningModel
{
    // -----------------------------------------------------------------------
    //  Variables declarations
    // -----------------------------------------------------------------------
    /** The classifier object which does the real classification. */
    protected Classifier classifier;

    /** The target attribute as application attribute. */
    protected ApplicationAttribute target;

    // -----------------------------------------------------------------------
    //  Constructor
    // -----------------------------------------------------------------------
    /**
     * Default constructor.
     */
    public SupervisedMiningModel()
    {
    }

    // -----------------------------------------------------------------------
    //  Getter and setter methods
    // -----------------------------------------------------------------------
    /**
     * Returns classifier object.
     *
     * @return classifier object
     */
    public Classifier getClassifier()
    {
        return classifier;
    }

    /**
     * Sets classifier object.
     *
     * @param classifier new classifier
     */
    public void setClassifier(Classifier classifier)
    {
        this.classifier = classifier;
    }

    /**
     * Returns target attribute.
     *
     * @return target attribute
     */
    public ApplicationAttribute getTarget() {
        return target;
    }

    /**
     * Sets target attribute.
     *
     * @param target new target attribute
     */
    public void setTarget(ApplicationAttribute target) {
        this.target = target;
    }

    // -----------------------------------------------------------------------
    //  Application of model to new data
    // -----------------------------------------------------------------------
    /**
     * Applies supervised model to mining vector obtaining its score.
     * Meta data should correspond to that of training, including the
     * target attribute.
     *
     * @param miningVector mining vector to be classified
     * @return score of the mining vector
     * @throws MiningException if there are some errors when model is applied
     * @deprecated since version 1.1, use applyModelFunction instead
     */
    public double apply(MiningVector miningVector) throws MiningException
    {
       return applyModelFunction(miningVector);
    }

    /**
     * Applies function of supervised mining model to a mining vector. In general,
     * the meta data of the mining vector should be similar to the metaData
     * of this class. This ensures compatibility of training and
     * application data. Especially, the mining vector also should countain
     * the target attribute which was used for training.
     *
     * @param miningVector mining vector where the model should be applied
     * @return function value of the mining vector
     * @throws MiningException if there are some errors when model is applied
     */
    public double applyModelFunction(MiningVector miningVector)
        throws MiningException
    {
      // Run inner transformations (e.g. missing values replacement, outliers):
      if (miningTransform != null)
        miningVector = miningTransform.transform(miningVector);

      // Apply classifier:
      return classifier.apply( miningVector );
    }

    //<<Frank Xu, 09/11/2004
    //New methods to integrate with KBBI.
	public double deployModelFunction(MiningVector miningVector) throws MiningException
	{
		// Apply classifier:
		return classifier.apply( miningVector );
	}    
	
	//<<Frank J. Xu, 17/03/2005
	//If wekainstances of classifier is different from the one of scoring data,
	//error appears for MiningStream to Instance, overload above method to solve 
	//this problem.
	public double deployModelFunction(MiningVector miningVector, Object wekaInstances) throws MiningException
	{
		// Apply classifier:
		return classifier.apply( miningVector, wekaInstances);		
	}
	//Frank J. Xu, 17/03/2005>>
	
    //Frank Xu, 09/11/2004>>
	
    /**
     * General function of applying the supervised mining model to some data.
     * Not implemented.
     *
     * @param miningData mining data where the model should be applied
     * @return data resulting from the model application
     * @throws MiningException always thrown
     */
    public MiningMatrixElement applyModel(MiningMatrixElement miningData)
        throws MiningException {
      throw new MiningException("Not implemented.");
    }

    // -----------------------------------------------------------------------
    //  Methods of PMML handling
    // -----------------------------------------------------------------------
    /**
     * Creates PMML document from supervised mining model.
     *
     * @param writer writer for PMML document
     * @exception MiningException cannot write PMML document
     */
    public void writePmml(Writer writer) throws com.prudsys.pdm.Core.MiningException
    {
        throw new MiningException("not implemented");
    }

    /**
     * Reads supervised mining model from PMML document.
     *
     * @param reader reader of PMML document
     * @exception MiningException cannot read PMML model
     */
    public void readPmml(Reader reader) throws com.prudsys.pdm.Core.MiningException
    {
        throw new MiningException("not implemented");
    }

    /**
     * Creates PMML object from supervised mining model.
     *
     * @return PMML object of supervised mining model
     * @exception MiningException cannot create PMML model
     */
    public Object createPmmlObject() throws com.prudsys.pdm.Core.MiningException
    {
        throw new MiningException("not implemented");
    }

    /**
     * Gets supervised mining model from PMML object.
     *
     * @param pmmlObject PMML object containing supervised mining model
     * @exception MiningException cannot parse PMML model
     */
    public void parsePmmlObject(Object pmmlObject) throws com.prudsys.pdm.Core.MiningException
    {
        throw new MiningException("not implemented");
    }

    // -----------------------------------------------------------------------
    //  Further export methods
    // -----------------------------------------------------------------------
    /**
     * Writes supervised mining model into plain text.
     *
     * @param writer writer for plain text
     * @exception MiningException cannot write model as plain text
     */
    public void writePlainText(Writer writer) throws com.prudsys.pdm.Core.MiningException
    {
        throw new MiningException("not implemented");
    }

    /**
     * Returns string representation of supervised mining model.
     *
     * @return string representation of supervised mining model
     */
    public String toString()
    {
        return "Supervised mining model";
    }

    /**
     * Returns HTML string representation of supervised mining model.
     *
     * @return HTML string representation of supervised mining model
     */
    public String toHtmlString()
    {
        return toString();
    }
}

⌨️ 快捷键说明

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