Introduction to Machine Learning
Understand what machine learning is, how it differs from traditional software programming, the core types of learning (supervised, unsupervised, reinforcement), and how the end-to-end ML workflow operates in production.
1. What Is Machine Learning?
In traditional software engineering, a programmer writes explicit rules and logic: if temperature > 30, turn on cooling. The computer takes data and applies human-written rules to calculate answers.
Machine Learning (ML) flips this paradigm upside down: instead of writing the rules yourself, you feed the computer data and observed outcomes, and the algorithm discovers the mathematical patterns and rules automatically.
Traditional Programming vs Machine Learning
Traditional Programming: Data + Rules → Answers
Machine Learning: Data + Answers → Rules (Model)
2. The Three Primary Types of Machine Learning
Machine learning problems generally fall into three overarching paradigms based on the nature of the data and learning objective:
A. Supervised Learning (Learning with a Teacher)
The training data includes both input features (X) and labeled target answers (y). The algorithm learns a mapping function from input to output.
- Regression: Predicting continuous numerical quantities (e.g., forecasting house prices, customer lifetime value, or tomorrow's temperature).
- Classification: Predicting discrete category labels (e.g., email spam detection, credit fraud classification, or tumor malignancy).
B. Unsupervised Learning (Finding Hidden Structure)
The model receives unlabeled data (only features X, no target y). Its objective is to uncover inherent groupings, anomalies, or compressed representations.
- Clustering: Grouping similar observations together (e.g., customer market segmentation with K-Means).
- Dimensionality Reduction: Compressing high-dimensional datasets while preserving variance (e.g., PCA).
- Anomaly Detection: Identifying rare observations that deviate from normal patterns (e.g., network intrusion detection).
C. Reinforcement Learning (Learning by Trial and Reward)
An autonomous agent interacts with an environment, executing actions and receiving scalar rewards or penalties. Through exploration and exploitation, it learns an optimal policy to maximize cumulative rewards (e.g., self-driving navigation, robotic arm manipulation, and game playing).
3. The End-to-End Machine Learning Workflow
Successful applied machine learning follows a systematic engineering lifecycle:
- Problem Definition: Frame the business problem as an ML task (classification, regression, or clustering) and define success metrics (e.g., RMSE, F1-score, latency).
- Data Collection & Exploration (EDA): Gather representative datasets, inspect distributions, detect anomalies, and uncover feature correlations.
- Data Preprocessing: Handle missing values, encode categorical variables, scale numerical features, and perform train/test splits (covered in detail in Module 2).
- Model Training: Train candidate algorithms (e.g., Linear Regression, Random Forest, XGBoost) on historical training data.
- Evaluation & Validation: Measure performance on unseen test data using cross-validation to guard against overfitting.
- Deployment & Monitoring: Serve predictions via APIs, monitor data drift, and retrain models as underlying distributions evolve.
4. Your First Model in Python: 5 Lines of Scikit-Learn
Python's scikit-learn library provides a consistent, clean API across all classical algorithms: fit() to train, and predict() to infer.
from sklearn.neighbors import KNeighborsClassifier
# 1. Feature data: [Age, Annual Salary in k]
X_train = [[22, 25], [28, 45], [35, 80], [45, 120], [50, 140]]
# 2. Labels: 0 = No purchase, 1 = Purchase premium service
y_train = [0, 0, 1, 1, 1]
# 3. Instantiate model
model = KNeighborsClassifier(n_neighbors=3)
# 4. Train the model (find mathematical patterns)
model.fit(X_train, y_train)
# 5. Make a prediction on a new prospective customer
new_customer = [[30, 60]]
prediction = model.predict(new_customer)
print("Predicted class:", prediction[0]) # Output: 1
Check your understanding
Your machine learning roadmap
- 01Introduction to Machine LearningYou are here
- 02Preparing Data for Machine LearningClean data, scaling & splits
- 03Linear RegressionPredicting numbers
- 04Logistic RegressionPredicting categories
- 05Model EvaluationMeasuring accuracy
- 06K-Nearest NeighboursDistance-based classification
- 07Decision TreesRule-based learning
- 08Random Forest & BoostingEnsemble intelligence
- 09Support Vector MachinesMargin maximisation
- 10Naive BayesProbabilistic classification
- 11K-Means ClusteringUnsupervised grouping
- 12PCADimensionality reduction
- 13Capstone ProjectReal-world churn model