1. Learn
  2. /
  3. Courses
  4. /
  5. Bayesian Data Analysis in Python

Exercise

Optimizing the price

Great job on fitting and inspecting the model! Now, down to business: your boss asks you to provide the avocado price that would yield the largest profit, and to state what profit can be expected. Also, they want the price to be divisible by $0.25 so that the customers can easily pay with quarters.

In this exercise, you will use your model to predict the volume and the profit for a couple of sensible prices. Next, you will visualize the predictive distributions to pick the optimal price. Finally, you will compute the credible interval for your profit prediction. Now go and optimize!

The posterior means you have computed before are available to you as intercept_mean, organic_mean, price_mean, and sd_mean, respectively. Also, pymc3, arviz, and numpy are imported as pm, az, and np.

Instructions 1/3

undefined XP
    1
    2
    3
  • For each price in 0.5, 0.75, 1 and 1.25, calculate the predictive mean.
  • Sample from the predictive distribution to predict sales volume.
  • Use the predicted volume to predict the profit.