試圖做一個樸素的貝葉斯分類器但是我不斷收到錯誤,「返回超出函數」或「縮進不匹配和級別」。任何幫助是極大的讚賞,Python錯誤 - 貝葉斯分類器
繼承人我的代碼片段
if row[2] == 'C1':
self.c1_data.append(row)
else:
self.c2_data.append(row)
#Get relative frequencies from variables
#using the values in A ,B and C to
#return a dictionary
def getCatProbs(self, data):
a_count = 0
b_count = 0
c_count = 0
probs = {}
#For every row in the datafile
for row in data:
#Based on figure increase counts
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)
回報probs
我們不在這裏做*緊急*。從你的問題中刪除。 – jamylak 2013-04-26 10:06:15
請提供返回probs縮進的正確方法。 – 2013-04-26 10:08:05
:/是真的有必要嗎?只是尋找問題的幫助,我不能通過研究找出 – user2311700 2013-04-26 10:08:33