【发布时间】:2022-12-17 14:37:42
【问题描述】:
我确实参加了最高班。如何将Leaf类中的predict方法从取最大类更改为取样本均值?
class Leaf:
def __init__(self, data, labels):
self.data = data
self.labels = labels
self.prediction = self.predict()
def predict(self):
classes = {}
for label in self.labels:
if label not in classes:
classes[label] = 0
classes[label] += 1
prediction = max(classes, key=classes.get)
return prediction
测试代码:
%%time
n_trees = 1
my_forest_1 = random_forest(train_data, train_labels, n_trees)
【问题讨论】:
标签: python pandas machine-learning random-forest