Elastic Data Frame - Regression Analysis
Tags: machinelearning, elasticsearch, beginners
Published: 2021-08-02 14:38:17

| [Menu](https://dev.to/priscilla_parodi/a-guide-to-machine-learning-ai-with-the-elastic-stack-1dkl) | [Next Post: Elastic Data Frame - Classification Analysis](https://dev.to/priscilla_parodi/elastic-data-frame-classification-analysis-1b3f) |

> Unlike the [Anomaly Detection](https://dev.to/priscilla_parodi/elastic-anomaly-detection-learning-process-and-anomaly-score-3nl7) models, this is a multi-variate analysis, it enables a better understanding of complex behaviors that are described by many features. For this analysis we have 3 models with different algorithms and learning types ([Outlier](https://dev.to/priscilla_parodi/elastic-data-frame-outlier-detection-16ni), Regression and [Classification](https://dev.to/priscilla_parodi/elastic-data-frame-classification-analysis-1b3f)) and in this post we'll talk about Regression Analysis.

**Regression** makes predictions on your data after it determines certain relationships among your data points (Supervised ML).

For example, suppose we are interested in finding the relationship between apartment size and monthly rent in a city, to do this we need to find the relationship between a number of **features** and a **target variable** to know if the target variable can/can't be explained by the feature(s).

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jp5os5594ginh5rjdh5q.png)

This example is a one-dimensional regression problem, because we only have one feature variable (size), but we could easily add more features.

###Evaluation of the Regression analysis###

For the regression analysis we use a variation of the XGBoost algorithm, which combines decision trees with gradient boosting methodologies.

The two measures that we can use to evaluate regression in the stack is R2 and MSE:

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oql3xo4eugegi6eppjo4.png)

* **R Squared** (ranges from 0 to 1 | the higher the better): measures goodness of fit, to know if the target variable can/can’t be explained by the feature variable, 1 is a perfect fit.

* **Mean Squared Error** (ranges from 0 to 1 | the lower the better) - measures the average error between the actual datapoints and the predicted data points telling you how close a regression line is to a set of points. It does this by taking the distances from the points (purple dots) to the regression line (blue line), these distances (red lines) are the “errors”, and squaring them.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6j2wulfvxfyk3tmscsrx.png)

We can measure how well our model is performing by computing the average squared sum of the difference between the true and predicted value - Mean Square Error.

When you view the regression results in Kibana. It provides information about the analysis, model evaluation metrics, total feature importance values, and a scatterplot matrix.

| [Menu](https://dev.to/priscilla_parodi/a-guide-to-machine-learning-ai-with-the-elastic-stack-1dkl) | [Next Post: Elastic Data Frame - Classification Analysis](https://dev.to/priscilla_parodi/elastic-data-frame-classification-analysis-1b3f) |

>*This post is part of a series that covers [Artificial Intelligence with a focus on Elastic's (Creators of Elasticsearch) Machine Learning solution](https://dev.to/priscilla_parodi/a-guide-to-machine-learning-ai-with-the-elastic-stack-1dkl), aiming to introduce and exemplify the possibilities and options available, in addition to addressing the context and usability.*