Python代码实现加权投票融合多分类模型 | CNN和GRU模型融合
import numpy as np
def weighted_voting(acc_cnn, acc_gru): weights = [0.85, 0.97, 0.96, 0.97, 0.98, 1.0, 0.96, 1.0] acc_cnn = np.array(acc_cnn) acc_gru = np.array(acc_gru)
# Calculate weighted average
weighted_avg = (weights[0] * acc_cnn + weights[1] * acc_gru) / sum(weights)
# Perform classification based on weighted average
predictions = np.argmax(weighted_avg)
return predictions
Example usage
acc_cnn = [0.85, 0.97, 0.96, 0.97, 0.98, 1.0, 0.96, 1.0] acc_gru = [0.95, 0.9, 0.94, 0.97, 0.98, 1.0, 0.66, 1.0]
predictions = weighted_voting(acc_cnn, acc_gru) print(predictions)
原文地址: https://www.cveoy.top/t/topic/qBCd 著作权归作者所有。请勿转载和采集!