allendowney / bayesmadesimple Goto Github PK
View Code? Open in Web Editor NEWCode for a tutorial on Bayesian Statistics by Allen Downey.
Code for a tutorial on Bayesian Statistics by Allen Downey.
I have installed empyrical-dist module using pipenv virtual environment but when I try to run your code 01_cookie.ipynb, it throws an error in the first cell at "from empiricaldist import Pmf" saying "ModuleNotFoundError: No module named 'empiricaldist'". Could you please look into this and confirm this is not an issue with the package itself?
First of all, thank you for putting on a great tutorial!
I believe I found bad solution in the cookie-notebook.
Bonus exercise: In Dungeons and Dragons, the amount of damage a goblin can withstand is the sum of two six-sided dice. The amount of damage you inflict with a short sword is determined by rolling one six-sided die.
Suppose you are fighting a goblin and you have already inflicted 3 points of damage. What is your probability of defeating the goblin with your next successful attack?
The provided solution is:
d6 = Pmf()
for x in [1,2,3,4,5,6]:
d6[x] = 1
d6.normalize()
twice = d6.add_dist(d6)
twice[2] = 0
twice[3] = 0
twice.normalize()
>>> d6.ge_dist(twice)
0.11111111111111109
This implies that Goblin's health should be reduced, due to the 3 damage you already did, by creating the posterior over the Goblin's health with the assumption that it does not have 1-3 health remaining. Clearly this is not correct. The blow means that the Goblin's health must lie in the interval [1, 9], not [4, 12]
The correct solution, I believe, would be:
d6 = Pmf()
for x in [1,2,3,4,5,6]:
d6[x] = 1
d6.normalize()
twice = d6.add_dist(d6)
goblin_health = twice.copy()
# 3 HP of damage already dealt:
dmg3 = Pmf()
dmg3[3] = 1.
sword = d6.copy().add_dist(dmg3)
>>> sword.ge_dist(goblin_health)
0.5
as title states
The error:
AttributeError: 'Pmf' object has no attribute 'add_dist'
Looks like you have removed add_dist from the Pmf class in the latest version of the empyrical_dist and that seems to break the code in the notebook.
My questions/requests to you are:
Probably should mention that the following is needed to be installed:
matplotlib
numpy
scipy
pandas
in the readme and/or your website to make it easier to get going.
To make it easier for attendees to install the necessary packages it would be nice to include a requirements.txt
, e.g.
# requirements.txt
scipy
numpy
matplotlib
pandas
Attendees can then run pip install -r requirement.txt
to get the required packages installed.
When I try to do it, I get the following error:
NotImplementedError Traceback (most recent call last)
in
1 for i, b in enumerate(beliefs):
----> 2 print(b.mean(), b.credible_interval(0.9))c:\users...\appdata\local\programs\python\python36-32\lib\site-packages\empiricaldist\empiricaldist.py in credible_interval(self, p)
716 tail = (1 - p) / 2
717 ps = [tail, 1 - tail]
--> 718 return self.quantile(ps)
719
720 @staticmethodc:\users...\appdata\local\programs\python\python36-32\lib\site-packages\empiricaldist\empiricaldist.py in quantile(self, ps, **kwargs)
137 :return: float
138 """
--> 139 return self.make_cdf().quantile(ps, **kwargs)
140
141 def choice(self, *args, **kwargs):c:\users...\appdata\local\programs\python\python36-32\lib\site-packages\empiricaldist\empiricaldist.py in inverse(self, **kwargs)
846 )
847
--> 848 interp = interp1d(self.ps, self.qs, **kwargs)
849 return interp
850c:\users...\appdata\local\programs\python\python36-32\lib\site-packages\scipy\interpolate\interpolate.py in init(self, x, y, kind, axis, copy, bounds_error, fill_value, assume_sorted)
443 elif kind not in ('linear', 'nearest'):
444 raise NotImplementedError("%s is unsupported: Use fitpack "
--> 445 "routines for other types." % kind)
446 x = array(x, copy=self.copy)
447 y = array(y, copy=self.copy)NotImplementedError: next is unsupported: Use fitpack routines for other types.
The link in the README is broken.
A good replacement could be the Wayback Machine version
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.