generated from LufsX/Challenge-kNN
This commit is contained in:
+4
-2
@@ -41,8 +41,8 @@ name = "董秋"
|
|||||||
|
|
||||||
# 这里写自己的代码实现
|
# 这里写自己的代码实现
|
||||||
import operator
|
import operator
|
||||||
from collections import Counter
|
from collections import Counter
|
||||||
def classify0(inX, dataSet, labels, k=2):
|
def classify0(inX, dataSet, labels, k=1):
|
||||||
"""
|
"""
|
||||||
KNN 分类算法。
|
KNN 分类算法。
|
||||||
|
|
||||||
@@ -89,6 +89,8 @@ def classify0(inX, dataSet, labels, k=2):
|
|||||||
|
|
||||||
# 返回出现次数最多的类别的标签
|
# 返回出现次数最多的类别的标签
|
||||||
return classCount.most_common(1)[0][0]
|
return classCount.most_common(1)[0][0]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def load_data(file_path):
|
def load_data(file_path):
|
||||||
|
|||||||
Reference in New Issue
Block a user