Computer science | Learning from data

AI and machine learning: patterns, predictions, and limits

Understand how machine-learning systems learn from examples, how predictions are evaluated, why models can fail, and what responsible use requires.

COMPUTER SCIENCEAI AND ML GUIDEBeginner to intermediate
A machine-learning workflowA team defines a task, prepares data, trains a model, evaluates it on separate examples, and monitors its behavior after deployment. Task + dataPrepareTrainEvaluateMonitor evaluation and real-world feedback lead to refinement
Figure 1. Machine learning is a lifecycle; evaluation and monitoring are necessary after training.

Artificial intelligence and machine learning

Artificial intelligence (AI) is a broad field concerned with building systems that perform tasks associated with perception, reasoning, language, planning, or decision-making. Machine learning (ML) is a family of methods that learn patterns from data rather than relying only on manually written rules.

Not every AI system learns from data, and not every automated decision is AI. A rule-based program can use explicit conditions such as “if the temperature is below a limit, turn on the heater.” A machine-learning model might instead estimate a temperature from noisy sensor readings after seeing examples.

A model is a mathematical or computational representation that maps inputs to outputs. During training, an algorithm adjusts model parameters to reduce some measure of error on examples. The result is not a person-like understanding; it is a system whose behavior depends on its data, objective, model design, and operating context.

Ways a model can learn

Learning setupWhat the data providesExample task
Supervised learningInputs paired with target labels or valuesPredict a home price from property features
Unsupervised learningInputs without target labelsGroup similar documents by content
Self-supervised learningTargets derived from the data itselfPredict a hidden part of text or an image
Reinforcement learningFeedback or rewards from actions over timeLearn a strategy in a simulated environment

Classification predicts a category, such as whether an email belongs in a spam folder. Regression predicts a numeric value, such as tomorrow's energy use. Clustering groups data based on similarity. Different tasks need different evaluation methods and different definitions of success.

A model's output is not necessarily a calibrated probability or a reliable explanation. A score of 0.8 has a probabilistic interpretation only if the system is designed and evaluated to support that interpretation.

The machine-learning workflow

  1. Define the decision: say what prediction is needed, who uses it, and what action follows.
  2. Collect appropriate data: ensure examples are relevant, permitted, and representative of intended use.
  3. Prepare data: handle missing values, errors, formats, and features without leaking information.
  4. Choose a baseline: compare a simple model or rule against the task's needs.
  5. Train: fit model parameters to training examples using a defined objective.
  6. Evaluate: use separate data and measures that reflect real costs.
  7. Deploy and monitor: check performance, data changes, and unintended outcomes over time.

Data preparation is often a large part of the work. Incorrect labels, missing groups, duplicate examples, or data collected under different conditions can produce misleading results. More data does not automatically mean better data.

Features and labels

A feature is an input used by a model. A label is the target answer for a supervised example. For a model estimating delivery time, features might include distance and time of day; the label might be the measured time for a past delivery.

Features can encode sensitive or indirect information. A field that appears neutral may correlate with a protected characteristic. Feature choices should be justified by the task, reviewed for privacy and fairness concerns, and tested against the consequences of errors.

Worked example: predict study time

Imagine estimating how long a student may need to finish a practice set. Historical examples contain the number of questions and the time actually taken. A simple regression model could learn an approximate relationship from a training set.

Before training, clarify what “time needed” means: active time, elapsed time including breaks, or time until all answers are submitted? The prediction may be used for planning but should not be presented as a guarantee. A student who is learning a new topic may take much longer than one who has practiced it.

QuestionsObserved minutesRole in the example
518One training example
1035One training example
829Held-out evaluation example

A baseline could predict the average training time for every set. A more complex model can use question count and other justified features. Compare its predictions on data it did not train on, then ask whether the improvement is useful enough to justify added complexity.

This example also reveals limits: past timing may reflect different question difficulty or student circumstances. Collecting additional personal information could raise privacy concerns and still fail to explain an individual's needs. The system should communicate uncertainty and let the learner plan flexibly.

Evaluation and data splits

A common workflow splits examples into a training set for fitting parameters, a validation set for selecting model settings, and a test set for a final check. The test set should not guide repeated tuning; otherwise it stops being an independent estimate.

For classification, accuracy is the proportion of predictions that are correct. It can hide important errors when categories are imbalanced. If only 1% of transactions are fraudulent, a model that always predicts “not fraud” has 99% accuracy while finding no fraud at all.

MeasureWhat it summarizesQuestion to ask
PrecisionAmong positive predictions, how many were correct?How costly are false alarms?
RecallAmong actual positives, how many were found?How costly are missed cases?
Mean absolute errorAverage magnitude of numeric prediction errorsWhat size error matters to users?
CalibrationWhether predicted confidence matches observed frequencyCan a score be used as a probability?

Choose measures based on the action and its consequences. A medical screening tool, spam filter, and music recommender need not share one definition of success. Overall scores should be supplemented by analysis of relevant subgroups and difficult cases.

Thresholds change outcomes

Many classifiers produce a score and apply a threshold to choose a category. Lowering the threshold may identify more positive cases, increasing recall but also increasing false positives. Raising it may reduce false alarms while missing more real cases. The right threshold depends on the costs of both error types and how people respond to the result.

Calibration matters when a score is presented as confidence. If a model labels many cases with a 70% probability, about 70% of those cases should meet the event definition over an appropriate set of examples. A model can rank cases well but be poorly calibrated, so “good performance” depends on how its output will be used.

Data leakage

Data leakage occurs when training or evaluation uses information that would not be available at the time of a real prediction, or when examples from the same source improperly appear in both training and test sets. Leakage can make an impressive test score collapse in real use. Split data according to how the model will be used, such as by time, person, or location where appropriate.

Overfitting and generalization

A model overfits when it learns details or noise specific to its training examples and performs poorly on new data. A very simple model may underfit important patterns; an overly complex model may fit the training set perfectly without generalizing.

Generalization is the ability to perform on relevant examples that were not used for training. A clean test split is one source of evidence, but real-world data may differ from the test set. Monitor how input patterns and outcomes change after deployment.

Regularization, more representative data, simpler models, and careful validation can help reduce overfitting. These techniques do not guarantee that deployment behavior will be safe or fair; they address particular statistical concerns.

Repeated experimentation can overfit the test set

If a team checks a test score after every model change and chooses the best result, it has indirectly tuned to the test data. The final score can become optimistic even though the test examples were never included in gradient updates. Keep the final test set untouched until the approach is selected, or use a well-designed cross-validation procedure for model selection.

Cross-validation divides training data into several parts and repeats training and evaluation so different portions serve as validation. It can provide a more stable comparison on limited data, but it does not fix a biased sample, leakage, or a mismatch between test and real-world conditions.

Distribution shift and drift

Distribution shift occurs when the data seen during use differs from the training data. A delivery model trained on one region may perform differently after a service expands. Changes in user behavior, sensors, policies, or economic conditions can make older data less representative.

Monitor input quality and outcome measures, define alert thresholds, and decide who responds when performance changes. Retraining is not an automatic fix: if the new data reflects a harmful outcome or biased process, training on it can reproduce the problem.

Neural networks and modern AI

A neural network is a model built from layers of parameterized computations. During training, optimization adjusts its weights to reduce an objective function. Deep learning uses networks with many layers and has been effective for images, speech, language, and other data types.

Large language models are trained on large collections of text to predict or generate sequences of tokens. They can produce useful summaries and drafts, but plausible wording is not proof of factual accuracy. They can reproduce biases, omit relevant information, and generate claims without reliable evidence.

Generative AI systems are probabilistic components, not guaranteed databases or trusted authorities. Verify important claims using reliable sources, avoid sending confidential data to services without an approved privacy arrangement, and keep accountable human review for consequential use.

Model quality depends on the whole system

A deployed model is part of a larger product: inputs are collected and transformed, predictions are shown to people, and those people may take actions that affect future data. Poor interface design can cause a good model to be misused. Evaluate the complete human-and-software workflow.

Limits, risks, and responsible use

Machine-learning models learn statistical patterns, not necessarily causal explanations. A correlation in training data does not prove that changing one feature will change the outcome. If a team needs to understand causes or estimate the effect of an intervention, it needs methods designed for that question.

Potential harms include privacy loss, unfair outcomes, inaccurate decisions, inaccessible interfaces, environmental costs, and overreliance on automated results. Consider who is represented in the data, who bears the cost of errors, how people can challenge a result, and whether a simpler non-ML solution would be more appropriate.

Responsible deployment includes a clear purpose, data minimization, documented limitations, meaningful evaluation, human oversight where needed, monitoring, and a way to stop or roll back the system. Not every task should be automated.

Explainability and human review

Some models can provide feature importance or example-based explanations, but an explanation method is itself an approximation and may not faithfully describe every individual prediction. Show uncertainty honestly and make explanations appropriate to the user's needs. A technical explanation is not the same as a justification for a decision.

Human review is useful only when reviewers have time, authority, and information to question the output. If a person is expected to approve every prediction quickly without context, review may become a rubber stamp. Design the workflow so reviewers can investigate, override, and escalate uncertain or high-impact cases.

Compact glossary

Model
A learned or designed representation that maps inputs to outputs.
Feature
An input variable used by a model.
Label
The target answer associated with a supervised training example.
Overfitting
Learning training-specific patterns that do not generalize well.
Data leakage
Information entering training or evaluation that would not be legitimately available.
Distribution shift
A change between data conditions during training and use.

References and further reading

  1. Google. Machine Learning Crash Course. Interactive course.
  2. scikit-learn developers. scikit-learn User Guide. Documentation and examples.
  3. National Institute of Standards and Technology. AI Risk Management Framework. Framework resources.
  4. Rachel Thomas and fast.ai. Practical Deep Learning for Coders. Free course.

Try it yourself

  1. Design a simple supervised-learning task and identify inputs, labels, and one way labels could be wrong.
  2. Why can accuracy be misleading when one class is rare?
  3. Give an example of data leakage in a time-based prediction problem.
  4. Choose an AI-generated answer and describe how you would verify its important claims.
  5. List who could be harmed by a false positive and a false negative in an automated decision.

Remember: models learn from data and objectives chosen by people; evaluate them in context and make their limits visible.

Keep exploring

Try another topic

A fresh topic suggestion is ready for you.

Explore a topic
0% read