This repository has been archived by the owner on Jun 18, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Build estimator pickles on install #70
Pickles are always dependent on installed versions of libraries used in pickle, so having just one set was never a good idea. It now also doesn't work because some pickles can contain Numba JIT'd functions
- Loading branch information
Showing
11 changed files
with
104 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
""" Setup pickles for distribution -- NOT A MODULE INCLUDED IN YATSM | ||
Note that pickles are generated at time of installation. Upgrading or altering | ||
the libraries that the pickles are dependent upon may cause errors. | ||
""" |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
""" Setup script to pickle various statistical estimators for distribution | ||
Available pickles to build: | ||
* glmnet_Lasso20.pkl | ||
* sklearn_Lasso20.pkl | ||
""" | ||
from __future__ import print_function | ||
|
||
import json | ||
import logging | ||
import os | ||
import traceback | ||
|
||
# Don't alias to ``np``: https://github.com/numba/numba/issues/1559 | ||
import numpy | ||
import sklearn.linear_model | ||
from sklearn.externals import joblib as jl | ||
import six | ||
|
||
logger = logging.getLogger() | ||
|
||
|
||
# GLMNET pickles | ||
try: | ||
import glmnet | ||
_glmnet_pickles = { | ||
'glmnet_Lasso20.pkl': glmnet.Lasso(lambdas=20), | ||
'glmnet_LassoCV_n50.pkl': glmnet.LassoCV( | ||
lambdas=numpy.logspace(1e-4, 35, 50)), | ||
} | ||
except: | ||
logger.error('Could not produce pickles from package "glment". ' | ||
'Check if it is installed') | ||
print(traceback.format_exc()) | ||
_glmnet_pickles = {} | ||
|
||
# scikit-learn pickles | ||
_sklearn_pickles = { | ||
'OLS.pkl': sklearn.linear_model.LinearRegression(), | ||
'sklearn_Lasso20.pkl': sklearn.linear_model.Lasso(alpha=20.0), | ||
'sklearn_LassoCV_n50.pkl': sklearn.linear_model.LassoCV( | ||
alphas=numpy.logspace(1e-4, 35, 50)), | ||
} | ||
|
||
# YATSM pickles | ||
from ..robust_fit import RLM # flake8: noqa | ||
_yatsm_pickles = { | ||
'rlm_maxiter10.pkl': RLM(maxiter=10) | ||
} | ||
|
||
pickles = [_glmnet_pickles, _sklearn_pickles, _yatsm_pickles] | ||
here = os.path.dirname(__file__) | ||
pickles_json = os.path.join(here, 'pickles.json') | ||
|
||
|
||
def make_pickles(): | ||
logger.info('Serializing estimators to pickles...') | ||
packaged = {} | ||
|
||
for pickle in pickles: | ||
for fname, obj in six.iteritems(pickle): | ||
jl.dump(obj, os.path.join(here, fname), compress=5) | ||
packaged[fname] = obj.__class__.__name__ | ||
|
||
with open(pickles_json, 'w') as f: | ||
json.dump(packaged, f, indent=4) | ||
logger.info('Wrote pickles.json to %s' % pickles_json) |
Binary file not shown.