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

📄 associationrulesalgorithm.java

📁 一个数据挖掘软件ALPHAMINERR的整个过程的JAVA版源代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 *    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.AssociationRules;

import java.util.Date;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Vector;

import com.prudsys.pdm.Core.CategoricalAttribute;
import com.prudsys.pdm.Core.Category;
import com.prudsys.pdm.Core.CategoryHierarchy;
import com.prudsys.pdm.Core.MiningAlgorithm;
import com.prudsys.pdm.Core.MiningException;
import com.prudsys.pdm.Core.MiningModel;
import com.prudsys.pdm.Core.MiningSettings;
import com.prudsys.pdm.Utils.IntHashtable;
import com.prudsys.pdm.Utils.IntVector;

/**
 * A class representing an Association Rules algorithm. Each implementation
 * should to extend this class and override only methods:
 * {@link #runAlgorithm() runAlgorithm()},
 * {@link #getAssociationRules()() getAssociationRules()} and
 * {@link #getLargeItemSets() getLargeItemSets()}
 *
 * Example (How to use):
 * <pre>
 * AssociationRulesSettings miningSettings = ...;
 * MiningInputStream miningInputStream = ...;
 * ApplicationInputSpecification applicationInputSpecification = ...;
 * AprioriOptimizedAlgorithm algorithm = new AprioriOptimizedAlgorithm();
 * algorithm.setMiningSettings( miningSettings );
 * algorithm.setApplicationInputSpecification( applicationInputSpecification );
 * algorithm.setMiningInputStream( miningInputStream );
 * AssociationRulesMiningModel model = algorithm.buildModel();<br>
 * </pre>
 * @author  <a href="mailto:vlntn@inbox.ru">Valentine Stepanenko</a>
 * @version 1.0
 * @see     com.prudsys.pdm.Core.MiningAlgorithm
 * @see     com.prudsys.pdm.Models.AssociationRules.Algorithms.Apriori.AprioriOptimizedAlgorithm
 * @see     com.prudsys.pdm.Models.AssociationRules.Algorithms.Apriori.AprioriHybridAlgorithm
 * @see     com.prudsys.pdm.Models.AssociationRules.Algorithms.Apriori.AprioriTidAlgorithm
 */
public abstract class AssociationRulesAlgorithm extends MiningAlgorithm
{
    // -----------------------------------------------------------------------
    //  Constants of taxonomy handling
    // -----------------------------------------------------------------------
    /** If taxonomy: remove nothing from rules. */
    public static final int TAX_REMOVE_NOTHING_FROM_RULE  = 0;

    /** If taxonomy: remove items from conlusion which are parents of premise items. */
    public static final int TAX_REMOVE_ANCEST_FROM_RULE  = 1;

    /** If taxonomy: remove ancestors and all parents within premise and conclusion. */
    public static final int TAX_REMOVE_ANCEST_AND_PARENTS_FROM_RULE = 2;

    // -----------------------------------------------------------------------
    //  Variables declarations
    // -----------------------------------------------------------------------
    /** Item ID attribute. */
    protected CategoricalAttribute categoryItemId;

    /** Transaction ID attribute. */
    protected CategoricalAttribute categoryTransactId;

    /** Minimum support. */
    protected double minimumSupport;

    /** Minimum confidence. */
    protected double minimumConfidence;

    /** Use taxonomy for creating rules. */
    protected boolean useTaxonomy = false;

    /** Taxonomy object for item ID attribute. */
    protected CategoryHierarchy itemIdTax = null;

    /** Defines pruning type of rules when taxonomy is used. */
    private int pruneRuleTaxType = TAX_REMOVE_ANCEST_FROM_RULE;

    /** Export all transaction IDs into PMML. */
    protected boolean exportTransactIds = true;

    /** Export names of item ID and transaction ID into PMML. */
    private int exportTransactItemNames = AssociationRulesMiningModel.EXPORT_PMML_NAME_TYPE_XELOPES;

    // -----------------------------------------------------------------------
    //  Constructor
    // -----------------------------------------------------------------------
    /**
     * Empty constructor.
     */
    public AssociationRulesAlgorithm()
    {
    }

    // -----------------------------------------------------------------------
    //  Getter and setter methods
    // -----------------------------------------------------------------------
    /**
     * Set use taxonomy of itemId attribute.
     *
     * @param useTaxonomy true if use, else false
     */
    public void setUseTaxonomy(boolean useTaxonomy)
    {
        this.useTaxonomy = useTaxonomy;
    }

    /**
     * Is taxonomy included?
     *
     * @return true if taxonomy used, otherwise false
     */
    public boolean isUseTaxonomy()
    {
        return useTaxonomy;
    }

    /**
     * Returns type of how to prune rules if taxonomy is used.
     *
     * @return type of rule pruning
     */
    public int getPruneRuleTaxType() {

      return pruneRuleTaxType;
    }

    /**
     * Sets type of how to prune rules if taxonomy is used.
     *
     * @param pruneRuleTaxType new type of rule pruning
     */
    public void setPruneRuleTaxType(int pruneRuleTaxType) {

      this.pruneRuleTaxType = pruneRuleTaxType;
    }

    /**
     * Write all transaction IDs into PMML (default: true)?
     *
     * @return true if write all transaction IDs into PMML, otherwise not
     */
    public boolean isExportTransactIds()
    {
      return exportTransactIds;
    }

    /**
     * Set export all transaction IDs into PMML (default: true).
     *
     * @param exportTransactIds true if export, otherwise false
     */
    public void setExportTransactIds(boolean exportTransactIds)
    {
      this.exportTransactIds = exportTransactIds;
    }

    /**
     * Returns type how item and transaction IDs are handled in PMML.
     *
     * @return PMML export type of item and transaction IDs
     */
    public int getExportTransactItemNames()
    {
      return exportTransactItemNames;
    }

    /**
     * Sets type how item and transaction IDs are handled in PMML.
     * This is because of an incompleteness in PMML 20: item and
     * transaction ID are not specially denoted in the mining schema.
     * This makes PMML20 association models not really applicable
     * to new data (except you use agreed names for the IDs). <p>
     *
     * There are three ways to handle this problem:
     * 1. Do nothing: conform with PMML 2.0 but lose of functionality,
     * 2. Use XELOPES PMML Extension: to AssociationModel two new attributes
     * 'itemIdName' (itemId) and 'transactIdName' (transactionId) are added,
     * 3. Use PMML 2.1 solution: transaction ID is marked as 'group'
     * in mining schema, so the other active attribute is the item ID
     * (currently not implemented in XELOPES).
     *
     * @param exportTransactItemNames PMML export type of item and transaction IDs
     */
    public void setExportTransactItemNames(int exportTransactItemNames)
    {
      this.exportTransactItemNames = exportTransactItemNames;
    }

    /**
     * Creates an instance of the association rules settings class that is required
     * to run the algorithm. The mining settings are assigned through the
     * setMiningSettings method.
     *
     * @return new instance of the association rules settings class of the algorithm
     */
    public MiningSettings createMiningSettings() {

      return new AssociationRulesSettings();
    }

    /**
     * Set association rules settings.
     *
     * @param miningSettings instance of AssociationRulesSettings
     * @exception IllegalArgumentException mining settings not association rules settings

⌨️ 快捷键说明

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