Data and modeling

Machine learning for data analysis

Machine learning extends data analysis from describing what happened to predicting and grouping. Analysts use regression to estimate a measured outcome, clustering to segment customers or records, and feature importance to see which variables a model relies on.

Where to start

Start with pandas summaries and plots so you know the data before fitting anything. Then learn regression and clustering in scikit-learn, and always compare a model with a simple descriptive baseline.

How machine learning is used in data analysis

Segmenting customers

Clustering groups customers by behaviour, such as how recently, how often and how much they buy, so each group can be served differently. Analysts usually build a few summary features per customer, scale them and try k-means before anything more complex.

Real example: RFM customer segmentation of a UK online retailer (Chen, Sain and Guo, 2012). The paper segments the customers of a UK online retailer using RFM (recency, frequency, monetary) features and data mining, and is the introductory paper for the UCI Online Retail dataset.

Spotting unusual changes in metrics

Instead of eyeballing dashboards, anomaly detection models learn the normal range of a metric, including its weekly pattern, and flag days that fall outside it. This lets analysts look into real changes rather than ordinary noise.

Real example: Google Analytics anomaly detection. Google Analytics lets users create insights with a 'has anomaly' condition, in which Analytics determines when a change in a metric is anomalous without a fixed threshold.

Grouping free-text feedback

Survey comments, reviews and support tickets are too many to read one by one. Topic models and embedding-based clustering group them into themes an analyst can count, label and track over time.

Real example: BERTopic (Grootendorst, 2022). BERTopic clusters document embeddings and describes each cluster with a class-based TF-IDF procedure to produce interpretable topics.

Estimating what drives an outcome

Regression and tree models estimate how much each variable is associated with an outcome such as sales or grades, beyond what a simple cross-tab shows. Analysts then check the result against domain knowledge before treating it as a driver.

Real example: Robyn (Meta, open source). Robyn estimates the contribution of each marketing channel to an outcome with ridge regression, using automated hyperparameter search to reduce analyst bias.

Can you learn machine learning for data analysis?

Yes, and analysts are well placed to learn it because the hardest parts, cleaning data and asking good questions, are already familiar. Move from spreadsheets or SQL to Python and pandas, then add statistics and a small set of models with proper evaluation.

  1. Python. Learn enough Python to replace repeated spreadsheet steps with scripts you can rerun on new data. Taught in the Python track of Foundations of AI
  2. pandas and visualisation. Filter, group, join and reshape tables in pandas, and chart distributions and relationships before modelling. Taught in the Data Tools track of Foundations of AI
  3. Statistics for analysts. Revisit descriptive statistics, sampling error and hypothesis tests so model results are read with the right amount of caution. Taught in the Statistics track of Foundations of AI
  4. Regression, trees and clustering. Fit regression and tree models with a held-out test set, explain them with feature importance, and cluster records when there is no label. Taught in the Machine Learning track of Foundations of AI

Moving from data analysis into machine learning

If you already work in the field

Data analysts already know SQL, the business metrics and how to present results. Add Python and scikit-learn, then pick one recurring question, such as which customers are likely to churn, and answer it with a model that beats a simple baseline on held-out data.

If you come from data science or ML

If you know modelling but not analysis work, practise the analyst's habits: checking data quality, reconciling numbers with finance or operations, and turning results into a short chart-led summary. Spend time with the people who own the metrics you model.

Roles that do this work: Data analystSenior data analystAnalytics engineerBusiness intelligence analystData scientist

Tools you will use

ToolWhat you use it for
pandasFilter, group and summarise records to answer descriptive questions before modelling.
PolarsProcess larger tables quickly with a lazy, multi-threaded DataFrame engine.
MatplotlibDraw the charts that check distributions, trends and model residuals.
scikit-learnRun regression, k-means clustering and permutation importance with one consistent interface.
SHAPBreak individual predictions into feature contributions to explain a fitted model.

Public data to practise on

  • Student Performance (UCI): Grades, demographics and study habits of secondary-school students in maths and Portuguese, for regression practice.
  • Online Retail II (UCI): Transactions from an online retailer, for customer segmentation by recency, frequency and spend.

Your first project

Download the Student Performance dataset, predict final maths grades from background and study-habit columns (leaving out earlier term grades) with a random forest, and compare it with a mean-grade baseline using mean absolute error.

Keep the result, your code and a short note on what didn't work. That record is worth more than the score.

Common questions

Do data analysts use machine learning?
Increasingly, yes, mostly for forecasting, segmentation, anomaly detection and driver analysis. Much day-to-day analysis still relies on SQL, descriptive statistics and well-designed charts.
What is the difference between data analysis and machine learning?
Data analysis explains what happened and why, usually for a person to read. Machine learning builds a model that makes predictions on new data, which is judged by how well it performs on data it has not seen.
Can I do machine learning in Excel?
Excel can fit linear regression and simple forecasts, but it becomes awkward for proper train and test splits, many models and repeatable pipelines. Python with pandas and scikit-learn is the usual next step.
Which machine learning methods should an analyst learn first?
Linear and logistic regression, decision trees and random forests, k-means clustering and a time series baseline cover most analyst problems. Learn cross-validation and simple baselines alongside them.

First Principles, the SchoolWhool newsletter

One machine learning idea, explained properly, every week.

The intuition, the common mistake, and a five-minute way to try it yourself. Written by Gaurav.

Learn the machine learning behind it, from first principles.

Start with Python from zero, free. Every stage after that builds on the last, and a person answers your doubts.