Suggestion: Implement a `.remove_data` function for Results
Maintainer thường phản hồi trong vòng 1 ngày
@bashtage đang làm issue này rồi.
Từ ngày 21/9/2023.
Đánh giá
Issue này chưa được đánh giá.
Mô tả
Description
Fitted results from linearmodels can be pickled with pickle.dump. These pickled files contain the estimated parameters, along side all the data required to estimate these parameters. Saving the data required to estimate the results is generally (always?) not desired, as keeping this data in the results substantially increases the size of the pickled files. The estimated parameters however no longer require these potentially large datasets to be displayed or processed.
Example
My use case is as follows, with a large (N = 500'000, T = 123) panel dataset.
- Create a list of all desired model specifications and comparisons
- Estimate all the different models
- Save different comparison of these results with
compare
In pseudocode
specifications = pd.DataFrame({"formulas": formulas, "criterium": criteria})
results = []
for formula in specifications["formulas"]:
model = PanelOLS(y, x)
res = model.fit()
results.append(res)
specifications["results"] = results
for criteria in specifications["criteria"].unique():
results = specificiations.query("criterium == @criteria")["results"]
comparison = compare(results)
comparison.summary.as_latex()
As my dataset is very large, pickeling results or the DataFrame specifications takes up multiple Gb's to store just a few number of estimated parameters. Ideally, I would be able to store/pickle the results. That way, I can separate the estimating the models from comparing the models. For example, this would allow someone to do the estimations during the night and kill the process once done.
Workaround
I created this hacky workaround to remove a lot of attributes from the model and result that aren't required if you're only interested in storing the results. With this, I can reduce the size of the pickle objects from ~50Gb to around 250Mb.
import functools
def fake_cov(_deferred_cov, *args, **kwargs):
return _deferred_cov
def shrink_mod_and_res(mod, res):
"""
Remove any DataFrame and large objects that are unnecessarily stored in the model and results objects.
"""
mod.dependent._frame = mod.dependent._frame.head(1)
mod.dependent._original = None
mod.dependent._panel = None
mod.exog._frame = mod.exog._frame.head(1)
mod.exog._original = None
mod.exog._panel = None
mod.weights._frame = mod.weights._frame.head(1)
mod.weights._original = None
mod.weights._panel = None
mod._cov_estimators = None
mod._x = None
mod._y = None
mod._w = None
mod._not_null = None
mod._original_index = None
res._resids = None
res._wresids = None
res._original_index = None
res._effects = None
res._index = None
res._fitted = None
res._idiosyncratic = None
res._not_null = None
_deferred_cov = res._deferred_cov()
res._deferred_cov = functools.partial(fake_cov, _deferred_cov=_deferred_cov)
return mod, res
model = PanelOLS(y, x)
res = model.fit()
mod, res = shrink_mod_and_res(mod,res)
It's not clear to my why the calculation of the covariance is deferred? I suppose if you want to change the covariance estimator after the estimation, that this hacky method needs to store all possible covariance estimations.
Suggestion
Implement a (cleaner) method to remove large datasets contained in the Results, similar to the remove_data flag in the .save() method of statsmodels' models.
- Ngôn ngữ chính
- Python
- Star
- 1.1k
- Fork
- 203
- Merge trung bình
- 3 giờ 26 phút
- Pull request đã merge (30 ngày)
- 115
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của bashtage/linearmodels
-
enhancement
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 15/100
bashtage/linearmodels#832 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
bashtage/linearmodels#831 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
IV: LIML kappa with an endogenous regressor spanned by the instruments, kappa's unit dependence, scale-dependent instrument rank checkCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mởbug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
bashtage/linearmodels#823 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 18/100
bashtage/linearmodels#817 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
bashtage/linearmodels#780 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của bashtage/linearmodels
Issue tương tự
-
Release notes from PR titlesĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
[DATA] BDC portfolio DataFrame converts filed zero fair value and principal to missing valuesĐang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
dgunning/edgartools#1853 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 80/100
Imbad0202/academic-research-skills#1039 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 82/100
openmainframeproject/feilong#980 ·
Maintainer thường phản hồi trong vòng 5 ngày