📄 decisiontreenode.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)
* @author Rolf Rossius
* @author Michael Thess
* @version 1.1
*/
package com.prudsys.pdm.Models.Classification.DecisionTree;
import com.prudsys.pdm.Adapters.PmmlVersion20.False;
import com.prudsys.pdm.Adapters.PmmlVersion20.Node;
import com.prudsys.pdm.Adapters.PmmlVersion20.ScoreDistribution;
import com.prudsys.pdm.Adapters.PmmlVersion20.True;
import com.prudsys.pdm.Core.CategoricalAttribute;
import com.prudsys.pdm.Core.Category;
import com.prudsys.pdm.Core.MiningAttribute;
import com.prudsys.pdm.Core.MiningDataSpecification;
import com.prudsys.pdm.Core.MiningException;
import com.prudsys.pdm.Core.MiningMatrixElement;
import com.prudsys.pdm.Core.MiningTreeNode;
import com.prudsys.pdm.Core.NumericAttribute;
import com.prudsys.pdm.Core.PmmlPresentable;
import com.prudsys.pdm.Input.MiningVector;
import com.prudsys.pdm.Input.Predicates.ConstantPredicate;
import com.prudsys.pdm.Input.Predicates.Predicate;
import com.prudsys.pdm.Models.Supervised.Classifier;
/**
* Node of a decision tree. <p>
*
* From PDM CWM extension. <p>
*
* Superclasses:
* <ul>
* <li> MiningTreeNode
* </ul>
*
* In addition, functionality from PMML was added.
* It corresponds to the PMML element Node.
*
* @see DecisionTreeMiningModel
* @see com.prudsys.pdm.Adapters.PmmlVersion20.Node
*/
public class DecisionTreeNode extends MiningTreeNode implements Classifier, PmmlPresentable, MiningMatrixElement
{
// -----------------------------------------------------------------------
// Variables declarations
// -----------------------------------------------------------------------
/** Reference to decision tree mining model. Required for NDTs. */
protected DecisionTreeMiningModel decisionTreeModel = null;
/** Meta data. */
protected MiningDataSpecification metaData;
/** Target attribute. */
protected MiningAttribute target;
/** Predicate for evaluation. */
protected Predicate predicate;
/** Score of node. */
protected double score = Category.MISSING_VALUE;
/** Class distribution of node. */
protected double[] distribution;
/** Assign distribution category names to distribution classes. */
protected String[] distribCategNames;
/** Cumulated counts. */
protected double[] cumulatedRecordCountThis;
/** Cumulated counts. */
protected double[] cumulatedRecordCountOther;
/** Total counts. */
protected double[] totalRecordCountThis;
/** Total counts. */
protected double[] totalRecordCountOther;
// -----------------------------------------------------------------------
// Getter and setter methods
// -----------------------------------------------------------------------
/**
* Returns reference to DT model that owns this node.
*
* @return DT model that owns this node, null if not set
*/
public DecisionTreeMiningModel getDecisionTreeModel()
{
return decisionTreeModel;
}
/**
* Sets reference to DT model that owns this node.
*
* @param decisionTreeModel new DT model owning this node, null if not defined
*/
public void setDecisionTreeModel(DecisionTreeMiningModel decisionTreeModel)
{
this.decisionTreeModel = decisionTreeModel;
}
/**
* Returns predicate.
*
* @return predicate
*/
public Predicate getPredicate()
{
return predicate;
}
/**
* Sets new predicate.
*
* @param predicate new predicate
*/
public void setPredicate(Predicate predicate)
{
this.predicate = predicate;
}
/**
* Returns meta data.
*
* @return meta data
*/
public MiningDataSpecification getMetaData()
{
return metaData;
}
/**
* Sets meta data.
*
* @param metaData meta data to set
*/
public void setMetaData(MiningDataSpecification metaData)
{
this.metaData = metaData;
}
/**
* Returns target attribute.
*
* @return target attribute
*/
public MiningAttribute getTarget()
{
return target;
}
/**
* Sets target attribute.
*
* @param target new target attribute
*/
public void setTarget(MiningAttribute target)
{
this.target = target;
}
/**
* Returns score value.
*
* @return score value
*/
public double getScore()
{
return score;
}
/**
* Sets new score value.
*
* @param score new score value
*/
public void setScore(double score)
{
this.score = score;
}
/**
* Returns score value as string.
*
* @return string of score value
*/
protected String getScoreString() {
String sScore;
if(target instanceof CategoricalAttribute)
{
Category category = ((CategoricalAttribute)target).getCategory(score);
if(category == null) sScore = "meaningless";
else if(category.getValue() != null) sScore = category.getValue().toString();
else sScore = category.getDisplayValue();
}
else
sScore = Double.toString(score);
return sScore;
}
/**
* Returns class distribution of node.
*
* @return class distribution of node
*/
public double[] getDistribution()
{
return distribution;
}
/**
* Sets class distribution of node.
*
* @param distribution new class distribution of node
*/
public void setDistribution(double[] distribution)
{
this.distribution = distribution;
}
/**
* Returns the category names of distribution indexes.
*
* @return category names of distribution indexes
*/
public String[] getDistribCategNames()
{
return distribCategNames;
}
/**
* Sets category names to distribution indexes.
*
* @param distribCategNames new category names of distribution indexes
*/
public void setDistribCategNames(String[] distribCategNames)
{
this.distribCategNames = distribCategNames;
}
/**
* Gets node record count.
*
* @return recordCount
*/
public double getRecordCount() {
if(distribution==null || distribution.length==0)
return 0.0;
double recordCount = 0.0;
for(int i=0; i < distribution.length; i++)
recordCount += distribution[i];
return recordCount;
}
/**
* Get node cumulated record count.
*
* @return distribution
*/
public double[] getCumulatedRecordCountThis()
{
return cumulatedRecordCountThis;
}
/**
* Set node cumulated record count.
*
* @param cumulatedRecordCountThis distribution
*/
public void setCumulatedRecordCountThis(double[] cumulatedRecordCountThis)
{
this.cumulatedRecordCountThis = cumulatedRecordCountThis;
}
/**
* Get node cumulated record count.
*
* @return distribution
*/
public double[] getCumulatedRecordCountOther()
{
return cumulatedRecordCountOther;
}
/**
* Set node cumulated record count.
*
* @param cumulatedRecordCountOther distribution
*/
public void setCumulatedRecordCountOther(double[] cumulatedRecordCountOther)
{
this.cumulatedRecordCountOther = cumulatedRecordCountOther;
}
/**
* Get node total record count.
*
* @return distribution
*/
public double[] getTotalRecordCountThis()
{
return totalRecordCountThis;
}
/**
* Set node total record count.
*
* @param totalRecordCountThis distribution
*/
public void setTotalRecordCountThis(double[] totalRecordCountThis)
{
this.totalRecordCountThis = totalRecordCountThis;
}
/**
* Get node total record count.
*
* @return distribution
*/
public double[] getTotalRecordCountOther()
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -