Loading

【机器学习实战】中featList = [example[i] for example in dataSet]

在学习机器学习实战决策树时,清单3.3出现了如下代码

featList = [example[i] for example in dataSet]

此为按照dataSet列表的列创建新列表featList

dataSet = [[1, 1, 'yes'],  #弄否浮出水面,是否有脚蹼,是否是鱼类
			[1, 1, 'yes'],
			[1, 0, 'no'],
			[0, 1, 'no'],
			[0, 1, 'no']]

执行代码i = 0时
结果为

[1, 1, 1, 0, 0]

i = 1时结果为

[1, 1, 0, 1, 1]

i = 2时结果为

['yes', 'yes', 'no', 'no', 'no']
posted @ 2021-01-09 22:19  ZZZLEI  阅读(19)  评论(0)    收藏  举报  来源