← Back to list

Three essential Machine Learning Algorithms Explained in 2 Minutes

Introduction

SULTAN ANSARI · 2026-08-08 16:45 · 0 claps · 1.3 min read
#machine-learning #linear-regression #clustering #decision-tree #data-analysis
Open on Medium ↗
Wiki topics: ML · Machine Learning EDU · Education & Learning 💻 · Programming

Gemini Generated

Gemini Generated

Three essential Machine Learning Algorithms Explained in 2 Minutes

Introduction

Machine learning algorithms turn raw data into actionable insights, driving everything from house price predictions to email spam filters. Here are three core algorithms every developer should know, explained simply with quick Python examples.

1. Linear Regression (Predicting Continuous Values)

Fits a straight line through data points to model relationships between independent features and a numerical target.

Example

Estimating house prices based on square footage.

from sklearn.linear_model import LinearRegression

# Features: [Square Footage] | Target: Price in $k
X = [[600], [800], [1000], [1200]]
y = [150, 200, 250, 300]

model = LinearRegression().fit(X, y)

# Predict price for a 900 sq ft house
print(model.predict([[900]])) # Output: [225.]

2. Decision Tree (Categorical Classification)

Works like a flowchart by making yes-or-no split decisions on data features to assign a class label.

Example

Filtering emails into “Spam” or “Not Spam” based on keyword triggers.

from sklearn.tree import DecisionTreeClassifier

# Features: [Contains 'FREE' (1/0), Has External Link (1/0)]
X = [[1, 1], [1, 0], [0, 0], [0, 1]]
y = ['Spam', 'Spam', 'Not Spam', 'Not Spam']

model = DecisionTreeClassifier().fit(X, y)

# Classify an email without 'FREE' or links
print(model.predict([[0, 0]])) # Output: ['Not Spam']

3. K-Means Clustering (Grouping Unlabeled Data)

An unsupervised algorithm that automatically organizes data points into distinct clusters based on mathematical similarity.

Example

Segmenting customer bases into low-spend vs. high-spend groups for targeted marketing.

from sklearn.cluster import KMeans

# Features: [Monthly Spend ($), Visit Frequency]
X = [[15, 1], [20, 2], [500, 10], [600, 12]]

model = KMeans(n_clusters=2, n_init=10, random_state=42).fit(X)

# Output cluster IDs for each user point
print(model.labels_) # Output: [0 0 1 1]

메타데이터
post_id
d255ddf48963
slug
three-essential-machine-learning-algorithms-explained-in-2-minutes-d255ddf48963
url
https://medium.com/@sultan.jamshed10/three-essential-machine-learning-algorithms-explained-in-2-minutes-d255ddf48963
canonical_url
https://medium.com/@sultan.jamshed10/three-essential-machine-learning-algorithms-explained-in-2-minutes-d255ddf48963
author_url
https://medium.com/@sultan.jamshed10
status
ok
fetched_at
2026-08-11 06:01:17