jonasharnau / apc Goto Github PK
View Code? Open in Web Editor NEWPython Package for Age-Period-Cohort and extended Chain-Ladder Analysis
License: GNU General Public License v3.0
Python Package for Age-Period-Cohort and extended Chain-Ladder Analysis
License: GNU General Public License v3.0
Hi @JonasHarnau , first, thank you for releasing this package!
I started playing with it a little and encountered a few errors, which seem to be related to pandas version I am using. As both errors below come from pandas, could you maybe share which last version you tested the code with and check if it's working with the newest 0.25.3
version?
The simple code to replicate is as follows:
import apc
model = apc.Model()
model.data_from_df(apc.loss_KN(), data_format="CL", time_adjust=1)
model.fit("gen_log_normal_response", "APC")
and then:
model.forecast()
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-4-87d05bd4ab9b> in <module>
----> 1 model.forecast()
~[...]/venv/lib/python3.6/site-packages/apc/Model.py in forecast(self, quantiles, method, attach_to_self)
2404 raise ValueError('Forecasting not supported for this family.')
2405
-> 2406 self._get_point_fc()
2407
2408 def _agg(df, lvl):
~[...]/venv/lib/python3.6/site-packages/apc/Model.py in _get_point_fc(self, attach_to_self)
2294 """Generate point forecasts."""
2295 fc_design = self._get_fc_design(self.predictor)
-> 2296 fc_linpred = fc_design.dot(self.parameters['coef']).rename(
2297 'linear_predictor_forecast')
2298
~[...]/venv/lib/python3.6/site-packages/pandas/core/frame.py in dot(self, other)
1076 common = self.columns.union(other.index)
1077 if len(common) > len(self.columns) or len(common) > len(other.index):
-> 1078 raise ValueError("matrices are not aligned")
1079
1080 left = self.reindex(columns=common, copy=False)
ValueError: matrices are not aligned
and
model.plot_parameters()
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
~[...]/venv/lib/python3.6/site-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
2896 try:
-> 2897 return self._engine.get_loc(key)
2898 except KeyError:
pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
KeyError: 'index'
During handling of the above exception, another exception occurred:
KeyError Traceback (most recent call last)
<ipython-input-5-e4fd0d5dc15b> in <module>
----> 1 model.plot_parameters()
~[...]/venv/lib/python3.6/site-packages/apc/Model.py in plot_parameters(self, plot_style, around_coef, simplify_ranges, figsize)
2130 predictor = self.predictor
2131
-> 2132 parameters_adhoc = self.identify(plot_style, attach_to_self=False)
2133
2134 def get_coefs(x):
~[...]/venv/lib/python3.6/site-packages/apc/Model.py in identify(self, style, attach_to_self)
2018 index=column_labels).T
2019
-> 2020 A_d_rows.index = A_d_rows.reset_index()['index'].apply(
2021 lambda x: 'A_detrend_' + x[2:])
2022 B_d_rows.index = B_d_rows.reset_index()['index'].apply(
~[...]/venv/lib/python3.6/site-packages/pandas/core/frame.py in __getitem__(self, key)
2993 if self.columns.nlevels > 1:
2994 return self._getitem_multilevel(key)
-> 2995 indexer = self.columns.get_loc(key)
2996 if is_integer(indexer):
2997 indexer = [indexer]
~[...]/venv/lib/python3.6/site-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
2897 return self._engine.get_loc(key)
2898 except KeyError:
-> 2899 return self._engine.get_loc(self._maybe_cast_indexer(key))
2900 indexer = self.get_indexer([key], method=method, tolerance=tolerance)
2901 if indexer.ndim > 1 or indexer.size > 1:
pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
KeyError: 'index'
I am using JupyterLab within Amazon SageMaker, but this should be irrelevant here.
Python and package versions:
Python 3.6.6 :: Anaconda, Inc.
apc==1.0.1
backcall==0.1.0
clear==1.0.1
cycler==0.10.0
decorator==4.4.1
goodlogging==1.0.1
ipdb==0.12.3
ipykernel==5.1.3
ipython==7.11.1
ipython-genutils==0.2.0
jedi==0.15.2
jupyter-client==5.3.4
jupyter-core==4.6.1
kiwisolver==1.1.0
matplotlib==3.1.2
numpy==1.18.1
pandas==0.25.3
parso==0.5.2
patsy==0.5.1
pexpect==4.7.0
pickleshare==0.7.5
prompt-toolkit==3.0.2
ptyprocess==0.6.0
Pygments==2.5.2
pyparsing==2.4.6
python-dateutil==2.8.1
pytz==2019.3
pyzmq==18.1.1
quad-form-ratio==0.1.1
rarfile==2.7
requests==2.6.0
scipy==1.4.1
seaborn==0.9.0
six==1.13.0
statsmodels==0.10.2
tornado==6.0.3
traitlets==4.3.3
wcwidth==0.1.8
I am regenerating the model for the purpose of using it as a base for my own apc analysis.
I can see the response and rate data is separately brought in, but where does the dose data come from? I is not available in neither Out[3] nor Out[4].
Line 2268 in 4908cc1
Thank you for your work on Python. Recently, I encountered a problem with mismatched matrix shapes when using it. I don't quite understand what kind of operation the โdotโ here is supposed to perform, as the two matrices involved in the calculation seem to be unable to match. This problem occurred on Belgian_lung_cancer.
--> fc_linpred = fc_design.dot(self.parameters['coef']).rename(
'linear_predictor_forecast')
if self.family in ('poisson_response', 'od_poisson_response'):
fc_point = np.exp(fc_linpred).rename('point_forecast')
ValueError: matrices are not aligned
Hi! Thanks for all your support. I got my paper ready for publication. Just to ask, if it is possible to output the charts not into jpg, but to some kind of editable format. I am not even sure what the editable format would be...
Thanks Janika
janikabachmann/apc
I am using the same input format as Belgian_lung_cancer.xlsx reading from excel file as data1 and data2.
Then data=[data1, data2] but from model.data_from_df(**data) get an error:
data_from_df() argument after ** must be a mapping, not list
Can you please share steps 1-6 when imported from excel?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.