我正在尝试构建一个朴素的贝叶斯分类器,它从文本文件中读取数据并输出到文本文件中,我的代码出现错误,说返回在函数之外,但是我看不到任何错误
# compute the relative frequencies of the
# 2nd explanatory variable taking on the
# values 'A', 'B' and 'C'
# and return a dictionary with these values
def getCatProbs(self, data):
a_count = 0
b_count = 0
c_count = 0
probs = {}
for row in data:
if row[1] == ">50K":
a_count = a_count + 1
if row[1] == "<=50K":
b_count = b_count + 1
else:
c_count = c_count + 1
probs[">50K"] = float(a_count)/len(data)
probs["<=50K"] = float(b_count)/len(data)
probs['C'] = float(c_count)/len(data)
return probs