The Dummy Regressor is a kind of Regressor that gives prediction based on simple strategies without paying any attention to the input Data. As similar to Dummy Classifier the sklearn library also provides Dummy Regressor which is used to set up a baseline for comparing other existing Regressor namely Poisson Regressor, Linear Regression, Ridge Regression and many more. However, in this article, the main focus will be to draw a comparison between Dummy Regression and Linear regression.
- STEP 1- Importing the necessary modules. The dummy module of sklearn provides an in-built DummyRegressor model which will be used in this case. Apart from importing other modules the mean square error and the median absolute error are worth special mentioning and the purpose of doing so will be explained later in the due course.
- STEP 2- Loading the Dataset. Here the Boston Dataset has been used for the purpose which is available in the sklearn Dataset module. Since, this is a regression problem, so only one feature i.e. the “data” has been considered as an input feature and labelled as X and “target” as y for the target labels. To match the X and y dimensionality the X is reduced to 1 element in each row, by the following code.
- STEP 3- Training and testing the dummy and the linear model. The below code shows that training the dummy model is similar to training any regular regression model, except for the strategies. The main role of strategy is to predict target values without any influence of the training data. There are namely four types of strategies that are used by the Dummy Regressor:-
- Mean: This is the default strategy used by the Dummy Regressor. It always predicts the mean of the training target values.
- Median: This is used to predict the median of the training target values.
- Quantile: It is used to predict a particular quantile of training target values provided the quantile parameter is used along with it.
- Constant: This is generally used to predict a specific custom value that is provided and the constant parameter must be mentioned.
In this case, however, the “mean” and “median” has been used for strategy. But the other two can be used depending upon the necessity.
After training both the models they are evaluated on the test set using y_predict for the linear model and y_predict_dummy_mean and y_predict_dummy_median for predicting the dummy mean and median respectively.
- STEP 4- Error analysis. To understand how better both the model performed the evaluation metrics such as mean squared error, median absolute error and r2_ score are calculated for both the linear and dummy models. The mean square error and the median absolute error are evaluated along with r2_ score, mainly to demonstrate the influence of “mean”, “median” strategies of the DummyRegressor.
OBSERVATION: As can be seen from the above result. The expected Dummy Regressor always predict the r2_ score as 0 for both the mean and median, since it is always predicting a constant without having an insight of the output. ( In general, best r2_score is 1 and Constant r2_score is 0). The Linear Regression Model seems to fit a little better than the Dummy Regressor in terms of “mean squared error”, “median absolute error” and “r2_score”.
- STEP 5- For visualizing the performance of Dummy Regressor and Linear Regressor, both the models are plotted over the test data.
Conclusion- The scattered plot in the above plot, are the instances of the test set that trends to accumulate slightly at the bottom right. The green line is the linear regression model that was fit to the training points. The red line shows the dummy mean that always uses the strategy of predicting the mean of the training set, similarly the blue line shows the dummy median and serves the same purpose for predicting the median of the training set. As it is, see the linear model doesn’t fit so well to test data.
Hence, it can now be finally concluded that the Dummy Regressor can be used for checking how well a regular regression model is fitted to a particular dataset but can never be used in any real problem.
Please refer to the scikit learn documentation(“https://scikit-learn.org/stable/modules/generated/sklearn.dummy.DummyRegressor.html“) for more details.