for i in range(len(dataSet) - 1): # 遍历所有特征
# 获取dataSet的第i个所有特征-第i列全部特征
featList = [example[i] for example in dataSet
dataSet = [[0, 0, 0, 0, 'no'], # 数据集
[0, 0, 0, 1, 'no'],
[0, 1, 0, 1, 'yes'],
[0, 1, 1, 0, 'yes'],
[0, 0, 0, 0, 'no'],
[1, 0, 0, 0, 'no'],
[1, 0, 0, 1, 'no'],
[1, 1, 1, 1, 'yes'],
[1, 0, 1, 2, 'yes'],
[1, 0, 1, 2, 'yes'],
[2, 0, 1, 2, 'yes'],
[2, 0, 1, 1, 'yes'],
[2, 1, 0, 1, 'yes'],
[2, 1, 0, 2, 'yes'],
[2, 0, 0, 0, 'no']]
featList = [example[i] for example in dataSet:
将dataSet中的数据按行依次放入example中,然后取得example中的example[i]元素放入featList中
对数据的遍历一般都是按行,这种方法是取列的方法