Comments (4)
thanks !!! yeah i found it in the starter notebook. thank you !
from tfcausalimpact.
Looks like you optimized using hmc
, in this case use the code discussed in the next cell:
def get_param_index(model, name):
for i, v in enumerate(model.parameters):
if v.name == name:
return i
tf.reduce_mean(ci.model.components_by_name['SparseLinearRegression/'].params_to_weights(
ci.model_samples[get_param_index(ci.model, 'SparseLinearRegression/_global_scale_variance')],
ci.model_samples[get_param_index(ci.model, 'SparseLinearRegression/_global_scale_noncentered')],
ci.model_samples[get_param_index(ci.model, 'SparseLinearRegression/_local_scale_variances')],
ci.model_samples[get_param_index(ci.model, 'SparseLinearRegression/_local_scales_noncentered')],
ci.model_samples[get_param_index(ci.model, 'SparseLinearRegression/_weights_noncentered')],
), axis=0)
from tfcausalimpact.
Hi @Berlyli866 ,
Yes, there is. Please refer to the getting_started.ipnb
on section "2.5 Understanding Results", there's some discussion about this subject.
As a reference, here's an example of getting the average weights when the optimization technique is default variational inference:
tf.reduce_mean(ci.model.components_by_name['SparseLinearRegression/'].params_to_weights(
ci.model_samples['SparseLinearRegression/_global_scale_variance'],
ci.model_samples['SparseLinearRegression/_global_scale_noncentered'],
ci.model_samples['SparseLinearRegression/_local_scale_variances'],
ci.model_samples['SparseLinearRegression/_local_scales_noncentered'],
ci.model_samples['SparseLinearRegression/_weights_noncentered'],
), axis=0)
I think TFP already offers some functions for performing this operation but couldn't update the notebook so far.
Let me know if this helps you.
from tfcausalimpact.
Hey @WillianFuks ,
i used same code and got error
ci.model.components_by_name
tf.reduce_mean(ci.model.components_by_name['SparseLinearRegression/'].params_to_weights(
ci.model_samples['SparseLinearRegression/_global_scale_variance'],
ci.model_samples['SparseLinearRegression/_global_scale_noncentered'],
ci.model_samples['SparseLinearRegression/_local_scale_variances'],
ci.model_samples['SparseLinearRegression/_local_scales_noncentered'],
ci.model_samples['SparseLinearRegression/_weights_noncentered'],
), axis=0)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
/tmp/ipykernel_12815/3091180208.py in <module>
1 tf.reduce_mean(ci.model.components_by_name['SparseLinearRegression/'].params_to_weights(
----> 2 ci.model_samples['SparseLinearRegression/_global_scale_variance'],
3 ci.model_samples['SparseLinearRegression/_global_scale_noncentered'],
4 ci.model_samples['SparseLinearRegression/_local_scale_variances'],
5 ci.model_samples['SparseLinearRegression/_local_scales_noncentered'],
TypeError: list indices must be integers or slices, not str
i checked the ci.model_samples it's a list of array instead of a dictionary. do you know how to know the order of ci.model_samples['SparseLinearRegression/_global_scale_variance'],
ci.model_samples['SparseLinearRegression/_global_scale_noncentered'],
ci.model_samples['SparseLinearRegression/_local_scale_variances'],
ci.model_samples['SparseLinearRegression/_local_scales_noncentered'],
ci.model_samples['SparseLinearRegression/_weights_noncentered'],
in the array ? the ci.model_samples total has 7 elements
from tfcausalimpact.
Related Issues (20)
- Fix for Dark Mode for plots? HOT 2
- comparison of output (impact$series$cum.effect) in Python and R packages HOT 2
- Problems with the tensorflow_probability HOT 7
- Type-error HOT 7
- Installation HOT 3
- Add compatibility for Python 3.10 HOT 4
- 'CausalImpact' object has no attribute 'posterior_dist' HOT 2
- TypeError: ufunc 'isfinite' not supported for the input types HOT 5
- Saving Figures of the Model Output HOT 2
- AttributeError: 'NoneType' object has no attribute 'loc' HOT 4
- Understanding the results and improving the model HOT 2
- p-value is always less than 0.5 HOT 1
- How to save model ? HOT 2
- Categorical Variables HOT 2
- have an error when using customized model HOT 6
- ResourceExhaustedError HOT 1
- How to save the results HOT 2
- Support Python 3.11
- AttributeError: 'NoneType' object has no attribute 'loc' HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tfcausalimpact.