机器学习实战—FPGrowth算法的实现

本文详述了FP-Growth算法的Java实现过程,包括构建FP树的数据结构,详细阐述了FPGrowth算法的实现步骤,并通过运行算法得出实验结果。
摘要由CSDN通过智能技术生成

本博文主要讲FPGrwoth算法的java实现,话不多说,直接上代码

1.首先构建FP树所需要的数据结构。

package com.jiang.fpGrowth;


import java.util.ArrayList;
import java.util.List;

import javax.swing.tree.TreeNode;

/**
 *类说明
 * @author jiangfeng
 * @since 2016年1月11日
 */
public class FP_TreeNode implements Comparable<FP_TreeNode> {
    private String nodeName;//节点名称
    private int count;//计数
    private FP_TreeNode parent;//父节点
    private List<FP_TreeNode> children;
    private FP_TreeNode nextNode;//下一个同名节点
    
    public FP_TreeNode(){}
    
    public FP_TreeNode(String name){
	nodeName=name;
    }

    public String getNodeName() {
        return nodeName;
    }

    public void setNodeName(String nodeName) {
        this.nodeName = nodeName;
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public FP_TreeNode getParent() {
        return parent;
    }

    public void setParent(FP_TreeNode parent) {
        this.parent = parent;
    }

    public List<FP_TreeNode> getChildren() {
        return children;
    }

    public void setChildren(List<FP_TreeNode> children) {
        this.children = children;
    }

    public FP_TreeNode getNextNode() {
        return nextNode;
    }

    public void setNextNode(FP_TreeNode nextNode) {
        this.nextNode = nextNode;
    }
    //添加孩子节点
    public void addChild(FP_TreeNode child){
	if(this.getChildren()==null){//孩子节点为空,新建链表,加入孩子节点,再作为该节点的孩子结合
	    List<FP_TreeNode> list=new ArrayList<>();
	    list.add(child);
	    this.setChildren(list);
	}
	else{
	    this.getChildren().add(child);
	}
    }
    
    //查找孩子节点
    public FP_TreeNode findChild(String name){
	List<FP_TreeNode> children=this.getChildren();
	if(children!=null){
	    for(FP_TreeNode child:children){
		if(child.getNodeName().equals(name)){
		    return child;
		}
	    }
	
  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值