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
.
Cet exercice fait partie du cours
Bayesian Data Analysis in Python
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de code.
# For each price, predict volume and use it to predict profit
predicted_profit_per_price = {}
for price in [0.5, 0.75, 1, 1.25]:
pred_mean = (____)
volume_pred = ____(____, ____, size=1000)
profit_pred = ____
predicted_profit_per_price.update({price: profit_pred})