ML Models & Algorithms
Linear Regression
In shortLinear regression is a supervised model that predicts a number by fitting a straight line through your data, such as clicks against average position.
Linear regression is a supervised learning model that predicts a number by fitting a straight line (or, with several inputs, a flat plane) through your data. It is the simplest member of the regression family: given inputs such as month or average position, it estimates an output such as sessions or click-through rate. Because every input gets one readable weight, it is usually the first model to try and the baseline that more complex models have to beat.
How it works
With one input, the model learns an equation of the form y = b + w × x. The intercept b is the predicted value when x is zero, and the slope w is how much y changes for each one-unit increase in x. With several inputs, called features, each one gets its own weight. Training finds the weights that minimise the squared differences between predicted and actual values, a method called ordinary least squares, which is what scikit-learn’s LinearRegression implements.
MLforSEO’s introductory course places it inside the regression task: supervised learning with a continuous target, such as forecasting website traffic or sales trends. Its close relative, logistic regression, uses the same weighted sum but passes it through a sigmoid function to output a class probability, so it is a classification model despite its name.
Fit is usually reported with R squared (the share of variation the model explains) and an error measure such as mean absolute error, checked on data the model did not see during training (see train/test split).
How it’s used in SEO and marketing
- Trend estimation: fitting clicks or sessions against time to see the underlying direction, the regression-based forecasting our ML data characteristics lesson mentions for traffic and rank-tracking data.
- CTR curves: modelling how click-through rate changes with average position in your own Search Console data. The relationship flattens lower down the page, so position is usually transformed first (for example onto a log scale).
- Spend and conversions: a first estimate of how conversions move with budget across channels.
- Content analysis: checking whether a page attribute, such as word count or internal links, is associated with performance, with the weight showing direction and size.
- Baselines: a random forest or gradient boosting model should beat a linear model on held-out data before you adopt it.
Example
You export twelve months of Search Console data for one site section, with average position and CTR for each query. Plotting CTR against the log of position gives a roughly straight downward line, so you fit a linear regression to it. The slope tells you how much expected CTR falls per step down that scale, and the fitted line gives an expected CTR for every query. Queries sitting well below the line, earning fewer clicks than their position predicts, go on the shortlist for title and snippet rewrites.
Limitations and things to watch
- It assumes a straight-line relationship. Curved patterns need transformed features or a different model.
- Traffic has seasonality, trend breaks and algorithm updates. A single line through dates ignores all of them, so use time series forecasting methods for real forecasts.
- Outliers, such as one viral day, pull the line hard because errors are squared.
- Strongly correlated inputs, such as impressions and clicks, make individual weights unstable. Regularised versions (ridge and lasso) help.
- Weights describe association in your data. A link between word count and rankings does not mean adding words will lift rankings.
Learn it on MLforSEO
- Introduction to Machine Learning for SEO, which covers regression in the ML task and data characteristics lessons
- The Characteristics of a Machine Learning Problem: A Task, Data and Solution Framework for SEOs
- What Machine Learning Classification Is, and Where It Fits in SEO, including the classification versus regression split
- ML Data Characteristics Mapped to SEO and ML Tasks (Guide)
- When to use Machine Learning in SEO: Decision Checklist
Where Linear Regression shows up on MLforSEO
Sources and further reading
- The Characteristics of a Machine Learning Problem: A Task, Data and Solution Framework for SEOs MLforSEO
- ML Data Characteristics Mapped to SEO & ML Tasks (Guide) MLforSEO
- Course: Introduction to Machine Learning for SEO MLforSEO
- scikit-learn: Linear Models (Ordinary Least Squares)
- Google Machine Learning Crash Course: Linear regression
Other terms from ML Models & Algorithms
- BERT (Bidirectional Encoder Representations from Transformers)Google's 2018 transformer language model that reads text in both directions to produce context-aware embedding…
- BERTopicA modular topic modelling technique that clusters transformer embeddings and labels each cluster with class-ba…
- BIRCH (Balanced Iterative Reducing and Clustering using Hierarchies)BIRCH (Balanced Iterative Reducing and Clustering using Hierarchies) clusters very large numeric datasets by s…
- BM25A classic ranking function that scores documents by how often query words appear, adjusted for word rarity and…
- Boyer-MooreA fast exact string-search algorithm that compares a pattern from right to left and skips ahead after mismatch…
- c-TF-IDFClass-based TF-IDF: treats each cluster as one document to find the words that best describe it, used by BERTo…
- Centroid-based ClusteringA clustering family that groups data around central points (centroids), each the average of its cluster's memb…
- Convolutional Neural Network (CNN)A deep learning architecture that scans data with small learned filters to detect local patterns; the classic…
- DBSCANDensity-based clustering that groups closely packed points, finds the number of clusters itself and labels iso…