7.6 试编程实现AODE分类器,并以西瓜数据集3.0为训练集,对p151的‘测1’样本进行判别。
通过下列代码实现,结果为5.144433573365839和0.5121125686430099,显然应该划分为“好瓜”。
# -*- coding: utf-8 -*-
# exercise 7.6: AODE method to estimate likelihood based on first 6 DISCRETE attributes with Laplacian correction
# it avoids the last 2 attributes in continuous range,that would be more complex
import numpy as np
D = np.array([
[1, 1, 1, 1, 1, 1, 1],
[2, 1, 2, 1, 1, 1, 1],
[2, 1, 1, 1, 1, 1, 1],
[1, 1, 2, 1, 1, 1, 1],
[3, 1, 1, 1, 1, 1, 1],
[1, 2, 1, 1, 2, 2, 1],
[2, 2, 1, 2, 2, 2, 1],
[2, 2, 1, 1, 2, 1, 1],
[2, 2, 2, 2, 2, 1, 0],
[1, 3, 3, 1, 3, 2, 0],
[3, 3, 3, 3, 3, 1, 0],
[3, 1, 1, 3, 3, 2, 0],
[1, 2, 1, 2, 1, 1, 0],
[3, 2, 2, 2, 1, 1, 0],
[2, 2, 1, 1, 2, 2, 0],
[3, 1, 1, 3, 3, 1, 0],
[1, 1, 2, 2, 2, 1, 0]])
test = [1,1,1,1,1,1] # the predict sampl