Get startedGet started for free

How much is an avocado?

1. How much is an avocado?

Congratulations! You have reached the final lesson of the course, in which you will use what you have learned to solve a data analysis problem, the Bayesian way.

2. The Avocado, Inc.

You have just landed every millennial's dream job: a data analyst position at The Avocado Incorported, a company selling, yes, you guessed that right, avocados.

3. Case study: estimating price elasticity

These final few exercises will take the form of a case study, in which you will help your new company make their pricing decisions more data-driven. Your job will be to estimate the price elasticity for avocados and based on the outcome, propose the optimal price. Price elasticity is the impact of a price change on the sales volume. It can be estimated with a linear regression model, and this will be your starting point. Next, you will verify the model's correctness, and use it to predict sales volumes for different prices. Finally, you will propose the profit-maximizing price and the associated uncertainty.

4. Avocado data

The company has prepared some data for you. It includes the avocado price per piece, the volume sold for this price (in tens of thousands), and an indicator for whether the particular fruit was organic.

5. Priors in pymc3

Before you set off, let's discuss one thing that we didn't look at before: specifying priors in pymc3 models. Here's how we have fitted the number-of-bikes model before. We've said that since the priors are not specified, the model will just use the pretty good defaults. But it is, of course, possible to select our own priors. Say we expect the effect of wind speed to be negative and we would like to have a normal distribution with a mean of -5 as a prior for this variable.

6. Priors in pymc3

All we have to do is to create a dictionary, let's call it priors, with the variable name as key, and the desired prior distribution as value. Here, we use pm-normal-dist, with the mu parameter, that is the mean, set to -5. Then, we simply pass this dictionary to the priors argument in from_formula.

7. Extracting draws from trace

And the last thing before you go. How to extract the posterior draws for a particular parameter from the trace? We just call the get_values method on trace with the variable name passed as the argument. This results in a numpy array with posterior draws for this variable, from all chains combined.

8. What you will need

Now you are ready to face the avocado quest! Here is the list of the functions you will need to use. You have already seen all of them.

9. Let's put what you've learned to practice!

Let's put what you've learned to practice!