Foundations to Frontier
Tests
D. Classical Machine Learning › D7 Ensemble Methods

Hard and Soft Voting Ensembles

A voting ensemble combines the predictions of several models. Hard voting takes the most common predicted label, and soft voting averages predicted probabilities. Condorcet's jury theorem explains when this helps: independent voters that are each better than chance become almost always right as a group. Correlated errors put a ceiling on the gain, and weak members can drag a vote below its best member. This page covers hard, soft and weighted voting, Condorcet's theorem and the optimal log-odds weights, the role of diversity and correlation, and when voting fails. In the exercises you implement the voting rules and verify Condorcet and optimal weighting; then you measure how error correlation caps the gain and test voting with four real classifiers.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Ask several experts

If five independent inspectors each catch a defect 70% of the time, a majority of them catches it 84% of the time. That is the core of ensemble learning: combine several imperfect models and let their errors cancel. Hard voting counts labels, and soft voting averages confidence. There is a catch: the inspectors must make different mistakes. Five copies of the same inspector are no better than one.

Wisdom of the crowd, and its limit
0.40.60.81number of voters →
majority accuracy with 11 voters: 82.7% (independent voters: 92.2%; one voter: 70%)
With independent voters better than chance, the majority approaches 100% (Condorcet's jury theorem). Shared errors put a ceiling on the gain: at high ρ, adding voters barely helps, because they all fail on the same cases. Below p = 0.5 the majority is worse than one voter, and more voters make it worse still.
Why engineers care

Redundancy with voting is a classic reliability pattern: triple-modular-redundant flight computers vote on outputs. In ML, voting is the simplest ensemble. It rarely hurts when the members are comparably good and diverse, and it is the foundation for bagging, random forests and stacking.

📝 Quick check (Level 0)
0/3 answered
  1. 1. Hard voting combines…
  2. 2. Voting helps most when members' errors are…
  3. 3. In the demo, high error correlation makes extra voters…

Level 1: Beginner

★★☆☆☆ Basic⏱ 25 minSecondary-school mathematics: arithmetic and elementary algebra.

Voting by hand

Condorcet with 5 independent voters at p = 0.7. The majority is right when at least 3 voters are right:

P = C(5,3)·0.7³·0.3² + C(5,4)·0.7⁴·0.3 + 0.7⁵ = 0.3087 + 0.3602 + 0.1681 = 0.837.

Hard and soft voting can disagree. Three models give P(class 1) = 0.1, 0.6 and 0.55.

  • Hard voting: two models say class 1, so it predicts 1.
  • Soft voting: the average is (0.1 + 0.6 + 0.55)/3 = 0.417, below 0.5, so it predicts 0.

The confident “class 0” model outweighs two lukewarm “class 1” models.

Weighted voting. One 90%-accurate expert and four 60%-accurate voters, all independent.

  • Optimal weights are wᵢ = log(pᵢ/(1 − pᵢ)): the expert gets log 9 = 2.20 and each weak voter log 1.5 = 0.41.
  • The four weak voters together (1.62) cannot outvote the expert (2.20), so the ensemble follows the expert. That is right, because a plain majority of these five is right only about 79% of the time.

The steps in plain English:

  1. Train several different models (different algorithms, features or data samples).
  2. Hard vote: take the most common label. Soft vote: average the probabilities (calibrate them first).
  3. Optionally weight members by validation performance, for example by log-odds of accuracy.
  4. Check on validation data that the ensemble beats its best member; drop members that drag it down.
📝 Quick check (Level 1)
0/3 answered
  1. 1. Majority accuracy of 3 independent 70% voters?
  2. 2. Soft vote of probabilities 0.1, 0.6, 0.55?
  3. 3. Optimal weight for a 90%-accurate independent voter?

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 35 minUndergraduate students and practising engineers.

Voting rules and why they work

Rules.

  • Hard (plurality) voting: ŷ = argmax over classes c of Σ wₘ·1[hₘ(x) = c].
  • Soft voting: ŷ = argmax over c of Σ wₘ·pₘ(c | x). It uses confidence, so it needs reasonably calibrated probabilities.
  • Ties: break by mean probability, by a fixed order, or use an odd number of voters.

Condorcet’s jury theorem (1785). For independent voters with common accuracy p above 1/2, the majority accuracy increases with M and tends to 1. If p is below 1/2 it tends to 0.

Optimal weights (Nitzan and Paroush, 1982). For independent voters with accuracies pᵢ, the weighted majority with wᵢ = log(pᵢ/(1 − pᵢ)) maximises the probability of a correct decision. It is a naive-Bayes combination of the votes.

Regression analogue. Averaging M predictors whose errors each have variance σ² and pairwise correlation ρ gives an averaged error variance of ρσ² + (1 − ρ)σ²/M. As M → ∞ this tends to ρσ², a floor set by correlation. The same mechanism limits classification voting (exercise 2).

Ambiguity decomposition (Krogh and Vedelsby, 1995). For squared loss, ensemble error = average member error − average “ambiguity” (spread of members around the ensemble). Diversity directly reduces error, but only if members stay accurate.

from sklearn.ensemble import VotingClassifier
vote = VotingClassifier([("lr", LogisticRegression()), ("knn", KNeighborsClassifier(15)),
                         ("tree", DecisionTreeClassifier(max_depth=4))], voting="soft").fit(X, y)
🐍 Exercise 1: voting rules and Condorcet
Implement weighted hard voting, weighted soft voting, Condorcet's majority probability and log-odds optimal weights; show that hard and soft voting can disagree and that log-odds weights beat a plain majority when one expert is much stronger.
📝 Quick check (Level 2)
0/3 answered
  1. 1. Variance of an average of M predictors with correlation ρ tends to…
  2. 2. Soft voting needs…
  3. 3. The ambiguity decomposition says ensemble error equals…

Level 3: Advanced

★★★★☆ Advanced⏱ 30 minGraduate level, with full derivations and proofs.

Theory

When voting fails.

  • Correlated errors: all members fail on the same hard cases. Exercise 2 (simulation): 25 voters at 70% reach 98.3% when independent, but only 74.2% at error correlation 0.6.
  • Unequal members: a plain vote gives a weak member as much say as a strong one, so weak, mutually correlated members can outvote the best one.
  • p below 1/2 (worse than chance): the majority is worse than one voter.

Diversity is not free. Making members diverse usually lowers their individual accuracy, and the ambiguity decomposition shows the trade-off explicitly. Bagging, random subspaces and random forests are recipes for generating diversity cheaply. Boosting creates members that focus on different examples. Stacking learns the combination rule.

Calibration matters for soft voting. Naive Bayes is typically over-confident and k-NN probabilities are coarse. Calibrating members (Platt scaling, isotonic regression) before averaging usually helps.

Interview questions.

  • Why might a voting ensemble be worse than its best member? Other members are much weaker and their errors are correlated with each other, so they outvote the best model where it is right. Weight members or drop the weak ones.
  • Hard or soft? Soft, if the probabilities are meaningful: it uses confidence and breaks ties gracefully. Hard voting is more robust to badly calibrated members.
📝 Quick check (Level 3)
0/3 answered
  1. 1. 25 voters at 70% with error correlation 0.6 reached about…
  2. 2. If every voter is worse than chance, majority voting…
  3. 3. Before soft voting, it often helps to…

Level 4: Expert

★★★★★ Expert⏱ 25 minResearchers: original papers and open problems.

Correlation, diversity and a real-world vote

History.

  • Condorcet’s Essai (1785) proved the jury theorem.
  • Galton (1907) observed the “wisdom of crowds” in an ox-weighing contest.
  • Nitzan and Paroush (1982) derived optimal weighted voting.
  • Hansen and Salamon (1990) applied voting to neural-network ensembles.
  • Krogh and Vedelsby (1995) gave the ambiguity decomposition.
  • Kittler et al. (1998) analysed combination rules (sum, product, majority).
  • Dietterich (2000) explained why ensembles work: statistical, computational and representational reasons.

Exercise 1.

  • Condorcet: 5 independent 70% voters reach 0.8369, and 51 reach 0.9986.
  • Hard and soft voting disagreed on the three-model example.
  • With one 90% expert and four 60% voters, plain majority scored 0.789 and log-odds weights 0.902.

Exercise 2(a). Majority-vote accuracy of 70%-accurate voters with correlated errors:

error correlation ρ M = 1 M = 5 M = 25
0 0.701 0.833 0.983
0.3 0.697 0.769 0.811
0.6 0.698 0.733 0.742

Exercise 2(b). Setup: a noisy “two moons” problem with 2 irrelevant features, n = 300, 10 repetitions. The table shows test accuracy.

logistic naive Bayes 15-NN depth-4 tree hard vote soft vote soft vote of 15-NN + tree
0.847 0.844 0.864 0.883 0.867 0.871 0.882
  • Correlation caps the gain. Independent voters approach perfection, while at ρ = 0.6, 25 voters add only 4 points over one.
  • With real models, voting did not beat the best member. The tree (0.883) beat both votes. The two linear-ish models (logistic, naive Bayes) are weaker and make similar mistakes, so they pull the vote toward their errors.
  • Soft voting edged out hard voting, as expected when probabilities carry information.
  • Even the best pair (15-NN + tree) only tied the tree. Voting helps when members are comparably strong and diverse; otherwise weight or select them (stacking, coming up).
🐍 Exercise 2 (research): correlated voters and a real vote
(a) Simulate majority voting of 70%-accurate voters with error correlation ρ in {0, 0.3, 0.6} for M = 1–25. (b) Train logistic regression, Gaussian naive Bayes, 15-NN and a depth-4 tree on noisy two-moons data and compare each with hard and soft voting (10 repetitions).

Voting in AI, robotics and aerospace

  • Triple-modular redundancy: flight computers and sensors vote to mask single faults.
  • Multi-model perception: combining detectors with different sensors (camera, lidar) whose failure modes differ.
  • Anomaly detection committees: several detectors flag an event only when enough agree.
  • Model averaging in forecasting and climate ensembles.

References

  1. Marquis de Condorcet (1785). Essai sur l’application de l’analyse à la probabilité des décisions rendues à la pluralité des voix.
  2. S. Nitzan, J. Paroush (1982). “Optimal decision rules in uncertain dichotomous choice situations.” International Economic Review 23(2).
  3. A. Krogh, J. Vedelsby (1995). “Neural network ensembles, cross validation, and active learning.” NeurIPS.
  4. J. Kittler, M. Hatef, R. P. W. Duin, J. Matas (1998). “On combining classifiers.” IEEE TPAMI 20(3).
  5. T. G. Dietterich (2000). “Ensemble methods in machine learning.” Multiple Classifier Systems, LNCS 1857.