scikit-learn-contrib / MAPIE

A scikit-learn-compatible module to estimate prediction intervals and control risks based on conformal predictions.
https://mapie.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
1.2k stars 99 forks source link

410 mapiequantileregressor predict method causing memoryerror #412

Closed LacombeLouis closed 4 months ago

LacombeLouis commented 5 months ago

Description

Fix issue #410. This involves simplifying the type of check and making it more memory efficient.

Type of change

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

from mapie.regression import MapieQuantileRegressor

random_state = 26 rng = np.random.default_rng(random_state)

Generate a random train_data

n = 10000000 p = 10 X = rng.standard_normal((n, p)) beta = rng.standard_normal(p) y = X @ beta + rng.standard_normal(n)

X_train, X_test, y_train, y_test = train_test_split( X, y, train_size=0.8, random_state=random_state, shuffle=False, ) X_train, X_calib, y_train, y_calib = train_test_split( X_train, y_train, train_size=0.8, random_state=random_state, shuffle=False, )

print(X_test.shape, X_calib.shape, X_train.shape)

estimator = LGBMRegressor( objective="quantile", alpha=0.5, random_state=random_state )

mqr = MapieQuantileRegressor( estimator, method="quantile", cv="split", alpha=0.02 ) mqr.fit( X_train, y_train, X_calib=X_calib, y_calib=y_calib, random_state=random_state, )

y_pred, y_pis = mqr.predict(X_test) print("DONE!")


- [x] Test by @gabrieltardochi and his own data: [link](https://github.com/scikit-learn-contrib/MAPIE/issues/410#issuecomment-1934063300)

# Checklist

- [x] I have read the [contributing guidelines](https://github.com/simai-ml/MAPIE/blob/master/CONTRIBUTING.rst)
- [x] I have updated the [HISTORY.rst](https://github.com/simai-ml/MAPIE/blob/master/HISTORY.rst) and [AUTHORS.rst](https://github.com/simai-ml/MAPIE/blob/master/AUTHORS.rst) files
- [x] Linting passes successfully : `make lint`
- [x] Typing passes successfully : `make type-check`
- [x] Unit tests pass successfully : `make tests`
- [x] Coverage is 100% : `make coverage`
- [x] Documentation builds successfully : `make doc`
codecov-commenter commented 5 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (614293e) 100.00% compared to head (89c47a4) 100.00%. Report is 256 commits behind head on master.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #412 +/- ## ========================================== Coverage 100.00% 100.00% ========================================== Files 39 39 Lines 4616 4877 +261 Branches 487 800 +313 ========================================== + Hits 4616 4877 +261 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.