【发布时间】:2021-03-13 04:06:44
【问题描述】:
我写了一个类来保存三个变量 column-name、cut-value 和 info-gain [1]。我在 for 循环中输入它,如下所示:
def best_split(X, y):
best_gain=0
Leaf_collection = []
for column in X:
....
info_gain = f(column, y)
if info_gain >= best_gain:
best_gain= info_gain
Leaf_colletion.append(Leaf(column, value, info_gain))
return Leaf_collection
现在,目的是在 iris 数据集中过滤掉这两种特殊情况,其中两个列值的 info_gain 相同:
column ; value ; info-gain
petal width (cm) ; 0.6 ; 0.5893309047577491
petal length (cm); 1.9 ; 0.5893309047577491
关于如何在同一个 for 循环中或之后找到一些最大值的任何建议。我尝试了一种找到最大值的方法,但遗憾的是,它只过滤了两个案例中的一个。 :(
非常感谢,
[1]
class Leaf:
def __init__(self, column, value, info_gain):
self.column = column //string
self.value = value // float
self.info_gain = info_gain //float
【问题讨论】:
标签: python pandas algorithm class decision-tree