weka之对id3实现可视化

参照J48,添加两个变量

    /*the node's id*/
    private int m_id;
    //static count to assign the ids
    private static int ms_count=0;

添加构造函数

  public Id3Visualise() 
  {
      m_id=ms_count++;
  }

继承Drawable接口

public class Id3Visualise 
  extends Classifier 
  implements TechnicalInformationHandler, Sourcable,Drawable

实现绘图相关函数

/**
   * return a string that describe a id3 tree
   * the out put is in dotty format
   * @return the graph dsicribed by a string
   */
  public String graph()
  {
      StringBuffer text=new StringBuffer();
      text.append("digraph ID3Tree{\n");
      text.append(graph(0));
      return text.toString()+"}\n";
  }

  /**
   *  Returns the type of graph this classifier
   *  represents.
   *  @return Drawable.TREE
   */   
  public int graphType() 
  {
      return Drawable.TREE;
  }


    /**
     * return a string that describe a id3 tree the out put is in dotty format
     * 
     * @param level
     *            the level at which the tree is to be printed
     */
    public String graph(int level) 
    {
        StringBuffer text = new StringBuffer();
        if (m_Attribute == null) 
        {
            if (Instance.isMissingValue(m_ClassValue)) 
            {
                text.append("N" + m_id + " [label=\"null\" " + "shape=box style=filled");
            }
            else 
            {
                text.append("N" + m_id + " [label=\""+m_ClassAttribute.value((int)m_ClassValue)+
                        "\" " + "shape=box style=filled");
            }
            text.append("]\n");
        }
        else
        {
            text.append("N"+m_id+" [label=\""+m_Attribute.name()+"\" ");
            text.append("]\n");
            for(int j=0;j<m_Attribute.numValues();j++)
            {
                text.append("N"+m_id+"->"+"N"+m_Successors[j].m_id+"[label=\"= "+
                        m_Attribute.value(j)+"\"]\n");
                text.append(m_Successors[j].graph(level+1));
            }
        }
        return text.toString();
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值