---
title: Linear Prediction
slug: litmusedge/linear-prediction
docTags: 
createdAt: 2024-08-06T19:05:02.892Z
---

The Linear Prediction processor forecasts future values by fitting a linear trend line to a window of collected data using least-squares regression.

## Why use Linear Prediction

Use this processor to project where a value is headed based on its recent trend, for example, predicting when a slowly rising temperature or pressure reading will cross a threshold.

## How it works

The processor fits a line to the values in the window using least-squares regression: it calculates the slope as `sum((Yᵢ - meanY)(Xᵢ - meanX)) / sum((Xᵢ - meanX)²)` and the intercept as `meanY - slope × meanX`. It then extrapolates the resulting line, `y = slope × X + intercept`, forward by the number of predictions you configure.

The processor also reports a residual error: the difference between what the model predicted for the current value and the value that actually occurred.

If your input tag doesn't publish at a steady rate, use **Timer Interval** to publish a value on a fixed schedule instead of waiting for the next incoming event. If your input already publishes at the interval you expect, enter `0` to disable the timer.

## Parameters

| **Parameter**         | **Details**                                                                                                                                                                                                        |
| --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| Window Size           | How many values the processor observes before making each prediction.                                                                                                                                              |
| Number of Predictions | How many polling intervals into the future the processor predicts.                                                                                                                                                 |
| Polling Interval      | The time interval (in seconds) between successive data polls.                                                                                                                                                      |
| Timer Interval        | Sets a timer (in milliseconds) that continuously publishes the output when no event triggers a prediction. Enter `0` to disable the timer; the prediction model then relies entirely on incoming data for updates. |
| Pass Through Value    | Determines whether the processor's output is the predicted value or the original unchanged input value.                                                                                                            |

## Related topics

- &#x20;[Use the Linear Prediction Function](docId\:fk-ABv9B-Ppn3L2D9n0ik)&#x20;

