Introduction to Machine Learning

What is Machine Learning?

Machine Learning (ML) is a subset of artificial intelligence (AI) that focuses on enabling systems to learn from data and make predictions or decisions without being explicitly programmed. Instead of following a set of predefined rules, ML algorithms use statistical techniques to "learn" patterns from large datasets.

Core Idea

Learning from experience (data) to improve performance on a task.

Think of it like teaching a child. You show them many examples of cats and dogs, and eventually, they learn to distinguish between them. Machine learning algorithms do something similar, but with much larger and more complex datasets.

Key Components

Types of Machine Learning

Machine learning can broadly be categorized into three main types:

1. Supervised Learning

In supervised learning, algorithms are trained on a labeled dataset, meaning each data point is associated with a correct output or "label." The goal is to learn a mapping function from input variables (features) to the output variable (label).

Examples: Image classification (identifying objects in images), spam detection (classifying emails as spam or not spam), predicting house prices.

Supervised Learning

Learning with labeled data. Predicts output based on input.

2. Unsupervised Learning

In unsupervised learning, algorithms are trained on unlabeled data. The goal is to find hidden patterns, structures, or relationships within the data without any predefined output.

Examples: Customer segmentation (grouping similar customers), anomaly detection (identifying unusual data points), dimensionality reduction.

Unsupervised Learning

Learning with unlabeled data. Finds patterns and structures.

3. Reinforcement Learning

In reinforcement learning, an agent learns to make a sequence of decisions by trying to maximize a reward it receives for its actions. It learns through trial and error, receiving feedback (rewards or penalties) from its environment.

Examples: Game playing (like chess or Go), robotics, autonomous navigation.

Reinforcement Learning

Learning through interaction and feedback (rewards/penalties).

A Simple Example: Linear Regression

One of the simplest supervised learning algorithms is Linear Regression, used for predicting a continuous output value. If we want to predict house prices based on their size, we might use linear regression.


import numpy as np
from sklearn.linear_model import LinearRegression

# Sample data: House size (sq ft) and price ($)
X = np.array([[1000], [1500], [2000], [2500], [3000]])
y = np.array([300000, 450000, 500000, 700000, 800000])

# Create a linear regression model
model = LinearRegression()

# Train the model
model.fit(X, y)

# Predict the price of a 2200 sq ft house
predicted_price = model.predict([[2200]])

print(f"The predicted price for a 2200 sq ft house is: ${predicted_price[0]:,.2f}")
        

This code trains a model to find a line that best fits the relationship between house size and price, allowing us to predict prices for new house sizes.

Want to see a more interactive demo?

Check out our Linear Regression Visualizer.