![]() ![]() Import matplotlib module to plot the contour plot and NumPy to number the axis and create grid layout.Create a contour plot in matplotlib import matplotlib.pyplot as plt The main purpose of a contour plot is to display a 3-Dimensional surface in a 2-Dimensional plot. Here, by slices, we mean that a 3-D graph is cut into equal partitions along an axis and the boundaries are merged together in a 2-D plane. What is a contour plot?Ī contour plot is a technique of plotting constant z slices called a contour on a 2-Dimensional format to represent a 3-dimensional surface. Matplotlib is a data visualization library in python which is used to represent data in the form of plots and graphs. To do this we need to know about matplotlib library. blue for negative returns).In this tutorial, we are going to see how to create a legend for a contour plot in matplotlib in Python. Here I may want to either use a mask to not show negative expected returns, or a diverging color scheme (e.g. Next up in my personal learning will be how to manipulate color bars a bit more. The color bar does nice here out of the box. ![]() #plt.savefig('RevContour.png',dpi=500,bbox_inches='tight') Plt.annotate('Revenue subtracts $200 of fixed labor costs', #clb.ax.set_xlabel('Revenue') #Abit too wideĬlb.ax.set_title('dollar') #html does not like the dollar signĪx.t_major_formatter(StrMethodFormatter('$')) #np.logspace(0,np.log10(10000),n) #if you want to do logged # Example of making a revenue contour plotįrom matplotlib.ticker import StrMethodFormatter After that is is just idiosyncratic matplotlib code to make a nice filled contour. The revenue estimates are then simply the probability times the claims amount, minus some fixed (often labor to audit the claim) cost. Then I use np.meshgrid to get the data in the right shape for the contour plot. First, I generate data over a regular grid to illustrate different claim amounts and then probabilities. The code snippet is small enough to just copy-paste entirely. So I have been making the subsequent filled contour plot I am going to show in the next section to illustrate this. In this framework, it is more important to audit a high dollar claim than a lower dollar claim, even if the higher dollar value claim has a lower probability. I am working with medical insurance claims data at HMS, and often determining models to audit those claims in some way. (If you have a vector of varying probabilities, in R code the estimated revenue will then look like prob 0.02 sum( (50*prob - 1)*pover ).)īut many of the decisions I work with are not a single number in the benefits column. Any single advert may be a bust, but if your model is right and you send out a bunch, you should make this much money in the end. The probabilities you get from your predictive model can be thought of as in the long run averages. So if you have a probability of 10% for 2000 customers, you would expect to make 2000 * (50*0.1 - 1) = 8000. So in this case you need the predicted probability to be above 2% to have an expected positive return on the investment of sending the advert. In this framework, if you have a predictive model for the probability the advert will be successful, then your decision threshold will look like this: $50*probability - $1 If the person buys the product, your company makes $50, and the advert only costs $1 to send. For example, say you are sending adverts in the mail for a product. If you can identify the costs and benefits of making particular decisions, you can set a simple threshold to make that decision. do I do some process to this observation if the probability is 20%, 30%, 60%, etc. ![]() So people often talk about setting a decision threshold to turn a predicted probability into a binary yes/no decision. ![]() I’ve been making a chart that looks similar to this for a few different projects at work, so figured a quick blog post to show the notes of it would be useful. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |