real or categorical predictors, which one is faster?
조회 수: 1 (최근 30일)
이전 댓글 표시
In regressions, is there a guidline to treat predictors as real values or categorical?
In a fitting problem with input as X, y where X contains the hour of the day information, e.g. 1, 2, 3, etc.., I tend to consider it as a categorical predictor because the length of unique(X) is limited (i.e. 24). Surprislingly, the fitting procedures seem slower than treating it as real values in a gaussian process fitrgp.
My questions are:
- why does it take longer with categorical predictor?
- in a similar situation, is there a guidline to decide whether take the predictors as real values or categorical inputs?
댓글 수: 3
dpb
2023년 9월 19일
편집: dpb
2023년 9월 19일
"why does it take longer with categorical predictor?"
I'd venture owing to the large number of dummy variables introduced by having 24 levels of time being modeled as categorical instead of continuous/discrete. You could try artificially reducing the same data set to 24, 12, 2 levels and see if that hypothesis is correct.
Regardless of whether it's true or not, it's still the model definition and purpose that should be controlling decisions such as this, not anything to do with compute time.
채택된 답변
dpb
2023년 9월 17일
편집: dpb
2023년 9월 17일
Whether to use categorical or continuous variable is context sensitive and should be based on the model intent and interpretation, NOT the compute effort required.
If the time was measured in discrete intervals such as hours, then the question revolves about the interpretation of the response variable -- if the time is considered as continuous, then the regression model will calculate a coefficient between that predictor and the response variable after accounting for other variables in the model. Since the discrete predictor is numerical, fitting a line to it can be reasonable; its values are true numbers with meaningful intervals between them.
On the other hand, If you specify a predictor as categorical, the regression estimates a mean of the response variable for each category of the predictor and each of the set of coefficients for that predictor measures the difference in the means of Y between one category of X and the reference category.
So, the decision should be based on the research question being asked -- is it about estimating a change over X (time) or is it about estimating mean differences at specific values of X (hours)?
Which solution is more expensive in compute time is irrelevant...
댓글 수: 4
dpb
2023년 9월 19일
The solution time is what it is going to be dependent upon the model and the size of the input dataset -- MATLAB treats everything as double numerically and computationally, the designation in fitrgp of data class is going to be immaterial when passed to the function and the only way can be anything but a single numeric class of double when calling it is to use a table that has variables defined differently. But, even if do so, they're all going to be converted to double() internally, anyway.
The consideration of whether a variable is categorical is material only in the interpretation and model-building as to whether it creates the dummy variables or not.
There are some notes about using the QR or "V" solution technique, the latter of which is apparently faster but not exact, but it appears that it will use the latter automagically if the size of the input >2000 anyway. I'd expect that's the only choice you have in affecting the solution speed other than the uncontrollable effect of specific datasets other than the size of the dataset itself.
추가 답변 (0개)
참고 항목
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!