Using Data Science to Predict Election Results
Two fictional pre-election polls disagree. One measures support for Candidate A at 52% and Candidate B at 48%; another suggests a narrower difference. Both were conducted before any ballots were counted. Should students simply choose the larger poll, average the two reports, or predict a winner? A careful data scientist first asks how respondents were selected, when the surveys took place and which electoral rules will determine the result.
Election forecasting uses available evidence and transparent assumptions to estimate uncertain future outcomes. It can organize historical results, opinion polls, expected participation and statistical models, but cannot decide an election before official counting and certification. A small change in estimated turnout may reverse a narrow forecast. Similarly, a poll can measure preferences imperfectly without providing a probability of victory.
This guide develops two practical mathematical investigations using only fictional candidates: a three-region turnout-weighted scenario and a four-election forecast-error comparison. You will also study sampling, margins of error, poll aggregation, forecasting methods, uncertainty, election systems and ethical research. No real student’s voting preference, party affiliation or personal data is required.
What you’ll learn: Distinguish polls from forecasts, calculate vote shares and approximate sampling uncertainty, model turnout scenarios, test historical errors and explain why a projection is not an official result.
Election Forecasting: Definitions and Important Differences
An opinion poll is an attempt to estimate views or intended choices within a specified population at a particular time. Its sampling method, question wording and respondent characteristics influence its usefulness. A forecast estimates a future outcome using data, assumptions and an analytical procedure. A projection may mean either a model’s estimated outcome or a media organization’s assessment using reported votes; always establish which meaning applies.
Only the relevant election authority can report or certify results through the applicable legal process. A statistical forecast is not a vote count. Model outputs may include vote-share estimates, turnout ranges, seat totals, probabilities or intervals, but no one model must provide all of them.
| Information | What it means | Example |
|---|---|---|
| Opinion poll | Estimate of preferences at a time | Survey support |
| Election forecast | Estimated future outcome | Modeled share |
| Projection | Defined model or reported-result assessment | Specify its meaning |
| Certified result | Officially established outcome | Election authority |
Election forecasting is educationally useful because it teaches uncertainty, survey research, statistical inference, critical reading and the testing of assumptions. Similar principles apply to weather, sports and health planning. For introductory methods, see Introduction to Data Science.

What Data Can Election Researchers Use?
Forecasters may consider credible opinion polls, official historical results, historical turnout, electoral geography, voting rules, public economic indicators, election timing, and documented errors in previous forecasts. Some research models use aggregated population measures when there is a defensible theory for including them. Not every model needs every variable, and more information is not automatically more informative.
Observed election returns differ from assumptions about future participation or changes in preferences. Historical vote shares can be a useful baseline while still becoming outdated after shifts in parties, boundaries, rules or electorate composition. Public turnout databases may report participation using registered voters or voting-age population, which can create different percentages.
The International IDEA Voter Turnout Database covers multiple countries and distinguishes registered-voter and voting-age-population measures. The MIT Election Data and Science Lab provides documented historical US election datasets. Both require checking source definitions, timing and completeness before comparing records.
| Evidence | Use in forecasting | Check before using |
|---|---|---|
| Opinion polls | Estimated current support | Sample and wording |
| Historical returns | Baseline patterns | Boundary and rule changes |
| Turnout data | Potential participation | Denominator |
| Electoral geography | Where votes are counted | District definitions |
| Economic context | Hypothesized association | Theory and dates |
| Previous model errors | Calibration and robustness | Historical information cutoffs |
How Election Opinion Polls Are Conducted
A population is the clearly defined group a survey seeks to represent, such as eligible voters or likely voters. A sample is the set of people actually interviewed. Probability sampling gives members of the defined population known chances of selection; an opt-in website poll instead draws volunteers and may not represent the wider electorate.
Researchers may weight responses to align a sample with suitable population benchmarks. A likely-voter model estimates who may participate, but turnout cannot be known in advance. Question wording, survey mode, interview dates, undecided respondents and nonresponse all influence interpretation. Nonresponse bias arises when those who respond differ systematically from those who do not.
The Pew Research Center’s polling guidance emphasizes that polling organizations increasingly mix contact methods and must explain what population was surveyed. A large voluntary sample can be less representative than a carefully selected smaller one. Students should look for methodological transparency rather than assume all online percentages are national estimates.

Worked Example: Margin of Sampling Error
Imagine a purely fictional survey of 400 respondents: 208 choose Candidate A and 192 choose Candidate B. The sample estimates are 208 / 400 x 100 = 52% and 192 / 400 x 100 = 48%. Their observed difference is four percentage points, but this does not establish the future election result.
Under idealized simple random sampling, the approximate maximum 95% margin of sampling error for a single proportion is 1.96 x square root of (0.25 / 400), or 0.049: approximately plus or minus 4.9 percentage points. The expression uses p = 0.5 for a worst-case variance approximation; it does not describe every real survey design.
This range concerns sampling uncertainty in one estimated share, not the probability Candidate A will win. It excludes nonresponse, incorrect likely-voter assumptions and preference changes. The uncertainty for the difference between the two mutually exclusive shares needs an appropriate joint calculation rather than casually applying the individual margin twice.
A closely divided hypothetical poll therefore requires cautious language. The American Association for Public Opinion Research warns that a reported sampling margin is only one source of polling uncertainty.
How Polling Averages Work
Suppose three fictional polls show Candidate A at 51%, 49% and 52%, with sample sizes 400, 800 and 600 respectively. Their simple average is (51 + 49 + 52) / 3 = approximately 50.67%. A sample-size-weighted calculation is (400 x 51 + 800 x 49 + 600 x 52) / 1,800, or approximately 50.44%.
Neither average automatically measures election-day support, produces a valid confidence interval or specifies a win probability. Polls taken at different times may measure changing opinions; different methodologies may share systematic bias. Professional aggregators also consider poll quality, recency, weighting approaches, populations and repeated polls from the same organization.
Averaging poor-quality surveys cannot repair an error shared across them. Interpreting aggregation requires the same critical thinking skills used in other data science investigations.
Ten Steps in an Election Forecasting Workflow
Begin by specifying the outcome: vote shares, valid ballots, seats, turnout or model-based victory probability. Next identify the election rules and collect documented historical and polling information. Clean dates, missing records and incompatible definitions before exploring trends.
Choose a justified baseline or statistical model, disclose turnout and sampling assumptions, and calculate the estimate. Where possible, represent uncertainty rather than displaying one number with false precision. Finally, test the procedure on previous elections using only information available at each original forecast date, and communicate limitations and the model’s date.
Backtesting prevents the mistake of judging models using facts learned only afterward. A forecast should be assessed across multiple elections, not simply by celebrating one correctly predicted winner.

Election Forecasting Methods Compared
A historical baseline carries forward a cautiously adjusted past result. A poll-based estimate summarizes current responses, while poll aggregation combines suitable surveys. Regression examines relationships between variables and outcomes. Bayesian approaches update distributions based on assumptions and observations; simulations produce many outcomes from an explicitly defined uncertainty model.
Machine learning methods such as logistic regression or random forests can investigate complex patterns but may overfit a limited historical dataset or incorporate misleading predictors. No advanced model automatically outperforms a simple, transparent baseline. Students should begin with calculations they can check by hand.
| Method | Main evidence | Strength | Limitation |
|---|---|---|---|
| Historical baseline | Prior results | Transparent starting point | Changes can break patterns |
| Poll estimate | Surveys | Current snapshot | Nonresponse or timing |
| Poll aggregation | Multiple polls | Reduced individual noise | Shared survey bias |
| Regression | Historical predictors | Explains associations | Model misspecification |
| Bayesian model | Prior and observations | Represents uncertainty | Sensitive to assumptions |
| Simulation | Defined probability inputs | Many scenarios | Requires valid model |
| Machine learning | Training data | Flexible patterns | Overfitting and leakage |
Student Project: Three Fictional Voting Regions
Imagine a fictional country whose national popular vote is decided by the total number of valid votes for two candidates. The regions North, South and Central are invented, as are all projected valid-vote totals and candidate preferences. There are no other candidates or invalid ballots in this simplified exercise.
| Fictional region | Expected valid votes | Candidate A share | Candidate B share | A votes | B votes |
|---|---|---|---|---|---|
| North | 8,000 | 54% | 46% | 4,320 | 3,680 |
| South | 12,000 | 47% | 53% | 5,640 | 6,360 |
| Central | 10,000 | 51% | 49% | 5,100 | 4,900 |
| Total | 30,000 | 50.2% weighted | 49.8% weighted | 15,060 | 14,940 |
Estimate Candidate A’s votes: North 8,000 x 0.54 = 4,320; South 12,000 x 0.47 = 5,640; Central 10,000 x 0.51 = 5,100. Total A = 15,060. Candidate B: North 8,000 x 0.46 = 3,680; South 12,000 x 0.53 = 6,360; Central 10,000 x 0.49 = 4,900. Total B = 14,940.
The check is 15,060 + 14,940 = 30,000 estimated valid votes. National projected shares are 15,060 / 30,000 x 100 = 50.2% for Candidate A and 14,940 / 30,000 x 100 = 49.8% for Candidate B. The modeled difference is 120 votes, or 0.4 percentage points.

An unweighted average of regional A shares gives (54 + 47 + 51) / 3 = approximately 50.67%. This differs from 50.2%, because the South region has more expected valid votes than the North. The unweighted result treats regions equally; the turnout-weighted calculation estimates their combined national popular vote.
The result is a deterministic scenario, not a statistical probability that A will win. Regional preference assumptions, turnout, late changes and electoral rules remain uncertain. A country using district seats might produce a different winner from the national vote-share leader.
Sensitivity Analysis: Changing South’s Turnout
Now assume South produces 15,000 rather than 12,000 valid votes while its hypothetical candidate shares remain 47% and 53%. Candidate A’s revised South total is 15,000 x 0.47 = 7,050; Candidate B’s is 15,000 x 0.53 = 7,950.
National estimated turnout becomes 8,000 + 15,000 + 10,000 = 33,000. Revised totals are A: 4,320 + 7,050 + 5,100 = 16,470 and B: 3,680 + 7,950 + 4,900 = 16,530. Their shares are approximately 49.91% and 50.09%.
The modeled lead changes from A by 120 votes to B by 60 votes solely because one turnout assumption changed. In a real election turnout and candidate support may change together. This illustration demonstrates sensitivity, not a reliable prediction of any actual contest.

Build the Forecast in Excel or Google Sheets
Set columns A Region, B Expected Valid Votes, C Estimated A Share, D Estimated B Share, E Projected A Votes and F Projected B Votes. Enter North, South and Central in rows 2–4. Format columns C and D as percentages and enter 54%, 46%, 47%, 53%, 51% and 49% appropriately.
Use =B2*C2 and =B2*D2 in E2 and F2, then copy down. Sum projected valid votes with =SUM(B2:B4), Candidate A votes with =SUM(E2:E4), and B votes with =SUM(F2:F4). Overall A share is =SUMPRODUCT(B2:B4,C2:C4)/SUM(B2:B4). Format the result as a percentage.
| Cell | Excel / Google Sheets formula | Expected output |
|---|---|---|
| E2 | =B2*C2 | 4,320 |
| F2 | =B2*D2 | 3,680 |
| B5 | =SUM(B2:B4) | 30,000 |
| E5 | =SUM(E2:E4) | 15,060 |
| F5 | =SUM(F2:F4) | 14,940 |
| A overall share | =SUMPRODUCT(B2:B4,C2:C4)/SUM(B2:B4) | 50.2% |
Create a grouped regional share chart and a stacked regional vote-total chart. Replace the South expected-votes cell with 15,000, observe the revised totals, then restore 12,000. Label every chart “Fictional educational scenario — not a real election prediction.” The exercise works with paper and calculator too.
What Does a 60% Election Win Probability Mean?
A hypothetical model assigning Candidate A a 60% chance of victory is not predicting 60% of votes or guaranteeing success. It means the model, using specified uncertainty assumptions, assigns six-tenths of its probability to A winning. Well-calibrated 60% predictions should occur roughly six times out of ten across many appropriate comparable events.
A forecast vote share, model win probability, sampling confidence interval, prediction interval and survey margin of error answer different questions. Our three-region spreadsheet calculates a single assumed vote-share scenario; it does not calculate any winning probability or prediction interval.

Why Election Forecasts Can Be Wrong
Sampling variation is only one difficulty. Nonresponse and selection bias can create systematically unrepresentative surveys. Likely-voter models may miss turnout differences; respondents may change preferences after surveys. Historical patterns may be unsuitable, and incorrect model assumptions may hide relevant factors.
Overfitting occurs when a method captures historical noise rather than generalizable relationships. Data leakage happens when a backtest secretly uses information that was not yet available. Several polls can share the same error. Even an accurate national vote-share model may fail to predict constituency seats.
| Problem | What can go wrong | Good practice |
|---|---|---|
| Sampling and nonresponse | Sample is unrepresentative | Transparent survey design |
| Turnout misspecification | Participation differs | Sensitivity scenarios |
| Late changes | Preferences move | Show forecast date |
| Overfitting | Past noise mistaken for signal | Holdout backtests |
| Data leakage | Future data contaminate test | Historical cutoffs |
| Electoral rules | Wrong result target | Model seat or runoff rules |
| Shared polling error | Poll averages retain bias | Quality checks and uncertainty |
Real-World Lessons From Verified Research
In October 2025 the American Association for Public Opinion Research released an assessment of polls before the 2024 US election. It found that many polls broadly depicted a close race, while systematic errors persisted. Across 611 final-two-week polls covering presidential, senatorial, gubernatorial and congressional contests, average absolute error in the two-party vote margin was 3.3 percentage points, compared with 5.3 in 2020 and 5.2 in 2016.
The study also found that no single methodological approach guaranteed accuracy. Polling errors related to participation assumptions and other challenges remained. This retrospective example illustrates the difference between useful polling and perfect predictions; it does not imply the methods apply unchanged to another country.
Internationally, the IDEA turnout database allows comparison of participation relative to registered voters or voting-age population. Those denominators are not identical, and electoral systems differ. Accurate comparisons begin with the source definitions, not an assumption that every national election works the same way.
Electoral Rules Change the Forecasting Target
In plurality or first-past-the-post systems, a constituency’s candidate can win with more votes than each opponent, even without an absolute majority. Proportional systems translate votes into seats under specific allocation methods and thresholds. Runoff rules can require another voting round, while indirect or electoral-college systems may not award victory to the leader in the nationwide popular vote.
| System | Result depends on | Why simple national share is insufficient |
|---|---|---|
| First-past-the-post | Constituency plurality | Seats depend on local votes |
| Proportional representation | Seat formula and thresholds | Allocation rules matter |
| Runoff | Required threshold and later round | First round may not decide |
| Indirect election | College or intermediary rule | National popular vote may not decide |
A correct 50.2% national vote-share estimate is not automatically a correct prediction of seats, runoff qualification or an indirect winner. The election system must be understood before deciding what to forecast.
Test Forecast Accuracy With Four Fictional Elections
Use four invented historical comparisons. Forecast Candidate A shares are 51%, 53%, 49% and 52%; fictional final shares are 50%, 50%, 51% and 54%. Absolute errors are |51 – 50| = 1, |53 – 50| = 3, |49 – 51| = 2 and |52 – 54| = 2 percentage points.
| Fictional election | Forecast A share | Invented final A share | Absolute error |
|---|---|---|---|
| 1 | 51% | 50% | 1 percentage point |
| 2 | 53% | 50% | 3 percentage points |
| 3 | 49% | 51% | 2 percentage points |
| 4 | 52% | 54% | 2 percentage points |
| MAE | 2 percentage points |
Mean absolute error is (1 + 3 + 2 + 2) / 4 = 2 percentage points. It describes the average magnitude of these four share errors, not the probability of winning, nor the accuracy of a real election model. Larger datasets, appropriate historical splits and comparison with simple baselines are necessary for meaningful model evaluation.

Social Media, AI and Election Forecasts
Social media posts, trends and sentiment classifiers can reveal themes of digital discussion, but active users do not automatically represent the voting population. Likes, hashtags, automated accounts and reposts are not ballots. Coordinated activity, platform access and language ambiguity can distort impressions of support.
Machine learning and text analysis may support research into public discourse, but unvalidated online sentiment should never replace representative surveys or official counting. Students can explore nonpolitical examples in social media analytics for high school students, without collecting anyone’s political beliefs.
Ethics, Neutrality and Data Privacy
Political neutrality, accurate sourcing and honest uncertainty reporting are essential. Researchers should never fabricate real polling figures, publish AI-generated fake election notices, claim an uncertain forecast proves fraud, or portray an uncounted contest as certified. Present genuine historical results only after checking the electoral authority.
No classroom assignment requires collecting classmates’ political preferences, identifying anonymous users, scraping private discussions or profiling people for targeted persuasion. Use invented candidates and aggregated, properly sourced records. Protect minors’ privacy, respect local election law and avoid harassment, intimidation or suppression tactics.

Student Tools and Four-Week Learning Plan
Excel, Google Sheets and graph paper are enough for the fictional calculations. Python with Pandas or Matplotlib and R can support later statistical work. Official election authorities, International IDEA and documented research archives provide historical datasets, but their dates, licensing and definitions must be checked.
| Week | Learning focus | Student output |
|---|---|---|
| 1 | Polls, rules, historical data | Glossary and sources |
| 2 | Sampling, MOE, averages | Checked calculations |
| 3 | Fictional regional forecast | Spreadsheet and sensitivity |
| 4 | Forecast errors and ethics | Neutral evaluation report |
Week one covers polls, electoral rules and sources; week two practices sample calculations; week three builds the three-region scenario and changes turnout; and week four evaluates forecast errors and discusses uncertainty. See student data science tools, data science project ideas and writing a data science research report for further study.
All forecasting estimates should have an explicit date. A survey completed weeks before an election measures a different moment from one completed immediately beforehand. Even a well-designed survey can be overtaken by events or information appearing after interviews end. Students should therefore state when each item was collected, whether undecided responses were excluded and whether sources were available in time for the forecast.
Conclusion: Understand Uncertainty Before Calling an Outcome
Election forecasts translate evidence and explicit assumptions into estimates of future events. They can illuminate the role of representative polling, historical outcomes, turnout and voting rules, but cannot replace actual ballots, counting procedures or certified results. A precise-looking number may still conceal substantial uncertainty when the underlying data or assumptions are weak.
The fictional three-region example shows why expected turnout matters: changing one region’s vote count reverses a very narrow modeled lead. The second activity demonstrates how absolute error and a simple baseline help test whether a method is useful. Both exercises should produce transparent calculations, not confident claims about real candidates.
Complete the spreadsheet, document every assumption, and write two statements: one your fictional figures support and one they cannot support. Reliable election data science means resisting unjustified certainty and communicating statistical evidence responsibly.
Five Knowledge-Check Questions
- What does a poll of 208 A and 192 B among 400 show? A 52%, B 48%, a four-point sample difference.
- What are the fictional baseline totals? A 15,060, B 14,940, from 30,000 projected valid votes.
- What changes if South turnout rises to 15,000? A 16,470 and B 16,530; the modeled leader changes.
- Does 60% chance to win mean 60% of votes? No; probability and vote share differ.
- What is the four-election MAE? Two percentage points.
Frequently Asked Questions
1. How does data science predict election results?
By combining suitable evidence and explicit statistical assumptions to estimate uncertain future outcomes, not by counting future ballots.
2. What is the difference between a poll and a forecast?
A poll estimates preferences at a particular time; a forecast attempts to estimate an election outcome that has not happened.
3. Can machine learning accurately predict winners?
It can be used, but performance depends on trustworthy data, model assumptions and evaluation across multiple elections.
4. What data do forecasters use?
Depending on method, credible polls, documented official historical results, turnout, electoral rules, timing and public contextual data.
5. What does polling margin of error mean?
It approximates sampling uncertainty under stated assumptions; it does not include every source of error or specify a win probability.
6. How does turnout affect a forecast?
Regions with different expected valid-vote totals receive different weights in a national popular-vote scenario.
7. Why can election forecasts fail?
Unrepresentative surveys, nonresponse, changing preferences, turnout errors, model weaknesses and electoral-system assumptions.
8. Can high school students build an election model?
Yes, with invented candidates, a calculator or spreadsheet and clear statements of uncertainty and ethical limitations.