質問
ナイーブベイズクラス分類器を学習中に出現したソースコードです。
途中のcounts={}とcounts[label]の部分が何を意味しているのか分かりません。特にcounts={}の部分は削除しても実行結果が同じになるのですが何の意味があるのでしょうか。
該当のソースコード
Python
1X = np.array([[0,1,0,1], 2 [1,0,1,1], 3 [0,0,0,1], 4 [1,0,1,0]]) 5y = np.array([0,1,0,1]) 6 7counts={} 8for label in np.unique(y): 9 counts[label] = X[y == label].sum(axis=0) 10print("Feature counts:\n{}".format(counts))
実行結果
Python
1Feature counts: 2{0: array([0, 1, 0, 2]), 1: array([2, 0, 2, 1])}
> 特にcounts={}の部分は削除しても実行結果が同じになる
本当ですか?
回答1件
あなたの回答
tips
プレビュー