I am currently conducting a linear regression on a large-scale data set which has many sparse features ($\simeq 10^5$) and many observations ($\simeq 10^6$) by using scikit-learn. (Most of the features are categorical variables, so my data set is very sparse and of size linear in the number of the observations.) While the solver outputs a solution in some minutes, the solution appears to contain a significant error (presumably due to numerical errors).
Specifically, I encountered two unreasonable behaviors:
- When I added some new features, the R-squared score of the train data set decreased significantly.
- When I normalized a feature, the R-squared score increased significantly.
I am not sure, but I suspect that these unreasonable behaviors are due to numerical errors.
My question is:
- Are there more numerically stable linear regression libraries (compared to sklearn.linear_model.LinearRegression, or equivalently, scipy.linalg.lstsq)?
- Is there any other way to fix these two problems?
- Why do these problems occur?