Machine learning lets a program improve from data instead of being explicitly coded for every case.

What Is Machine Learning

Arthur Samuel (1959) described machine learning (ML) as giving computers the ability to learn without being explicitly programmed. Tom Mitchell's definition is more precise: a program learns from experience E with respect to a task T and performance measure P if its performance at T, measured by P, improves with E. A spam filter learns from labelled emails (E) to classify mail (T), measured by accuracy (P). ML is used when rules are too complex to write by hand (recognising faces), when the task changes with time (fraud), and when the system must adapt to each user (recommendations).

Definition: Machine learning. The field of study in which computers improve their performance at a task through experience, by finding patterns in data rather than following explicit rules.

Types of Learning

Supervised learning learns from labelled examples (input, correct output). Classification predicts a category (spam or not spam; digit 0–9) using algorithms such as k-nearest neighbours, decision trees, naive Bayes, logistic regression and support vector machines; regression predicts a number (house price) with linear regression. Unsupervised learning finds structure in unlabelled data: clustering (k-means for customer segments), dimensionality reduction (PCA) and association rules. Semi-supervised learning mixes a few labels with many unlabelled examples. Reinforcement learning (RL) learns by interacting with an environment and receiving rewards; an agent finds a policy maximising total reward, as in game playing (AlphaGo), robotics and recommendation. Self-supervised learning creates labels from the data itself, as in large language models.

The ML Workflow

The steps are: collect data; prepare it (clean, handle missing values, encode, scale); split into training, validation and test sets; choose a model; train it; evaluate it using suitable metrics (accuracy, precision, recall, F1 for classification; mean squared error for regression); tune hyper-parameters; and deploy and monitor. The two chief problems are overfitting (the model memorises training data and fails on new data) and underfitting (too simple to capture the pattern). Remedies: more data, simpler models, regularisation, cross-validation.

Applications

Spam and fraud detection, medical diagnosis from images and records, recommendation systems (Netflix, Amazon), speech recognition, credit scoring, demand forecasting, predictive maintenance, self-driving cars, translation and agriculture (crop disease detection).

Table 4.1: Types of machine learning

Type Data Examples
Supervised Labelled Spam filter, price prediction
Unsupervised Unlabelled Customer clustering
Semi-supervised Few labels, many unlabelled Medical image labelling
Reinforcement Rewards from environment Game playing, robot control

Example 4.1: Learning a line from data

Problem: Given points (1, 2), (2, 4), (3, 5), (4, 4), (5, 5), fit y = mx + c by least squares and predict y at x = 6.

Solution:

  1. Means: x̄ = 3, ȳ = 4.
  2. Σ(x − x̄)(y − ȳ) = (−2)(−2) + (−1)(0) + 0(1) + (1)(0) + (2)(1) = 6; Σ(x − x̄)² = 10.
  3. Slope m = 6/10 = 0.6; intercept c = 4 − 0.6 × 3 = 2.2.
  4. Prediction at x = 6: 0.6 × 6 + 2.2 = 5.8.

Result: The learned model is y = 0.6x + 2.2; it predicts 5.8 for x = 6.

xs, ys = [1, 2, 3, 4, 5], [2, 4, 5, 4, 5]
mx, my = sum(xs) / len(xs), sum(ys) / len(ys)
sxy = sum((x - mx) * (y - my) for x, y in zip(xs, ys))
sxx = sum((x - mx) ** 2 for x in xs)
m = sxy / sxx
c = my - m * mx
print(f"slope={m:.1f} intercept={c:.1f}")
print("prediction at x=6:", round(m * 6 + c, 1))

Output

slope=0.6 intercept=2.2
prediction at x=6: 5.8

Common mistakes

  • Testing on the training data and reporting that accuracy as real performance.
  • Using accuracy alone on imbalanced data (a model predicting "no fraud" is 99 percent accurate).
  • Confusing classification (categories) with regression (numbers).
  • Assuming more complex models are always better; they may overfit.

Key takeaways

  • ML improves performance at a task from experience (data).
  • Supervised (labelled), unsupervised (unlabelled), semi-supervised and reinforcement (rewards).
  • Split data into training, validation and test sets.
  • Overfitting: great on training, poor on new data.

Practice questions

  1. Distinguish classification and regression.
  2. What is overfitting?
  3. What is reinforcement learning?

Answers to the practice questions

  1. Classification predicts a category; regression predicts a continuous number.
  2. A model fits the training data too closely, including noise, and performs badly on new data.
  3. Learning a policy by trial and error from rewards received from the environment.

Sources

  • Official BCA syllabus Artificial Intelligence, course code 26BCA404DS04, Unit IV