find-s 算法
实现《机器学习》19页的FIND-S算法。
验证不同的实例顺序
开始于非最特殊假设。
#__author__=lx #__date__=2011.10.18 #__brief__=FIND-S, from 'machine learning' 19 def find_s(): x1 = [ 'sunny', 'warm', 'nurmal', 'strong', 'warm', 'same' , 1 ] x2 = [ 'sunny', 'warm', 'high', 'strong', 'warm', 'same' , 1 ] x3 = [ 'rainy', 'cold', 'high', 'strong', 'warm', 'change', 0 ] x4 = [ 'sunny', 'warm', 'high', 'strong', 'cool', 'change', 1 ] h = [ None, None, None, None, None, None ] h1 = [ 'sunny', 'cold', 'high', 'strong', 'warm', 'change' ] xa = [ x1, x2, x3, x4 ] xb = [ x2, x3, x4, x1 ] for i in xb: if i[6] == 1: index = 0 for j in i[ :-1 ]: if ( h1[index] == None ): h1[index] = j elif ( h1[index] != j ): h1[index] = '?' index += 1 for i in h1: print i if __name__ == "__main__": find_s();