Skip to main content

Introduction to Data Science and ML

Data science extracts insight from data; machine learning (ML) is the part that learns patterns from data to make predictions or decisions without being explicitly programmed for each case.

Types of learning​

TypeDataGoalExamples
SupervisedInputs with labelsPredict labelsSpam detection, house prices
UnsupervisedInputs onlyFind structureCustomer segments, anomaly detection
ReinforcementRewards from actionsLearn a policyGame playing, robotics

Supervised problems are regression (predict a number) or classification (predict a category).

The ML workflow​

  1. Define the problem and success metric.
  2. Collect and clean data.
  3. Explore the data (EDA) and engineer features.
  4. Split into train, validation and test sets.
  5. Train and tune models.
  6. Evaluate on unseen data.
  7. Deploy and monitor (data drift, performance).

The Python toolkit​

LibraryPurpose
NumPyFast numerical arrays
pandasTabular data
Matplotlib / seabornVisualisation
scikit-learnClassic ML algorithms
PyTorch / TensorFlowDeep learning
JupyterInteractive notebooks
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.neighbors import KNeighborsClassifier

X, y = load_iris(return_X_y=True)
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.2, random_state=42
)

model = KNeighborsClassifier(n_neighbors=3).fit(X_train, y_train)
print("accuracy:", model.score(X_test, y_test))

Key vocabulary​

  • Feature: an input variable. Label / target: what we predict.
  • Overfitting: the model memorises training data and fails on new data.
  • Underfitting: the model is too simple to capture the pattern.
  • Bias-variance trade-off: simple models have high bias, complex models have high variance.