0
$\begingroup$

I am using a simple linear regression to predict the number of units an item has moved and price of the item is one of the input parameters.

For a few items, the older prices are not relevant and hence this results in incorrect predictions. The definition of old price varies from item to item. Is there a way to make the linear regression know that recent prices are more relevant?

$\endgroup$
0
$\begingroup$

Linear regressions have fixed number of variables. An alternative could be to run a separate regression for each item group, and add a different number of time lags for each. If you can't do that, I suggest you to find an optimal number of time lags to be chosen for this general model. You can take a look at ACF, and specifically PACF plots to understand how much memory (time dependency) your time series have.

In theory, adding a more time lags should't result in a problem: if the n-th time lag is not relevant to explain your y, then it's parameter will show no statistical significance.

$\endgroup$
  • $\begingroup$ Thanks for answering. "An alternative could be to run a separate regression for each item group, and add a different number of time lags for each"- how do I do this? $\endgroup$ – AntonySamuelB Oct 9 '19 at 8:08
  • $\begingroup$ I'm sorry, I don't know the nature of your data and your specific task. I wrote it in case it was possible to do that, but I don't know it it's the case. If you can't / it's not feasible, then go for the analysis of (P)ACF plots for time dependency, and find an optimal number of time lags for your regression model. $\endgroup$ – Leevo Oct 9 '19 at 9:15
  • $\begingroup$ Fair enough. Thanks. $\endgroup$ – AntonySamuelB Oct 9 '19 at 9:56
  • $\begingroup$ If you find it useful, please consider accepting my answer and/or upvoting :) $\endgroup$ – Leevo Oct 9 '19 at 9:57
0
$\begingroup$

The predictions are bad because the weight is too high for the "old price" feature (variable/column) of your dataset. If the coefficients are not well adjusted, the problem comes from the training rather than the dataset.

Here is what you can do:

  1. Find out the coefficient (weight) for each feature. In sklearn, there is a property called .coef_ for LinearRegression.
  2. If you find the coefficients are too high, you can try Ridge regression to penalize high coefficients.
  3. Otherwise, if you want to reduce the coefficient of less important variables to a minimum, try Lasso regression with several values for alpha (ex: 0.5,0.1,0.01)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.