使用不同训练数据样本的分类器之间进行投票

问题描述 投票:0回答:1

我有一个包含 25 个特征、36000 个样本和 11 个标签的数据集。在 python 中,我想使用该数据集的不同样本训练一些分类器(具有相同类型或不同类型)。换句话说,每个分类器的训练数据样本与另一个模型的训练数据样本不同。当然,标签和特征是相同的,区别在于样本。然后我想在经过训练的分类器之间进行投票。 python 的现有函数使用相同的训练数据进行投票。如果您能帮助我解决 python 中的问题,我真的很感激。

我尝试使用Python的投票函数,但不幸的是这些函数接受所有基分类器相同的训练数据。

python classification voting
1个回答
0
投票

获取所有分类器的预测并将其附加到列表中:

on_hot_encoded = True  # Change this to False if your models don not produce one-hot encoded predictions.
outputs = []
for i in range(n_models):
    preds = models[i].predict(x_test)
    # If the predictions are one-hot enocded, this line of the code will convert them into categorical classes
    if one_hot_encoded:
        preds /= np.max(preds , axis=1).reshape(-1,1)
    outputs.append(preds)

outputs = np.array(outputs).T
utlimate = [max(set(list(row)), key = list(row).count) for row in outputs]
© www.soinside.com 2019 - 2024. All rights reserved.