Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAINT: save data and rebuild model #49

Merged
merged 2 commits into from
Jul 18, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion bayesalpha/author_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import pandas as pd
from sklearn.preprocessing import LabelEncoder
import pymc3 as pm
import xarray as xr
from .serialize import to_xarray
from ._version import get_versions
from .base import BayesAlphaResult
Expand Down Expand Up @@ -155,7 +156,12 @@ class AuthorModelResult(BayesAlphaResult):
def rebuild_model(self, data=None):
""" Return an AuthorModelBuilder that recreates the original model. """
if data is None:
data = self.trace._data.to_pandas().copy()
data = (self.trace
._data
.to_pandas()
.rename('perf_sharpe_ratio_is')
.reset_index()
.copy())

return AuthorModelBuilder(data)

Expand Down Expand Up @@ -233,6 +239,12 @@ def fit_authors(data,
trace.attrs['model-version'] = get_versions()['version']
trace.attrs['model-type'] = AUTHOR_MODEL_TYPE

if save_data:
d = data.set_index(['meta_user_id',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These dimension names should match the ones used in the model (line 59)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That way xarray knows that they are the same dimension, and doesn't store the coordinates twice.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, so then:

author -> meta_user_id
algo -> meta_algorithm_id
backtest -> meta_code_id

Right?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

'meta_algorithm_id',
'meta_code_id']).squeeze()
trace['_data'] = xr.DataArray(d)

return AuthorModelResult(trace)


Expand Down