GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — 采用多数表决的方法决定该叶子节点的分类 · fciasth/pythonMLAction@4bc331c

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • 03
    • tree.py
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎03/tree.py‎

Copy file name to clipboardExpand all lines: 03/tree.py
+13-1Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from math import log
2+
import operator
23

34
def calcShannonEnt(dataSet):
45
#实例总数
@@ -68,4 +69,15 @@ def chooseBestFeatureToSplit(dataSet):
6869
bestFeature = i
6970
return bestFeature
7071
b = chooseBestFeatureToSplit(myDat)
71-
print(b)
72+
# print(b)
73+
#采用多数表决的方法决定该叶子节点的分类。
74+
def majorityCnt(classList):
75+
classCount ={}
76+
for vote in classList:
77+
if vote not in classCount.keys():
78+
classCount[vote] = 0
79+
classCount[vote] += 1
80+
sortedClassCount = sorted(classCount.items(),key=operator.itemgetter(1),reverse=True)
81+
return sortedClassCount[0][0]
82+
83+
#创建树的函数代码

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.