首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >决策树DecisionTree

决策树DecisionTree

作者头像
AI拉呱
发布于 2021-01-14 09:49:52
发布于 2021-01-14 09:49:52
4150
举报

决策树Python代码实现

1.DecisionTree.py

代码语言:javascript
复制
#! /usr/bin/env python2.8
# -*- coding: utf-8 -*-
# __author__ = "errrolyan"
# __Date__: 18-12-10
# __Describe__ = "决策树ID3算法算法Python实现版本”
import math

#find item in a list
def find(item, list):
    for i in list:
        if item(i): 
            return True
        else:
            return False

#find most common value for an attribute
def majority(attributes, data, target):
    #find target attribute
    valFreq = {}
    #find target in data
    index = attributes.index(target)
    #calculate frequency of values in target attr
    for tuple in data:
        if (tuple[index] in valFreq.keys()):
            valFreq[tuple[index]] += 1 
        else:
            valFreq[tuple[index]] = 1
    max = 0
    major = ""
    for key in valFreq.keys():
        if valFreq[key]>max:
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2018/12/12 ,如有侵权请联系 cloudcommunity@tencent.com 删除
目录
  • 决策树Python代码实现
    • 1.DecisionTree.py
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档