![]() |
VOOZH | about |
In this article, we are going to see how to perform quantile regression in Python.
Linear regression is defined as the statistical method that constructs a relationship between a dependent variable and an independent variable as per the given set of variables. While performing linear regression we are curious about computing the mean value of the response variable. Instead, we can use a mechanism known as quantile regression in order to compute or estimate the quantile (percentile) value of the response value. For example, 30th percentile, 50th percentile, etc.
Quantile regression is simply an extended version of linear regression. Quantile regression constructs a relationship between a group of variables (also known as independent variables) and quantiles (also known as percentiles) dependent variables.
Calculation quantile regression is a step-by-step process. All the steps are discussed in detail below:
Let us create a dataset now. As an example, we are creating a dataset that contains the information of the total distance traveled and total emission generated by 20 cars of different brands.
Output:
Distance Emission 0 5.939322 22.218454 1 7.436704 19.618575 2 6.424870 20.502855 3 5.903949 18.739366 4 4.812893 16.928183
Now we will construct a quantile regression model with the help of,
Now, We will make use of this model to estimate the 70th percentile of emission generated based on the total distance traveled by cars.
From the output of this program, the estimated regression equation can be deduced as,
val = 39.5647 + 1.3042 * X (distance in km)
It implies that the 70th percentile of emission for all the cars that travel X km is expected to be val.
Output:
👁 ImageIn order to visualize and understand the quantile regression, we can use a scatterplot along with the fitted quantile regression.
Output: