EZ LearnEZ Learn
Courses
EZ Board
Dashboard
All articles
ml-for-cyber-securitymlcsvoting-ensemblemodel-selection

Voting Ensembles, and Choosing Among the Four

A voting ensemble combines different kinds of models, not just many copies of one. In a real run in this unit, it actually scored below its own best individual member, which is exactly the lesson.

Ashish Revar25 October 20265 min read1 views

A random forest ensembles many trees. A voting ensemble goes further and combines entirely different model families, a logistic regression, a decision tree, and an SVM, letting them vote (or, with voting="soft", average their predicted probabilities). The idea is the same one behind the random forest, applied one level higher: models that make different kinds of mistakes cancel each other out more effectively than models that are all variations on the same algorithm.

voting_ensemble.py

from sklearn.ensemble import VotingClassifier
from sklearn.linear_model import LogisticRegression
from sklearn.tree import DecisionTreeClassifier
from sklearn.svm import SVC
from sklearn.model_selection import cross_val_score

voters = [
    ("logistic", LogisticRegression(max_iter=2000)),
    ("tree", DecisionTreeClassifier(max_depth=5, random_state=11)),
    ("svm", SVC(probability=True, random_state=11)),
]
ensemble = VotingClassifier(voters, voting="soft")

cv_scores = cross_val_score(ensemble, X_train, y_train, cv=5)
print(f"Ensemble CV accuracy: {cv_scores.mean():.4f} (+/- {cv_scores.std():.4f})")

ensemble.fit(X_train, y_train)
print(f"Ensemble test accuracy: {ensemble.score(X_test, y_test):.4f}")

Sample output

Ensemble CV accuracy: 0.8964 (+/- 0.0243)
Ensemble test accuracy: 0.9028

Individual test accuracies for comparison:
  logistic regression: 0.8583
  decision tree:        0.8667
  SVM:                   0.9306

Caution: A Voting Ensemble Is Not Automatically the Best Model

Notice, in the real run above, that the voting ensemble (0.9028) actually scored below the single best member, the SVM (0.9306). Voting helps most when the individual models are roughly comparable and make genuinely different mistakes; when one model is simply stronger than the others on this particular task, averaging it with weaker models can pull its score down. Always compare an ensemble against its own strongest individual member before assuming the ensemble wins.

Try it yourself: Compare All Six on Your Own Split

Using the same X_train, X_test, y_train, y_test throughout, train a decision tree, a random forest, an SVM, a gradient boosting classifier, an XGBoost classifier, and the voting ensemble above, and print each one's test accuracy and 5-fold CV mean. Which one wins changes with the dataset; running the comparison yourself, rather than trusting a rule of thumb, is the point of this exercise.

Choosing Among the Four, in Practice

ClassifierWhen to reach for it
Decision treeWhen you need a model a non-technical stakeholder can read directly, at some cost in raw accuracy
Random forestA strong, low-maintenance default for tabular security features; resistant to overfitting without much tuning
Support vector machineSmaller, cleaner datasets with a genuinely non-linear boundary; slower to train as the dataset grows
Gradient boosting (XGBoost)When squeezing out the last few points of accuracy matters and some tuning time is available; usually the strongest tabular option

No classifier wins every task; this unit trained all four on the same split specifically so you could compare, not guess.

Related to this topic

Continue learning

Reference material

eBook

ML for Cyber Security eBook

v1.0

Open resource

Cheatsheet

ML for Cyber Security Cheatsheet

v1.0

Open resource

MCQ Bank

ML for Cyber Security MCQ Bank

v1.0

Open resource

Question Bank

ML for Cyber Security Question Bank

v1.0

Open resource

Discussion

Loading comments…
More articlesTest your knowledge
EZ MentorAI · Free

Voting Ensembles, and Choosing Among the Four

Hi! I'm EZ Mentor

Your AI tutor for
Voting Ensembles, and Choosing Among the Four

Sign in to ask, it's free.

EZ Mentor is AI-powered · Answers may not be perfect · 10 free questions / day

EZ Learn

Structured learning across Reverse Engineering, Cloud Security and Research Methodology, plus games and practice tools. Free, and open to anyone.

Learn

  • Courses
  • EZ Articles
  • EZ Watch
  • EZ Bytes
  • EZ Talks
  • Community

Library & Exams

  • All Resources
  • eBooks & PDFs
  • Question Banks
  • Cheatsheets
  • All Exams
  • EZ Board

EZ Arena

  • EZ Games
  • Byte Rush
  • Firewall Defence
  • 3D Case Files
  • Live Quiz
  • ML Challenges

EZ Cyber Hygiene

  • Hygiene Journey
  • Cyber Safety Check
  • दिशा - Hygiene
  • सजग - Awareness
  • अभ्यास - Practice
  • Scammed? Call 1930

Platform

  • About
  • Contact
  • Events
  • Verify Certificate
  • Terms of Use
  • Disclaimer

© 2026 EZ Learn by EpochZero. Educational content for learning purposes.

Platform Lead: Ashish Revar